2006-10-02 07:22:43 +10:00
/** \file screen.h High level library for handling the terminal screen
The screen library allows the interactive reader to write its
output to screen efficiently by keeping an inetrnal representation
2008-01-14 02:47:47 +10:00
of the current screen contents and trying to find a reasonably
2006-10-02 07:22:43 +10:00
efficient way for transforming that to the desired screen content .
2008-01-14 02:47:47 +10:00
The current implementation is less smart than ncurses allows
and can not for example move blocks of text around to handle text
insertion .
*/
2006-10-02 02:02:58 +10:00
# ifndef FISH_SCREEN_H
# define FISH_SCREEN_H
2006-10-02 07:22:43 +10:00
/**
The struct representing the current and desired screen contents .
*/
2006-10-02 02:02:58 +10:00
typedef struct
{
2008-01-14 02:47:47 +10:00
/**
2006-10-02 07:22:43 +10:00
The internal representation of the desired screen contents .
*/
array_list_t desired ;
/**
The internal representation of the actual screen contents .
*/
array_list_t actual ;
/**
The desired cursor position .
*/
int desired_cursor [ 2 ] ;
/**
The actual cursor position .
*/
int actual_cursor [ 2 ] ;
/**
A stringbuffer containing the prompt which was last printed to
the screen .
*/
string_buffer_t actual_prompt ;
2006-10-05 07:45:02 +10:00
2008-01-14 02:47:47 +10:00
/**
2006-10-05 07:45:02 +10:00
The actual width of the screen at the time of the last screen
write .
*/
2010-09-18 09:51:16 +08:00
int actual_width ;
2006-10-05 09:33:12 +10:00
2006-10-09 23:26:42 +10:00
/**
This flag is set to true when there is reason to suspect that
the parts of the screen lines where the actual content is not
filled in may be non - empty . This means that a clr_eol command
has to be sent to the terminal at the end of each line .
*/
int need_clear ;
2010-09-18 09:51:16 +08:00
2006-10-05 09:33:12 +10:00
/**
These status buffers are used to check if any output has occurred
other than from fish ' s main loop , in which case we need to redraw .
*/
struct stat prev_buff_1 , prev_buff_2 , post_buff_1 , post_buff_2 ;
2006-10-02 02:02:58 +10:00
}
screen_t ;
2006-10-02 07:22:43 +10:00
/**
A struct representing a single line of a screen . Consists of two
array_lists , which must always be of the same length .
*/
2006-10-02 02:02:58 +10:00
typedef struct
{
2006-10-02 07:22:43 +10:00
/**
2006-10-02 09:21:36 +10:00
The text contents of the line . Each element of the array
represents on column of output . Because some characters are two
columns wide , it is perfectly possible for some of the comumns
2010-09-18 09:51:16 +08:00
to be empty .
2006-10-02 07:22:43 +10:00
*/
2006-10-02 02:02:58 +10:00
array_list_t text ;
2006-10-02 07:22:43 +10:00
/**
Highlight information for the line
*/
2006-10-02 02:02:58 +10:00
array_list_t color ;
}
line_t ;
2006-10-02 07:22:43 +10:00
/**
Initialize a new screen struct
*/
2006-10-02 02:02:58 +10:00
void s_init ( screen_t * s ) ;
2006-10-02 07:22:43 +10:00
/**
Free all memory used by the specified screen struct
*/
2006-10-02 02:02:58 +10:00
void s_destroy ( screen_t * s ) ;
2006-10-02 07:22:43 +10:00
/**
This is the main function for the screen putput library . It is used
to define the desired contents of the screen . The screen command
will use it ' s knowlege of the current contents of the screen in
order to render the desired output using as few terminal commands
as possible .
*/
2010-09-18 09:51:16 +08:00
void s_write ( screen_t * s ,
wchar_t * prompt ,
2006-10-02 07:22:43 +10:00
wchar_t * commandline ,
2010-09-18 09:51:16 +08:00
int * colors ,
2006-10-07 10:56:25 +10:00
int * indent ,
2006-10-02 07:22:43 +10:00
int cursor_pos ) ;
2010-09-18 09:51:16 +08:00
/**
2007-10-01 08:53:54 +10:00
This function resets the screen buffers internal knowledge about
the contents of the screen . Use this function when some other
function than s_write has written to the screen .
\ param s the screen to reset
2010-09-18 09:51:16 +08:00
\ param reset_cursor whether the line on which the curor has changed should be assumed to have changed . If \ c reset_cursor is set to 0 , the library will attempt to make sure that the screen area does not seem to move up or down on repaint .
2007-10-01 08:53:54 +10:00
If reset_cursor is incorreclt set to 0 , this may result in screen
contents being erased . If it is incorrectly set to one , it may
result in one or more lines of garbage on screen on the next
repaint . If this happens during a loop , such as an interactive
resizing , there will be one line of garbage for every repaint ,
which will quicly fill the screen .
2006-10-02 07:22:43 +10:00
*/
2007-09-24 18:13:01 +10:00
void s_reset ( screen_t * s , int reset_cursor ) ;
2006-10-02 02:02:58 +10:00
# endif