Move the move_cursor and writeb functions to output.c, and make the output function used by output.c configurable

darcs-hash:20060216134025-ac50b-360d4816ee2c3f2ffdc8e5660502cb97b31d699e.gz
This commit is contained in:
axel 2006-02-16 23:40:25 +10:00
parent cc69afc4fe
commit 94cae410f3
6 changed files with 84 additions and 49 deletions

View file

@ -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()
{

View file

@ -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
*/

View file

@ -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 );

View file

@ -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; i<steps; i++)
{
out(cursor_right);
}
}
}
int writeb( tputs_arg_t b )
{
write( 1, &b, 1 );
return 0;
}
int writembs( char *str )
{
#ifdef TPUTS_KLUDGE
@ -385,7 +429,7 @@ int writespace( int c )
{
if( repeat_char && strlen(repeat_char) )
{
writembs( tparm( repeat_char, ' ', c ) );
out( tparm( repeat_char, ' ', c ) );
}
else
{

View file

@ -80,7 +80,9 @@ void set_color( int c, int c2 );
/**
Write a char * narrow string to FD 1, needed for the terminfo
strings.
strings. This is usually just a wrapper aound tputs, using writeb
as the sending function. But a weird bug on PPC Linux means that on
this platform, write is instead used directly.
*/
int writembs( char *str );
@ -116,4 +118,24 @@ int writespace( int c );
*/
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
issue since this function is only used in interactive mode anyway.
*/
int writeb( tputs_arg_t b );
/**
Set the function used for writing in move_cursor, writespace and
set_color. By default, writembs is used.
*/
void output_set_writer( int (*writer)(char *) );
#endif

View file

@ -834,25 +834,6 @@ static void write_cmdline()
}
}
/**
perm_left_cursor and parm_right_cursor don't seem to be defined as
often as cursor_left and cursor_right, so we use this workalike.
*/
static void move_cursor( int steps )
{
int i;
if( steps < 0 ){
for( i=0; i>steps; i--)
{
writembs(cursor_left);
}
}
else
for( i=0; i<steps; i++)
writembs(cursor_right);
}
void reader_init()
{
@ -1462,7 +1443,7 @@ static void run_pager( wchar_t *prefix, int is_quoted, array_list_t *comp )
/**
Handle the list of completions. This means the following:
- If the list is empty, flash the terminal.
- If the list contains one element, write the whole element, and if
the element does not end on a '/', '@', ':', or a '=', also write a trailing
@ -2792,8 +2773,8 @@ wchar_t *reader_readline()
case R_CLEAR_SCREEN:
{
writembs( clear_screen );
if( clear_screen )
writembs( clear_screen );
repaint();
break;
}