tsm: screen: implement selection extraction
[platform/upstream/kmscon.git] / src / tsm_screen.h
1 /*
2  * TSM - Screen Management
3  *
4  * Copyright (c) 2011-2012 David Herrmann <dh.herrmann@googlemail.com>
5  * Copyright (c) 2011 University of Tuebingen
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files
9  * (the "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included
16  * in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26
27 /*
28  * Screen Management
29  * This screen does not emulate any terminal at all. This subsystem just
30  * provides functions to draw a screen to a framebuffer and modifying the state
31  * of it.
32  */
33
34 #ifndef TSM_SCREEN_H
35 #define TSM_SCREEN_H
36
37 #include <inttypes.h>
38 #include <stdarg.h>
39 #include <stdbool.h>
40 #include <stdlib.h>
41 #include "tsm_unicode.h"
42
43 /* screen objects */
44
45 struct tsm_screen;
46
47 /**
48  * tsm_log_t:
49  * @file: Source code file where the log message originated or NULL
50  * @line: Line number in source code or 0
51  * @func: C function name or NULL
52  * @subs: Subsystem where the message came from or NULL
53  * @sev: Kernel-style severity between 0=FATAL and 7=DEBUG
54  * @format: printf-formatted message
55  * @args: arguments for printf-style @format
56  *
57  * This is the type of a logging callback function. You can always pass NULL
58  * instead of such a function to disable logging.
59  */
60 typedef void (*tsm_log_t) (const char *file,
61                            int line,
62                            const char *func,
63                            const char *subs,
64                            unsigned int sev,
65                            const char *format,
66                            va_list args);
67
68 #define TSM_SCREEN_INSERT_MODE  0x01
69 #define TSM_SCREEN_AUTO_WRAP    0x02
70 #define TSM_SCREEN_REL_ORIGIN   0x04
71 #define TSM_SCREEN_INVERSE      0x08
72 #define TSM_SCREEN_HIDE_CURSOR  0x10
73 #define TSM_SCREEN_FIXED_POS    0x20
74
75 #define TSM_SCREEN_OPT_RENDER_TIMING    0x01
76
77 struct tsm_screen_attr {
78         int8_t fccode;                  /* foreground color code or <0 for rgb */
79         int8_t bccode;                  /* background color code or <0 for rgb */
80         uint8_t fr;                     /* foreground red */
81         uint8_t fg;                     /* foreground green */
82         uint8_t fb;                     /* foreground blue */
83         uint8_t br;                     /* background red */
84         uint8_t bg;                     /* background green */
85         uint8_t bb;                     /* background blue */
86         unsigned int bold : 1;          /* bold character */
87         unsigned int underline : 1;     /* underlined character */
88         unsigned int inverse : 1;       /* inverse colors */
89         unsigned int protect : 1;       /* cannot be erased */
90 };
91
92 typedef int (*tsm_screen_prepare_cb) (struct tsm_screen *con,
93                                       void *data);
94 typedef int (*tsm_screen_draw_cb) (struct tsm_screen *con,
95                                    uint32_t id,
96                                    const uint32_t *ch,
97                                    size_t len,
98                                    unsigned int posx,
99                                    unsigned int posy,
100                                    const struct tsm_screen_attr *attr,
101                                    void *data);
102 typedef int (*tsm_screen_render_cb) (struct tsm_screen *con,
103                                      void *data);
104
105 int tsm_screen_new(struct tsm_screen **out, tsm_log_t log);
106 void tsm_screen_ref(struct tsm_screen *con);
107 void tsm_screen_unref(struct tsm_screen *con);
108
109 void tsm_screen_set_opts(struct tsm_screen *scr, unsigned int opts);
110 void tsm_screen_reset_opts(struct tsm_screen *scr, unsigned int opts);
111 unsigned int tsm_screen_get_opts(struct tsm_screen *scr);
112
113 unsigned int tsm_screen_get_width(struct tsm_screen *con);
114 unsigned int tsm_screen_get_height(struct tsm_screen *con);
115 int tsm_screen_resize(struct tsm_screen *con, unsigned int x,
116                       unsigned int y);
117 int tsm_screen_set_margins(struct tsm_screen *con,
118                            unsigned int top, unsigned int bottom);
119 void tsm_screen_set_max_sb(struct tsm_screen *con, unsigned int max);
120 void tsm_screen_clear_sb(struct tsm_screen *con);
121
122 void tsm_screen_sb_up(struct tsm_screen *con, unsigned int num);
123 void tsm_screen_sb_down(struct tsm_screen *con, unsigned int num);
124 void tsm_screen_sb_page_up(struct tsm_screen *con, unsigned int num);
125 void tsm_screen_sb_page_down(struct tsm_screen *con, unsigned int num);
126 void tsm_screen_sb_reset(struct tsm_screen *con);
127
128 void tsm_screen_set_def_attr(struct tsm_screen *con,
129                              const struct tsm_screen_attr *attr);
130 void tsm_screen_reset(struct tsm_screen *con);
131 void tsm_screen_set_flags(struct tsm_screen *con, unsigned int flags);
132 void tsm_screen_reset_flags(struct tsm_screen *con, unsigned int flags);
133 unsigned int tsm_screen_get_flags(struct tsm_screen *con);
134
135 unsigned int tsm_screen_get_cursor_x(struct tsm_screen *con);
136 unsigned int tsm_screen_get_cursor_y(struct tsm_screen *con);
137
138 void tsm_screen_set_tabstop(struct tsm_screen *con);
139 void tsm_screen_reset_tabstop(struct tsm_screen *con);
140 void tsm_screen_reset_all_tabstops(struct tsm_screen *con);
141
142 void tsm_screen_write(struct tsm_screen *con, tsm_symbol_t ch,
143                       const struct tsm_screen_attr *attr);
144 void tsm_screen_newline(struct tsm_screen *con);
145 void tsm_screen_scroll_up(struct tsm_screen *con, unsigned int num);
146 void tsm_screen_scroll_down(struct tsm_screen *con, unsigned int num);
147 void tsm_screen_move_to(struct tsm_screen *con, unsigned int x,
148                         unsigned int y);
149 void tsm_screen_move_up(struct tsm_screen *con, unsigned int num,
150                         bool scroll);
151 void tsm_screen_move_down(struct tsm_screen *con, unsigned int num,
152                           bool scroll);
153 void tsm_screen_move_left(struct tsm_screen *con, unsigned int num);
154 void tsm_screen_move_right(struct tsm_screen *con, unsigned int num);
155 void tsm_screen_move_line_end(struct tsm_screen *con);
156 void tsm_screen_move_line_home(struct tsm_screen *con);
157 void tsm_screen_tab_right(struct tsm_screen *con, unsigned int num);
158 void tsm_screen_tab_left(struct tsm_screen *con, unsigned int num);
159 void tsm_screen_insert_lines(struct tsm_screen *con, unsigned int num);
160 void tsm_screen_delete_lines(struct tsm_screen *con, unsigned int num);
161 void tsm_screen_insert_chars(struct tsm_screen *con, unsigned int num);
162 void tsm_screen_delete_chars(struct tsm_screen *con, unsigned int num);
163 void tsm_screen_erase_cursor(struct tsm_screen *con);
164 void tsm_screen_erase_chars(struct tsm_screen *con, unsigned int num);
165 void tsm_screen_erase_cursor_to_end(struct tsm_screen *con,
166                                     bool protect);
167 void tsm_screen_erase_home_to_cursor(struct tsm_screen *con,
168                                      bool protect);
169 void tsm_screen_erase_current_line(struct tsm_screen *con,
170                                    bool protect);
171 void tsm_screen_erase_screen_to_cursor(struct tsm_screen *con,
172                                        bool protect);
173 void tsm_screen_erase_cursor_to_screen(struct tsm_screen *con,
174                                        bool protect);
175 void tsm_screen_erase_screen(struct tsm_screen *con, bool protect);
176
177 void tsm_screen_selection_reset(struct tsm_screen *con);
178 void tsm_screen_selection_start(struct tsm_screen *con,
179                                 unsigned int posx,
180                                 unsigned int posy);
181 void tsm_screen_selection_target(struct tsm_screen *con,
182                                  unsigned int posx,
183                                  unsigned int posy);
184 int tsm_screen_selection_copy(struct tsm_screen *con, char **out);
185
186 void tsm_screen_draw(struct tsm_screen *con,
187                      tsm_screen_prepare_cb prepare_cb,
188                      tsm_screen_draw_cb draw_cb,
189                      tsm_screen_render_cb render_cb,
190                      void *data);
191
192 #endif /* TSM_SCREEN_H */