mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
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
This commit is contained in:
parent
8b2059c628
commit
add1fa9208
5 changed files with 80 additions and 131 deletions
47
output.c
47
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<steps; i++)
|
||||
{
|
||||
writembs(cursor_right);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Default output method, simply calls write() on stdout
|
||||
*/
|
||||
|
@ -558,25 +530,6 @@ int write_escaped_str( const wchar_t *str, int max_len )
|
|||
}
|
||||
|
||||
|
||||
int writespace( int c )
|
||||
{
|
||||
if( repeat_char && strlen(repeat_char) )
|
||||
{
|
||||
writembs( tparm( repeat_char, ' ', c ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i=0; i<c; i++ )
|
||||
{
|
||||
out( ' ' );
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int output_color_code( const wchar_t *val )
|
||||
{
|
||||
int j, i, color=FISH_COLOR_NORMAL;
|
||||
|
|
12
output.h
12
output.h
|
@ -102,23 +102,11 @@ void writestr_ellipsis( const wchar_t *str, int max_width );
|
|||
*/
|
||||
int write_escaped_str( const wchar_t *str, int max_len );
|
||||
|
||||
/**
|
||||
parm_ich seems to often be undefined, so we use this
|
||||
workalike. Writes the specified number of spaces.
|
||||
*/
|
||||
int writespace( int c );
|
||||
|
||||
/**
|
||||
Return the internal color code representing the specified color
|
||||
*/
|
||||
int output_color_code( const wchar_t *val );
|
||||
|
||||
/**
|
||||
perm_left_cursor and parm_right_cursor don't seem to be defined
|
||||
very often so we use cursor_left and cursor_right as a fallback.
|
||||
*/
|
||||
void move_cursor( int steps );
|
||||
|
||||
/**
|
||||
This is for writing process notification messages. Has to write to
|
||||
stdout, so clr_eol and such functions will work correctly. Not an
|
||||
|
|
95
reader.c
95
reader.c
|
@ -504,17 +504,6 @@ static void remove_duplicates( array_list_t *l )
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
Translate a highlighting code ()Such as as returned by the highlight function
|
||||
into a color code which is then passed on to set_color.
|
||||
*/
|
||||
|
||||
static void set_color_translated( int c )
|
||||
{
|
||||
set_color( highlight_get_color( c & 0xffff ),
|
||||
highlight_get_color( (c>>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,7 +2203,7 @@ 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;
|
||||
}
|
||||
|
||||
|
|
47
screen.c
47
screen.c
|
@ -265,6 +265,11 @@ 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 )
|
||||
|
@ -273,9 +278,25 @@ static void s_output_append_char( screen_t *s, wchar_t b, int c, int prompt_widt
|
|||
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,14 +526,34 @@ 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;
|
||||
|
|
6
screen.h
6
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
|
||||
|
|
Loading…
Reference in a new issue