diff --git a/common.c b/common.c index a3d536671..228e061f7 100644 --- a/common.c +++ b/common.c @@ -641,12 +641,6 @@ int read_blocked(int fd, void *buf, size_t count) return res; } -int writeb( tputs_arg_t b ) -{ - write( 1, &b, 1 ); -// putc( b, stdout ); - return 0; -} void die_mem() { diff --git a/common.h b/common.h index 9c688947d..895f33134 100644 --- a/common.h +++ b/common.h @@ -223,13 +223,6 @@ int contains_str( const wchar_t *needle, ... ); */ int read_blocked(int fd, void *buf, size_t count); -/** - This is for writing process notification messages. Has to write to - stdout, so clr_eol and such functions will work correctly. Not an - issue since this function is only used in interactive mode anyway. -*/ -int writeb( tputs_arg_t b ); - /** Exit program at once, leaving an error message about running out of memory */ diff --git a/input.c b/input.c index bbb4a8c42..0352766a9 100644 --- a/input.c +++ b/input.c @@ -57,6 +57,7 @@ implementation in fish is as of yet incomplete. #include "event.h" #include "signal.h" #include "translate.h" +#include "output.h" static void input_read_inputrc( wchar_t *fn ); diff --git a/output.c b/output.c index 42669d65f..0825aa7c8 100644 --- a/output.c +++ b/output.c @@ -102,11 +102,22 @@ static size_t writestr_buff_sz=0; */ static char *writestr_buff = 0; +/** + The function used for output +*/ + +static int (*out)(char *str) = &writembs; + static void output_destroy() { free( writestr_buff ); } +void output_set_writer( int (*writer)(char *) ) +{ + out = writer; +} + void set_color( int c, int c2 ) { @@ -130,8 +141,8 @@ void set_color( int c, int c2 ) { c = c2 = FISH_COLOR_NORMAL; if( fg ) - writembs( tparm( fg, 0 ) ); - writembs( exit_attribute_mode ); + out( tparm( fg, 0 ) ); + out( exit_attribute_mode ); return; } @@ -164,7 +175,7 @@ void set_color( int c, int c2 ) Background color changed and is set, so we enter bold mode to make reading easier */ - writembs( enter_bold_mode ); + out( enter_bold_mode ); } if(!bg_set && last_bg_set) { @@ -172,14 +183,14 @@ void set_color( int c, int c2 ) Background color changed and is no longer set, so we exit bold mode */ - writembs( exit_attribute_mode ); + out( exit_attribute_mode ); /* We don't know if exit_attribute_mode resets colors, so we set it to something known. */ if( fg ) { - writembs( tparm( fg, 0 ) ); + out( tparm( fg, 0 ) ); last_color=0; } } @@ -190,8 +201,8 @@ void set_color( int c, int c2 ) if( c==FISH_COLOR_NORMAL ) { if( fg ) - writembs( tparm( fg, 0 ) ); - writembs( exit_attribute_mode ); + out( tparm( fg, 0 ) ); + out( exit_attribute_mode ); last_color2 = FISH_COLOR_NORMAL; } @@ -199,7 +210,7 @@ void set_color( int c, int c2 ) { if( fg ) { - writembs( tparm( fg, c ) ); + out( tparm( fg, c ) ); } } } @@ -212,13 +223,13 @@ void set_color( int c, int c2 ) { if( bg ) { - writembs( tparm( bg, 0 ) ); + out( tparm( bg, 0 ) ); } - writembs(exit_attribute_mode); + out(exit_attribute_mode); if(( last_color != FISH_COLOR_NORMAL ) && fg ) { - writembs(tparm( fg, last_color )); + out(tparm( fg, last_color )); } last_color2 = c2; @@ -227,13 +238,46 @@ void set_color( int c, int c2 ) { if( bg ) { - writembs( tparm( bg, c2 ) ); + out( tparm( bg, c2 ) ); } last_color2 = 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--) + { + out(cursor_left); + } + } + else + { + for( i=0; isteps; i--) - { - writembs(cursor_left); - } - } - else - for( i=0; i