From add1fa92087b07bbb9a394cb06c40983f38d48e9 Mon Sep 17 00:00:00 2001 From: axel Date: Mon, 2 Oct 2006 06:54:23 +1000 Subject: [PATCH] First cleanup of multiline patch - add support for commands longer than one line and do minor cleanups, including removal of a few unused functions darcs-hash:20061001205423-ac50b-2819a086fecb1bcd0ab1bc63bae76956f0181f54.gz --- output.c | 47 --------------------------- output.h | 12 ------- reader.c | 97 ++++++++++++++++++-------------------------------------- screen.c | 49 +++++++++++++++++++++++++--- screen.h | 6 +++- 5 files changed, 80 insertions(+), 131 deletions(-) diff --git a/output.c b/output.c index ac431be05..94b2445cb 100644 --- a/output.c +++ b/output.c @@ -341,34 +341,6 @@ void set_color( int c, int c2 ) } - -/** - perm_left_cursor and parm_right_cursor don't seem to be properly - emulated by many terminal emulators, so we only use plain - curor_left, curor_right... -*/ -void move_cursor( int steps ) -{ - int i; - - if( !steps ) - return; - - if( steps < 0 ){ - for( i=0; i>steps; i--) - { - writembs(cursor_left); - } - } - else - { - for( i=0; i>16)&0xffff ) ); -} - int reader_interupted() { int res=interupted; @@ -617,22 +606,6 @@ static void calc_prompt() } -/** - Write the whole command line (but not the prompt) to the screen. Do - not set the cursor correctly afterwards. -*/ -/*static void write_cmdline() -{ - int i; - - for( i=0; data->output[i]; i++ ) - { - set_color_translated( data->output_color[i] ); - writech( data->output[i] ); - } -} -*/ - void reader_init() { @@ -674,18 +647,13 @@ void reader_exit( int do_exit, int forced ) } -void repaint( int skip_return ) +void repaint() { - int flags = 0; - - if( skip_return ) - flags |= SCREEN_SKIP_RETURN; - calc_prompt(); // assert( wcslen( (wchar_t *)data->prompt_buff.buff)); - s_write( &data->screen, (wchar_t *)data->prompt_buff.buff, data->buff, data->color, data->buff_pos, flags ); + s_write( &data->screen, (wchar_t *)data->prompt_buff.buff, data->buff, data->color, data->buff_pos ); reader_save_status(); } @@ -758,7 +726,7 @@ static void reader_check_status() if( changed ) { - repaint( 0 ); + repaint(); } } @@ -786,7 +754,7 @@ static void remove_backward() data->buff_pos, 0 ); - repaint( 0 ); + repaint(); } @@ -834,7 +802,7 @@ static int insert_char( int c ) data->buff_pos-1, 0 ); - repaint( 0 ); + repaint(); return 1; } @@ -870,7 +838,7 @@ static int insert_str(wchar_t *str) /* repaint */ - repaint( 0 ); + repaint(); return 1; } @@ -1290,7 +1258,7 @@ static int handle_completions( array_list_t *comp ) } free( prefix ); - repaint( 0 ); + repaint(); } @@ -1436,7 +1404,7 @@ static void handle_history( const wchar_t *new_str ) data->buff_pos=wcslen(data->buff); reader_super_highlight_me_plenty( data->color, data->buff_pos, 0 ); - repaint( 0 ); + repaint(); } /** @@ -1521,7 +1489,7 @@ static void handle_token_history( int forward, int reset ) reader_replace_current_token( str ); reader_super_highlight_me_plenty( data->color, data->buff_pos, 0 ); - repaint( 0 ); + repaint(); } else { @@ -1594,7 +1562,7 @@ static void handle_token_history( int forward, int reset ) { reader_replace_current_token( str ); reader_super_highlight_me_plenty( data->color, data->buff_pos, 0 ); - repaint( 0 ); + repaint(); al_push( &data->search_prev, str ); data->search_pos = al_get_count( &data->search_prev )-1; } @@ -1721,16 +1689,12 @@ static void move_word( int dir, int erase ) reader_super_highlight_me_plenty( data->color, data->buff_pos, 0 ); - repaint( 0 ); + repaint(); } else { -/* move_cursor(end_buff_pos-data->buff_pos); - data->buff_pos = end_buff_pos; -*/ data->buff_pos = end_buff_pos; - repaint( 0 ); -// check_colors(); + repaint(); } } @@ -1821,7 +1785,7 @@ static int shell_test( wchar_t *b ) int tmp[1]; - s_write( &data->screen, L"", L"", tmp, 0, 0 ); + s_write( &data->screen, L"", L"", tmp, 0 ); parser_test( b, &sb, L"fish" ); fwprintf( stderr, L"%ls", sb.buff ); @@ -2033,7 +1997,7 @@ static int read_i() if( !reader_exit_forced() && !data->prev_end_loop && has_job ) { writestr(_( L"There are stopped jobs\n" )); - repaint( 0 ); + repaint(); data->end_loop = 0; data->prev_end_loop=1; } @@ -2101,7 +2065,7 @@ wchar_t *reader_readline() data->exec_prompt=1; reader_super_highlight_me_plenty( data->color, data->buff_pos, 0 ); - repaint( 1 ); + repaint(); tcgetattr(0,&old_modes); /* get the current terminal modes */ if( tcsetattr(0,TCSANOW,&shell_modes)) /* set the new modes */ @@ -2186,7 +2150,7 @@ wchar_t *reader_readline() { data->buff_pos = 0; - repaint( 0 ); + repaint(); break; } @@ -2195,7 +2159,7 @@ wchar_t *reader_readline() { data->buff_pos = data->buff_len; - repaint( 0 ); + repaint(); break; } @@ -2203,7 +2167,7 @@ wchar_t *reader_readline() { data->exec_prompt=1; s_reset( &data->screen ); - repaint( 0 ); + repaint(); break; } @@ -2239,8 +2203,8 @@ wchar_t *reader_readline() cursor_steps = token_end - data->buff- data->buff_pos; data->buff_pos += cursor_steps; - move_cursor( cursor_steps ); - + repaint(); + len = data->buff_pos - (begin-data->buff); buffcpy = wcsndup( begin, len ); @@ -2272,7 +2236,7 @@ wchar_t *reader_readline() data->buff[data->buff_len]=L'\0'; - repaint( 0 ); + repaint(); break; } @@ -2291,7 +2255,7 @@ wchar_t *reader_readline() data->buff_pos=0; reader_super_highlight_me_plenty( data->color, data->buff_pos, 0 ); - repaint( 0 ); + repaint(); break; } @@ -2302,7 +2266,7 @@ wchar_t *reader_readline() data->buff[data->buff_len]=L'\0'; reader_super_highlight_me_plenty( data->color, data->buff_pos, 0 ); - repaint( 0 ); + repaint(); break; } @@ -2345,8 +2309,7 @@ wchar_t *reader_readline() reader_replace_current_token( data->search_buff ); } *data->search_buff=0; - repaint(0); - //check_colors(); + repaint(); } @@ -2405,7 +2368,7 @@ wchar_t *reader_readline() } finished=1; data->buff_pos=data->buff_len; - repaint(0); + repaint(); writestr( L"\n" ); break; } @@ -2425,7 +2388,7 @@ wchar_t *reader_readline() default: { s_reset( &data->screen ); - repaint( 0 ); + repaint(); break; } @@ -2505,7 +2468,7 @@ wchar_t *reader_readline() if( data->buff_pos > 0 ) { data->buff_pos--; - repaint( 0 ); + repaint(); } break; } @@ -2516,7 +2479,7 @@ wchar_t *reader_readline() if( data->buff_pos < data->buff_len ) { data->buff_pos++; - repaint( 0 ); + repaint(); } break; } @@ -2526,7 +2489,7 @@ wchar_t *reader_readline() data->buff[0]=0; data->buff_len=0; data->buff_pos=0; - repaint( 0 ); + repaint(); break; } @@ -2563,7 +2526,7 @@ wchar_t *reader_readline() if( clear_screen ) writembs( clear_screen ); s_reset( &data->screen ); - repaint( 0 ); + repaint(); break; } diff --git a/screen.c b/screen.c index fbc35dc34..923d24bba 100644 --- a/screen.c +++ b/screen.c @@ -265,17 +265,38 @@ static void s_output_append_char( screen_t *s, wchar_t b, int c, int prompt_widt default: { line_t *current; + int screen_width = common_get_width(); + int cw = wcwidth(b); + int ew = wcwidth( ellipsis_char ); + int i; + current = (line_t *)al_get( &s->output, line_no ); - + if( !current ) { current = s_create_line(); al_push( &s->output, current ); } + + if( s->output_cursor[0] + cw + ew > screen_width ) + { + al_push_long( ¤t->text, ellipsis_char ); + al_push_long( ¤t->color, 0 ); + + current = s_create_line(); + al_push( &s->output, current ); + s->output_cursor[1]++; + s->output_cursor[0]=0; + for( i=0; i < (prompt_width-ew); i++ ) + { + s_output_append_char( s, L' ', 0, prompt_width ); + } + s_output_append_char( s, ellipsis_char, 0, prompt_width ); + } al_push_long( ¤t->text, b ); al_push_long( ¤t->color, c ); - s->output_cursor[0]+= wcwidth(b); + s->output_cursor[0]+= cw; break; } } @@ -505,15 +526,35 @@ static void s_update( screen_t *scr, wchar_t *prompt ) } -void s_write( screen_t *s, wchar_t *prompt, wchar_t *b, int *c, int cursor, int flags ) +void s_write( screen_t *s, + wchar_t *prompt, + wchar_t *b, + int *c, + int cursor ) { int i; int cursor_arr[2]; int prompt_width = calc_prompt_width( prompt ); + int screen_width = common_get_width(); -// debug( 0, L"Prompt width is %d", prompt_width ); + /* + Ignore huge prompts on small screens + */ + if( prompt_width > (screen_width - 8) ) + { + prompt = L""; + prompt_width = 0; + } + /* + Ignore impossibly small screens + */ + if( screen_width < 4 ) + { + return; + } + s_reset_arr( &s->output ); s->output_cursor[0] = s->output_cursor[1] = 0; diff --git a/screen.h b/screen.h index 4a85edc0d..0ae93db23 100644 --- a/screen.h +++ b/screen.h @@ -24,7 +24,11 @@ typedef struct void s_init( screen_t *s ); void s_destroy( screen_t *s ); -void s_write( screen_t *s, wchar_t *prompt, wchar_t *b, int *c, int cursor, int flags ); +void s_write( screen_t *s, + wchar_t *prompt, + wchar_t *b, + int *c, + int cursor ); void s_reset( screen_t *s ); #endif