comparison mcabber/src/screen.c @ 1172:334ae9f498f1

Add some more iline functions (Lego12239)
author Mikael Berthe <mikael@lilotux.net>
date Tue, 03 Apr 2007 20:30:28 +0200
parents 03a38b7ad2e0
children 960f34ec22a2
comparison
equal deleted inserted replaced
1171:03a38b7ad2e0 1172:334ae9f498f1
49 49
50 static unsigned short int Log_Win_Height; 50 static unsigned short int Log_Win_Height;
51 static unsigned short int Roster_Width; 51 static unsigned short int Roster_Width;
52 52
53 static inline void check_offset(int); 53 static inline void check_offset(int);
54 static void scr_cancel_current_completion(void);
55 static void scr_end_current_completion(void);
56 static void scr_insert_text(const char*);
57 static void scr_handle_tab(void);
54 58
55 static GHashTable *winbufhash; 59 static GHashTable *winbufhash;
56 60
57 typedef struct { 61 typedef struct {
58 GList *hbuf; 62 GList *hbuf;
2311 2315
2312 // readline_backward_word() 2316 // readline_backward_word()
2313 // Move back to the start of the current or previous word 2317 // Move back to the start of the current or previous word
2314 void readline_backward_word(void) 2318 void readline_backward_word(void)
2315 { 2319 {
2316 char *old_ptr_inputLine = ptr_inputline; 2320 int i = 0;
2317 int spaceallowed = 1;
2318 2321
2319 if (ptr_inputline == inputLine) return; 2322 if (ptr_inputline == inputLine) return;
2320 2323
2321 for (ptr_inputline = prev_char(ptr_inputline, inputLine) ; 2324 if (iswalnum(get_char(ptr_inputline)) &&
2322 ptr_inputline > inputLine ; 2325 !iswalnum(get_char(prev_char(ptr_inputline, inputLine))))
2323 ptr_inputline = prev_char(ptr_inputline, inputLine)) { 2326 i--;
2327
2328 for( ;
2329 ptr_inputline > inputLine;
2330 ptr_inputline = prev_char(ptr_inputline, inputLine)) {
2324 if (!iswalnum(get_char(ptr_inputline))) { 2331 if (!iswalnum(get_char(ptr_inputline))) {
2325 if (iswblank(get_char(ptr_inputline))) { 2332 if (i) {
2326 if (!spaceallowed) break; 2333 ptr_inputline = next_char(ptr_inputline);
2327 } else spaceallowed = 0; 2334 break;
2328 } else spaceallowed = 0; 2335 }
2329 } 2336 } else i++;
2330 2337 }
2331 if (ptr_inputline < prev_char(old_ptr_inputLine, inputLine)
2332 && iswblank(get_char(ptr_inputline))
2333 && iswblank(get_char(next_char(ptr_inputline))))
2334 ptr_inputline = next_char(ptr_inputline);
2335 2338
2336 check_offset(-1); 2339 check_offset(-1);
2337 } 2340 }
2338 2341
2339 // readline_forward_word() 2342 // readline_forward_word()
2340 // Move forward to the end of the next word 2343 // Move forward to the end of the next word
2341 void readline_forward_word(void) 2344 void readline_forward_word(void)
2342 { 2345 {
2343 int spaceallowed = 1; 2346 int stopsymbol_allowed = 1;
2344 2347
2345 while (*ptr_inputline) { 2348 while (*ptr_inputline) {
2349 if (!iswalnum(get_char(ptr_inputline))) {
2350 if (!stopsymbol_allowed) break;
2351 } else stopsymbol_allowed = 0;
2346 ptr_inputline = next_char(ptr_inputline); 2352 ptr_inputline = next_char(ptr_inputline);
2353 }
2354
2355 check_offset(1);
2356 }
2357
2358 void readline_updowncase_word(int upcase)
2359 {
2360 int stopsymbol_allowed = 1;
2361
2362 while (*ptr_inputline) {
2347 if (!iswalnum(get_char(ptr_inputline))) { 2363 if (!iswalnum(get_char(ptr_inputline))) {
2348 if (iswblank(get_char(ptr_inputline))) { 2364 if (!stopsymbol_allowed) break;
2349 if (!spaceallowed) break; 2365 } else {
2350 } else spaceallowed = 0; 2366 stopsymbol_allowed = 0;
2351 } else spaceallowed = 0; 2367 if (upcase)
2368 *ptr_inputline = towupper(get_char(ptr_inputline));
2369 else
2370 *ptr_inputline = towlower(get_char(ptr_inputline));
2371 }
2372 ptr_inputline = next_char(ptr_inputline);
2373 }
2374
2375 check_offset(1);
2376 }
2377
2378 void readline_capitalize_word(void)
2379 {
2380 int stopsymbol_allowed = 1;
2381 int upcased = 0;
2382
2383 while (*ptr_inputline) {
2384 if (!iswalnum(get_char(ptr_inputline))) {
2385 if (!stopsymbol_allowed) break;
2386 } else {
2387 stopsymbol_allowed = 0;
2388 if (!upcased) {
2389 *ptr_inputline = towupper(get_char(ptr_inputline));
2390 upcased = 1;
2391 } else *ptr_inputline = towlower(get_char(ptr_inputline));
2392 }
2393 ptr_inputline = next_char(ptr_inputline);
2352 } 2394 }
2353 2395
2354 check_offset(1); 2396 check_offset(1);
2355 } 2397 }
2356 2398
2366 { 2408 {
2367 if (!*ptr_inputline) return; 2409 if (!*ptr_inputline) return;
2368 2410
2369 ptr_inputline = next_char(ptr_inputline); 2411 ptr_inputline = next_char(ptr_inputline);
2370 check_offset(1); 2412 check_offset(1);
2413 }
2414
2415 int readline_accept_line(void)
2416 {
2417 scr_CheckAutoAway(TRUE);
2418 if (process_line(inputLine))
2419 return 255;
2420 // Add line to history
2421 scr_cmdhisto_addline(inputLine);
2422 // Reset the line
2423 ptr_inputline = inputLine;
2424 *ptr_inputline = 0;
2425 inputline_offset = 0;
2426
2427 // Reset history line pointer
2428 cmdhisto_cur = NULL;
2429
2430 return 0;
2431 }
2432
2433 int readline_accept_line_down_hist(void)
2434 {
2435 scr_CheckAutoAway(TRUE);
2436 if (process_line(inputLine))
2437 return 255;
2438 // Add line to history
2439 scr_cmdhisto_addline(inputLine);
2440 // Reset the line
2441 ptr_inputline = inputLine;
2442 *ptr_inputline = 0;
2443 inputline_offset = 0;
2444
2445 // Use next history line instead of a blank line
2446 const char *l = scr_cmdhisto_next("", 0);
2447 if (l) strcpy(inputLine, l);
2448 // Reset backup history line
2449 cmdhisto_backup[0] = 0;
2450
2451 return 0;
2452 }
2453
2454 void readline_cancel_completion(void)
2455 {
2456 scr_cancel_current_completion();
2457 scr_end_current_completion();
2458 check_offset(-1);
2459 }
2460
2461 void readline_do_completion(void)
2462 {
2463 int i, n;
2464
2465 if (scr_get_multimode() != 2) {
2466 // Not in verbatim multi-line mode
2467 scr_handle_tab();
2468 } else {
2469 // Verbatim multi-line mode: expand tab
2470 char tabstr[9];
2471 n = 8 - (ptr_inputline - inputLine) % 8;
2472 for (i = 0; i < n; i++)
2473 tabstr[i] = ' ';
2474 tabstr[i] = '\0';
2475 scr_insert_text(tabstr);
2476 }
2477 check_offset(0);
2478 }
2479
2480 void readline_refresh_screen(void)
2481 {
2482 scr_CheckAutoAway(TRUE);
2483 ParseColors();
2484 scr_Resize();
2485 redrawwin(stdscr);
2486 }
2487
2488 void readline_disable_chat_mode(void)
2489 {
2490 scr_CheckAutoAway(TRUE);
2491 currentWindow = NULL;
2492 chatmode = FALSE;
2493 if (current_buddy)
2494 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE);
2495 scr_RosterVisibility(1);
2496 scr_UpdateChatStatus(FALSE);
2497 top_panel(chatPanel);
2498 top_panel(inputPanel);
2499 update_panels();
2371 } 2500 }
2372 2501
2373 void readline_hist_prev(void) 2502 void readline_hist_prev(void)
2374 { 2503 {
2375 const char *l = scr_cmdhisto_prev(inputLine, ptr_inputline-inputLine); 2504 const char *l = scr_cmdhisto_prev(inputLine, ptr_inputline-inputLine);
2913 break; 3042 break;
2914 case KEY_RIGHT: 3043 case KEY_RIGHT:
2915 readline_forward_char(); 3044 readline_forward_char();
2916 break; 3045 break;
2917 case 7: // Ctrl-g 3046 case 7: // Ctrl-g
2918 scr_cancel_current_completion(); 3047 readline_cancel_completion();
2919 scr_end_current_completion();
2920 check_offset(-1);
2921 break; 3048 break;
2922 case 9: // Tab 3049 case 9: // Tab
2923 if (scr_get_multimode() != 2) { 3050 readline_do_completion();
2924 // Not in verbatim multi-line mode
2925 scr_handle_tab();
2926 } else {
2927 // Verbatim multi-line mode: expand tab
2928 char tabstr[9];
2929 int i, n;
2930 n = 8 - (ptr_inputline - inputLine) % 8;
2931 for (i = 0; i < n; i++)
2932 tabstr[i] = ' ';
2933 tabstr[i] = '\0';
2934 scr_insert_text(tabstr);
2935 }
2936 check_offset(0);
2937 break; 3051 break;
2938 case 13: // Enter 3052 case 13: // Enter
3053 if (readline_accept_line() == 255) return 255;
3054 break;
2939 case 15: // Ctrl-o ("accept-line-and-down-history") 3055 case 15: // Ctrl-o ("accept-line-and-down-history")
2940 scr_CheckAutoAway(TRUE); 3056 if (readline_accept_line_down_hist() == 255) return 255;
2941 if (process_line(inputLine))
2942 return 255;
2943 // Add line to history
2944 scr_cmdhisto_addline(inputLine);
2945 // Reset the line
2946 ptr_inputline = inputLine;
2947 *ptr_inputline = 0;
2948 inputline_offset = 0;
2949
2950 if (key == 13) // Enter
2951 {
2952 // Reset history line pointer
2953 cmdhisto_cur = NULL;
2954 } else { // down-history
2955 // Use next history line instead of a blank line
2956 const char *l = scr_cmdhisto_next("", 0);
2957 if (l) strcpy(inputLine, l);
2958 // Reset backup history line
2959 cmdhisto_backup[0] = 0;
2960 }
2961 break; 3057 break;
2962 case KEY_UP: 3058 case KEY_UP:
2963 readline_hist_prev(); 3059 readline_hist_prev();
2964 break; 3060 break;
2965 case KEY_DOWN: 3061 case KEY_DOWN:
3008 case 517: 3104 case 517:
3009 case 518: // Ctrl-Right 3105 case 518: // Ctrl-Right
3010 readline_forward_word(); 3106 readline_forward_word();
3011 break; 3107 break;
3012 case 12: // Ctrl-l 3108 case 12: // Ctrl-l
3013 scr_CheckAutoAway(TRUE); 3109 readline_refresh_screen();
3014 ParseColors();
3015 scr_Resize();
3016 redrawwin(stdscr);
3017 break; 3110 break;
3018 case KEY_RESIZE: 3111 case KEY_RESIZE:
3019 scr_Resize(); 3112 scr_Resize();
3020 break; 3113 break;
3021 case 27: // ESC 3114 case 27: // ESC
3022 scr_CheckAutoAway(TRUE); 3115 readline_disable_chat_mode();
3023 currentWindow = NULL;
3024 chatmode = FALSE;
3025 if (current_buddy)
3026 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE);
3027 scr_RosterVisibility(1);
3028 scr_UpdateChatStatus(FALSE);
3029 top_panel(chatPanel);
3030 top_panel(inputPanel);
3031 update_panels();
3032 break; 3116 break;
3033 default: 3117 default:
3034 display_char = TRUE; 3118 display_char = TRUE;
3035 } // switch 3119 } // switch
3036 3120