From 8bf0a14bd5124219d76ac40ff985380bb00297d5 Mon Sep 17 00:00:00 2001 From: axel Date: Tue, 13 Dec 2005 20:18:59 +1000 Subject: Autodetect common escape codes in fish_prompt output darcs-hash:20051213101859-ac50b-0ff01bb168d894d401d3d93cc11740789bac0d62.gz --- reader.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 126 insertions(+), 11 deletions(-) (limited to 'reader.c') diff --git a/reader.c b/reader.c index c4183916..e790db3b 100644 --- a/reader.c +++ b/reader.c @@ -620,6 +620,129 @@ void reader_write_title() set_color( FISH_COLOR_RESET, FISH_COLOR_RESET ); } +/** + Tests if the specified narrow character sequence is present at the + specified position of the specified wide character string. All of + \c seq must match, but str may be longer than seq. +*/ +static int try_sequence( char *seq, wchar_t *str ) +{ + int i; + + for( i=0;; i++ ) + { + if( !seq[i] ) + return i; + + if( seq[i] != str[i] ) + return 0; + } + + return 0; +} + +/** + Calculate the width of the specified prompt. Does some clever magic + to detect common escape sequences that may be embeded in a prompt, + such as color codes. +*/ +static int calc_prompt_width( array_list_t *arr ) +{ + int res = 0; + int i, j, k; + + for( i=0; iexec_prompt is set, the prompt command is first evaluated, and the title will be reexecuted as @@ -649,14 +772,8 @@ static void write_prompt() al_init( &prompt_list ); } } - data->prompt_width=0; - for( i=0; iprompt_width += my_wcswidth( next ); - } + + data->prompt_width=calc_prompt_width( &prompt_list ); data->exec_prompt = 0; reader_write_title(); @@ -2509,9 +2626,7 @@ wchar_t *reader_readline() if( last_char != R_YANK && last_char != R_YANK_POP ) yank=0; - - - switch (c) + switch( c ) { /* go to beginning of line*/ -- cgit v1.2.3