Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/screen.c @ 1171:03a38b7ad2e0
Add a collection of commands for key bindings (Lego12239)
This patch gives more flexibility to customize the key bindings, by adding
a /iline command.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Wed, 14 Mar 2007 21:33:17 +0100 |
parents | 29f805d8412f |
children | 334ae9f498f1 |
comparison
equal
deleted
inserted
replaced
1170:29f805d8412f | 1171:03a38b7ad2e0 |
---|---|
2254 put_char(put_char(c1, b), a); | 2254 put_char(put_char(c1, b), a); |
2255 check_offset(1); | 2255 check_offset(1); |
2256 } | 2256 } |
2257 } | 2257 } |
2258 | 2258 |
2259 void readline_forward_kill_word(void) | |
2260 { | |
2261 char *c, *old = ptr_inputline; | |
2262 int spaceallowed = 1; | |
2263 | |
2264 if (! *ptr_inputline) return; | |
2265 | |
2266 for (c = ptr_inputline ; *c ; c = next_char(c)) { | |
2267 if (!iswalnum(get_char(c))) { | |
2268 if (iswblank(get_char(c))) { | |
2269 if (!spaceallowed) break; | |
2270 } else spaceallowed = 0; | |
2271 } else spaceallowed = 0; | |
2272 } | |
2273 | |
2274 // Modify the line | |
2275 for (;;) { | |
2276 *old = *c++; | |
2277 if (!*old++) break; | |
2278 } | |
2279 } | |
2280 | |
2259 // readline_backward_kill_word() | 2281 // readline_backward_kill_word() |
2260 // Kill the word before the cursor, in input line | 2282 // Kill the word before the cursor, in input line |
2261 void readline_backward_kill_word(void) | 2283 void readline_backward_kill_word(void) |
2262 { | 2284 { |
2263 char *c, *old = ptr_inputline; | 2285 char *c, *old = ptr_inputline; |
2328 } else spaceallowed = 0; | 2350 } else spaceallowed = 0; |
2329 } else spaceallowed = 0; | 2351 } else spaceallowed = 0; |
2330 } | 2352 } |
2331 | 2353 |
2332 check_offset(1); | 2354 check_offset(1); |
2355 } | |
2356 | |
2357 void readline_backward_char(void) | |
2358 { | |
2359 if (ptr_inputline == (char*)&inputLine) return; | |
2360 | |
2361 ptr_inputline = prev_char(ptr_inputline, inputLine); | |
2362 check_offset(-1); | |
2363 } | |
2364 | |
2365 void readline_forward_char(void) | |
2366 { | |
2367 if (!*ptr_inputline) return; | |
2368 | |
2369 ptr_inputline = next_char(ptr_inputline); | |
2370 check_offset(1); | |
2371 } | |
2372 | |
2373 void readline_hist_prev(void) | |
2374 { | |
2375 const char *l = scr_cmdhisto_prev(inputLine, ptr_inputline-inputLine); | |
2376 if (l) strcpy(inputLine, l); | |
2377 } | |
2378 | |
2379 void readline_hist_next(void) | |
2380 { | |
2381 const char *l = scr_cmdhisto_next(inputLine, ptr_inputline-inputLine); | |
2382 if (l) strcpy(inputLine, l); | |
2383 } | |
2384 | |
2385 void readline_backward_kill_char(void) | |
2386 { | |
2387 char *src, *c; | |
2388 | |
2389 if (ptr_inputline == (char*)&inputLine) | |
2390 return; | |
2391 | |
2392 src = ptr_inputline; | |
2393 c = prev_char(ptr_inputline, inputLine); | |
2394 ptr_inputline = c; | |
2395 for ( ; *src ; ) | |
2396 *c++ = *src++; | |
2397 *c = 0; | |
2398 check_offset(-1); | |
2399 } | |
2400 | |
2401 void readline_forward_kill_char(void) | |
2402 { | |
2403 if (!*ptr_inputline) | |
2404 return; | |
2405 | |
2406 strcpy(ptr_inputline, next_char(ptr_inputline)); | |
2407 } | |
2408 | |
2409 void readline_iline_start(void) | |
2410 { | |
2411 ptr_inputline = inputLine; | |
2412 inputline_offset = 0; | |
2413 } | |
2414 | |
2415 void readline_iline_end(void) | |
2416 { | |
2417 for (; *ptr_inputline; ptr_inputline++) ; | |
2418 check_offset(1); | |
2419 } | |
2420 | |
2421 void readline_backward_kill_iline(void) | |
2422 { | |
2423 strcpy(inputLine, ptr_inputline); | |
2424 ptr_inputline = inputLine; | |
2425 inputline_offset = 0; | |
2426 } | |
2427 | |
2428 void readline_forward_kill_iline(void) | |
2429 { | |
2430 *ptr_inputline = 0; | |
2431 } | |
2432 | |
2433 void readline_send_multiline(void) | |
2434 { | |
2435 // Validate current multi-line | |
2436 if (scr_get_multimode()) | |
2437 process_command(mkcmdstr("msay send")); | |
2333 } | 2438 } |
2334 | 2439 |
2335 // which_row() | 2440 // which_row() |
2336 // Tells which row our cursor is in, in the command line. | 2441 // Tells which row our cursor is in, in the command line. |
2337 // -2 -> normal text | 2442 // -2 -> normal text |
2550 scr_end_current_completion(); | 2655 scr_end_current_completion(); |
2551 check_offset(-1); | 2656 check_offset(-1); |
2552 refresh_inputline(); | 2657 refresh_inputline(); |
2553 } | 2658 } |
2554 | 2659 |
2555 static void scr_handle_CtrlD(void) | |
2556 { | |
2557 // Validate current multi-line | |
2558 if (scr_get_multimode()) | |
2559 process_command(mkcmdstr("msay send")); | |
2560 } | |
2561 | |
2562 static void add_keyseq(char *seqstr, guint mkeycode, gint value) | 2660 static void add_keyseq(char *seqstr, guint mkeycode, gint value) |
2563 { | 2661 { |
2564 keyseq *ks; | 2662 keyseq *ks; |
2565 | 2663 |
2566 // Let's make sure the length is correct | 2664 // Let's make sure the length is correct |
2803 case ERR: | 2901 case ERR: |
2804 break; | 2902 break; |
2805 case 8: // Ctrl-h | 2903 case 8: // Ctrl-h |
2806 case 127: // Backspace too | 2904 case 127: // Backspace too |
2807 case KEY_BACKSPACE: | 2905 case KEY_BACKSPACE: |
2808 if (ptr_inputline != (char*)&inputLine) { | 2906 readline_backward_kill_char(); |
2809 char *src = ptr_inputline; | |
2810 char *c = prev_char(ptr_inputline, inputLine); | |
2811 ptr_inputline = c; | |
2812 for ( ; *src ; ) | |
2813 *c++ = *src++; | |
2814 *c = 0; | |
2815 check_offset(-1); | |
2816 } | |
2817 break; | 2907 break; |
2818 case KEY_DC:// Del | 2908 case KEY_DC:// Del |
2819 if (*ptr_inputline) | 2909 readline_forward_kill_char(); |
2820 strcpy(ptr_inputline, next_char(ptr_inputline)); | |
2821 break; | 2910 break; |
2822 case KEY_LEFT: | 2911 case KEY_LEFT: |
2823 if (ptr_inputline != (char*)&inputLine) { | 2912 readline_backward_char(); |
2824 ptr_inputline = prev_char(ptr_inputline, inputLine); | |
2825 check_offset(-1); | |
2826 } | |
2827 break; | 2913 break; |
2828 case KEY_RIGHT: | 2914 case KEY_RIGHT: |
2829 if (*ptr_inputline) | 2915 readline_forward_char(); |
2830 ptr_inputline = next_char(ptr_inputline); | |
2831 check_offset(1); | |
2832 break; | 2916 break; |
2833 case 7: // Ctrl-g | 2917 case 7: // Ctrl-g |
2834 scr_cancel_current_completion(); | 2918 scr_cancel_current_completion(); |
2835 scr_end_current_completion(); | 2919 scr_end_current_completion(); |
2836 check_offset(-1); | 2920 check_offset(-1); |
2874 // Reset backup history line | 2958 // Reset backup history line |
2875 cmdhisto_backup[0] = 0; | 2959 cmdhisto_backup[0] = 0; |
2876 } | 2960 } |
2877 break; | 2961 break; |
2878 case KEY_UP: | 2962 case KEY_UP: |
2879 { | 2963 readline_hist_prev(); |
2880 const char *l = scr_cmdhisto_prev(inputLine, | |
2881 ptr_inputline-inputLine); | |
2882 if (l) strcpy(inputLine, l); | |
2883 } | |
2884 break; | 2964 break; |
2885 case KEY_DOWN: | 2965 case KEY_DOWN: |
2886 { | 2966 readline_hist_next(); |
2887 const char *l = scr_cmdhisto_next(inputLine, | |
2888 ptr_inputline-inputLine); | |
2889 if (l) strcpy(inputLine, l); | |
2890 } | |
2891 break; | 2967 break; |
2892 case KEY_PPAGE: | 2968 case KEY_PPAGE: |
2893 scr_CheckAutoAway(TRUE); | 2969 scr_CheckAutoAway(TRUE); |
2894 scr_RosterUp(); | 2970 scr_RosterUp(); |
2895 break; | 2971 break; |
2896 case KEY_NPAGE: | 2972 case KEY_NPAGE: |
2897 scr_CheckAutoAway(TRUE); | 2973 scr_CheckAutoAway(TRUE); |
2898 scr_RosterDown(); | 2974 scr_RosterDown(); |
2899 break; | 2975 break; |
2900 case KEY_HOME: | 2976 case KEY_HOME: |
2901 case 1: | 2977 readline_iline_start(); |
2902 ptr_inputline = inputLine; | |
2903 inputline_offset = 0; | |
2904 break; | 2978 break; |
2905 case 3: // Ctrl-C | 2979 case 3: // Ctrl-C |
2906 scr_handle_CtrlC(); | 2980 scr_handle_CtrlC(); |
2907 break; | 2981 break; |
2908 case 4: // Ctrl-D | |
2909 scr_handle_CtrlD(); | |
2910 break; | |
2911 case KEY_END: | 2982 case KEY_END: |
2912 case 5: | 2983 readline_iline_end(); |
2913 for (; *ptr_inputline; ptr_inputline++) ; | |
2914 check_offset(1); | |
2915 break; | 2984 break; |
2916 case 21: // Ctrl-u | 2985 case 21: // Ctrl-u |
2917 strcpy(inputLine, ptr_inputline); | 2986 readline_backward_kill_iline(); |
2918 ptr_inputline = inputLine; | |
2919 inputline_offset = 0; | |
2920 break; | 2987 break; |
2921 case KEY_EOL: | 2988 case KEY_EOL: |
2922 case 11: // Ctrl-k | 2989 case 11: // Ctrl-k |
2923 *ptr_inputline = 0; | 2990 readline_forward_kill_iline(); |
2924 break; | 2991 break; |
2925 case 16: // Ctrl-p | 2992 case 16: // Ctrl-p |
2926 scr_BufferScrollUpDown(-1, 0); | 2993 scr_BufferScrollUpDown(-1, 0); |
2927 break; | 2994 break; |
2928 case 14: // Ctrl-n | 2995 case 14: // Ctrl-n |