1 #ifndef __TERM_H
2 #define __TERM_H
3 
4 typedef struct _TERM_WINDOW TERM_WINDOW;
5 
6 #define FG_MASK        ( 0x00ff )
7 #define BG_MASK        ( 0xff00 )
8 #define BG_SHIFT       8
9 
10 /* text attributes */
11 #define ATTR_RESETFG	( 0x010000 )
12 #define ATTR_RESETBG	( 0x020000 )
13 #define ATTR_BOLD	( 0x040000 )
14 #define ATTR_BLINK	( 0x080000 )
15 #define ATTR_UNDERLINE	( 0x100000 )
16 #define ATTR_REVERSE	( 0x200000 )
17 #define ATTR_ITALIC	( 0x400000 )
18 #define ATTR_FGCOLOR24	( 0x1000000 )
19 #define ATTR_BGCOLOR24	( 0x2000000 )
20 
21 #define ATTR_RESET	(ATTR_RESETFG|ATTR_RESETBG)
22 
23 #define ATTR_NOCOLORS (ATTR_UNDERLINE|ATTR_REVERSE|ATTR_BLINK|ATTR_BOLD|ATTR_ITALIC)
24 
25 /* terminal types */
26 #define TERM_TYPE_8BIT		0 /* normal 8bit text */
27 #define TERM_TYPE_UTF8		1
28 #define TERM_TYPE_BIG5		2
29 
30 #include "utf8.h"
31 
32 extern TERM_WINDOW *root_window;
33 extern int term_width, term_height;
34 extern int term_use_colors, term_type;
35 extern int term_use_colors24;
36 extern int term_color256map[];
37 
38 /* Initialize / deinitialize terminal */
39 int term_init(void);
40 void term_deinit(void);
41 
42 /* Gets the current terminal size, returns TRUE if ok. */
43 int term_get_size(int *width, int *height);
44 
45 /* Resize terminal - if width or height is negative,
46    the new size is unknown and should be figured out somehow */
47 void term_resize(int width, int height);
48 void term_resize_final(int width, int height);
49 /* Resize the terminal if needed */
50 void term_resize_dirty(void);
51 
52 /* Returns TRUE if terminal has colors */
53 int term_has_colors(void);
54 /* Force the colors on any way you can */
55 void term_force_colors(int set);
56 
57 /* Clear screen */
58 void term_clear(void);
59 /* Beep */
60 void term_beep(void);
61 
62 /* Create a new window in terminal */
63 TERM_WINDOW *term_window_create(int x, int y, int width, int height);
64 /* Destroy a terminal window */
65 void term_window_destroy(TERM_WINDOW *window);
66 
67 /* Move/resize window */
68 void term_window_move(TERM_WINDOW *window, int x, int y,
69 		      int width, int height);
70 /* Clear window */
71 void term_window_clear(TERM_WINDOW *window);
72 /* Scroll window up/down */
73 void term_window_scroll(TERM_WINDOW *window, int count);
74 
75 #ifdef TERM_TRUECOLOR
76 #define term_set_color(window, col) term_set_color2(window, (col) &~(ATTR_FGCOLOR24|ATTR_BGCOLOR24), UINT_MAX, UINT_MAX)
77 void term_set_color2(TERM_WINDOW *window, int col, unsigned int fgcol24, unsigned int bgcol24);
78 #else
79 #define term_set_color2(window, col, unused1, unused2) term_set_color(window, col)
80 void term_set_color(TERM_WINDOW *window, int col);
81 #endif
82 
83 void term_move(TERM_WINDOW *window, int x, int y);
84 void term_addch(TERM_WINDOW *window, char chr);
85 void term_add_unichar(TERM_WINDOW *window, unichar chr);
86 int  term_addstr(TERM_WINDOW *window, const char *str);
87 void term_clrtoeol(TERM_WINDOW *window);
88 void term_window_clrtoeol(TERM_WINDOW* window, int ypos);
89 void term_window_clrtoeol_abs(TERM_WINDOW* window, int ypos_abs);
90 
91 void term_move_cursor(int x, int y);
92 
93 void term_refresh_freeze(void);
94 void term_refresh_thaw(void);
95 void term_refresh(TERM_WINDOW *window);
96 
97 void term_stop(void);
98 
99 void term_set_appkey_mode(int enable);
100 void term_set_bracketed_paste_mode(int enable);
101 
102 /* keyboard input handling */
103 void term_set_input_type(int type);
104 void term_gets(GArray *buffer, int *line_count);
105 
106 /* internal */
107 void term_common_init(void);
108 void term_common_deinit(void);
109 
110 void term_environment_check(void);
111 
112 #endif
113