aboutsummaryrefslogtreecommitdiffhomepage
path: root/screen.h
blob: a50eacb06c9d9f776dc0c21648f8b1e4546bcb2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/** \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
	of the current screen contents and trying to find the most
	efficient way for transforming that to the desired screen content.
*/
#ifndef FISH_SCREEN_H
#define FISH_SCREEN_H

/**
   The struct representing the current and desired screen contents.
*/
typedef struct
{
	/*
	  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;

	/*
	  The actual width of the screen at the time of the last screen
	  write.
	*/
	int actual_width;	

	/**
	   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;
	
	/**
	   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;
}
	screen_t;

/**
   A struct representing a single line of a screen. Consists of two
   array_lists, which must always be of the same length.
*/
typedef struct
{
	/**
	   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
	   to be empty. 
	*/
	array_list_t text;
	/**
	   Highlight information for the line
	*/
	array_list_t color;
}
	line_t;

/**
   Initialize a new screen struct
*/
void s_init( screen_t *s );

/**
   Free all memory used by the specified screen struct
*/
void s_destroy( screen_t *s );

/**
   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.
*/
void s_write( screen_t *s, 
			  wchar_t *prompt, 
			  wchar_t *commandline,
			  int *colors, 
			  int *indent,
			  int cursor_pos );

/** 
	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.
*/
void s_reset( screen_t *s );

#endif