File: sys_win.cpp

package info (click to toggle)
cgdb 0.8.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,468 kB
  • sloc: cpp: 12,169; ansic: 10,042; sh: 4,383; exp: 640; makefile: 197
file content (340 lines) | stat: -rw-r--r-- 5,811 bytes parent folder | download | duplicates (2)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#if HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */

#if HAVE_CURSES_H
#include <curses.h>
#elif HAVE_NCURSES_CURSES_H
#include <ncurses/curses.h>
#endif

#include "cgdb_clog.h"
#include "sys_util.h"
#include "sys_win.h"

const int SWIN_A_NORMAL = A_NORMAL;
const int SWIN_A_STANDOUT = A_STANDOUT;
const int SWIN_A_UNDERLINE = A_UNDERLINE;
const int SWIN_A_REVERSE = A_REVERSE;
const int SWIN_A_BLINK = A_BLINK;
const int SWIN_A_DIM = A_DIM;
const int SWIN_A_BOLD = A_BOLD;

const int SWIN_KEY_BACKSPACE = KEY_BACKSPACE;

SWIN_CHTYPE SWIN_SYM_VLINE;
SWIN_CHTYPE SWIN_SYM_HLINE;
SWIN_CHTYPE SWIN_SYM_LTEE;

static bool initscr_intialized = false;

/**
 * Set the ESCDELAY environment variable.
 *
 * This environment variable is necessary for ncurses to not delay
 * user input when the ESCAPE key is pressed. CGDB does it's own handling
 * of escape.
 *
 * @return
 * True on success or False on failure
 */
static bool swin_set_escdelay(void)
{
    static char escdelay[] = "ESCDELAY=0";
    bool success = putenv(escdelay) == 0;
                
    if (!success)
        clog_error(CLOG_CGDB, "putenv(\"%s\") failed", escdelay);

    return success;
}

bool swin_start()
{
    bool success = swin_set_escdelay();
    if (success) {
        success = swin_initscr() != NULL;
        if (success) {
            if (swin_has_colors()) {
                swin_start_color();
                swin_use_default_colors();
            }

            swin_refresh();
        }
    }

    return success;
}

/* Determines the terminal type and initializes all data structures. */
SWINDOW *swin_initscr()
{
    SWINDOW *win = (SWINDOW *)initscr();

#ifdef HAVE_CYGWIN
    SWIN_SYM_VLINE = ':';
#else
    SWIN_SYM_VLINE = ACS_VLINE;
#endif

    SWIN_SYM_HLINE = ACS_HLINE;
    SWIN_SYM_LTEE = ACS_LTEE;
    
    initscr_intialized = true;

    return win;
}

int swin_endwin()
{
    int result = 0;
    
    if (initscr_intialized)
        result = endwin();

    return result;
}

int swin_lines()
{
    return LINES;
}

int swin_cols()
{
    return COLS;
}

int swin_colors()
{
    return COLORS;
}

int swin_color_pairs()
{
    return COLOR_PAIRS;
}

int swin_has_colors()
{
    return has_colors();
}

int swin_start_color()
{
    int result = start_color();
    if (result == ERR) {
        clog_error(CLOG_CGDB, "start_color failed");
    }
    return result;
}

int swin_use_default_colors()
{
    int result = use_default_colors();
    if (result == ERR) {
        clog_error(CLOG_CGDB, "use_default_colors failed");
    }
    return result;
}

bool swin_supports_default_color_pairs_extension()
{
    int result = init_pair(65, -1, COLOR_BLACK);
    return result != ERR;
}

int swin_resizeterm(int lines, int columns)
{
    return resizeterm(lines, columns);
}

int swin_scrl(int n)
{
    return scrl(n);
}

int swin_keypad(SWINDOW *win, int bf)
{
    return keypad((WINDOW *)win, bf);
}

char *swin_tigetstr(const char *capname)
{
    return tigetstr((char*)capname);
}

int swin_move(int y, int x)
{
    return move(y, x);
}

int swin_wmove(SWINDOW *win, int y, int x)
{
    return wmove((WINDOW *)win, y, x);
}

int swin_wattron(SWINDOW *win, int attrs)
{
    return wattron((WINDOW *)win, attrs);
}

int swin_wattroff(SWINDOW *win, int attrs)
{
    return wattroff((WINDOW *)win, attrs);
}

SWINDOW *swin_newwin(int nlines, int ncols, int begin_y, int begin_x)
{
    return (SWINDOW *)newwin(nlines, ncols, begin_y, begin_x);
}

int swin_delwin(SWINDOW *win)
{
    return delwin((WINDOW *)win);
}

int swin_curs_set(int visibility)
{
    return curs_set(visibility);
}

int swin_getcurx(const SWINDOW *win)
{
    return getcurx((WINDOW *)win);
}

int swin_getcury(const SWINDOW *win)
{
    return getcury((WINDOW *)win);
}

int swin_getbegx(const SWINDOW *win)
{
    return getbegx((WINDOW *)win);
}

int swin_getbegy(const SWINDOW *win)
{
    return getbegy((WINDOW *)win);
}

int swin_getmaxx(const SWINDOW *win)
{
    return getmaxx((WINDOW *)win);
}

int swin_getmaxy(const SWINDOW *win)
{
    return getmaxy((WINDOW *)win);
}

int swin_werase(SWINDOW *win)
{
    return werase((WINDOW *)win);
}

int swin_wvline(SWINDOW *win, SWIN_CHTYPE ch, int n)
{
    return wvline((WINDOW *)win, ch, n);
}

int swin_waddch(SWINDOW *win, const SWIN_CHTYPE ch)
{
    return waddch((WINDOW *)win, ch);
}

int swin_wprintw(SWINDOW *win, const char *fmt, ...)
{
    int ret;
    va_list ap;

    va_start(ap, fmt);
    ret = vw_printw((WINDOW *)win, fmt, ap);
    va_end(ap);

    return ret;
}

int swin_waddnstr(SWINDOW *win, const char *str, int n)
{
    return waddnstr((WINDOW *)win, str, n);
}

int swin_wclrtoeol(SWINDOW *win)
{
    return wclrtoeol((WINDOW *)win);
}

int swin_mvwprintw(SWINDOW *win, int y, int x, const char *fmt, ...)
{
    int ret;

    ret = wmove((WINDOW *)win, y, x);
    if (ret != ERR)
    {
        va_list ap;

        va_start(ap, fmt);
        ret = vw_printw((WINDOW *)win, fmt, ap);
        va_end(ap);
    }

    return ret;
}

int swin_refresh()
{
    return refresh();
}

int swin_wnoutrefresh(SWINDOW *win)
{
    return wnoutrefresh((WINDOW *)win);
}

int swin_wrefresh(SWINDOW *win)
{
    return wrefresh((WINDOW *)win);
}

int swin_doupdate()
{
    return doupdate();
}

int swin_init_pair(int pair, int f, int b)
{
    int result = init_pair(pair, f, b);
    if (result == ERR) {
        clog_error(CLOG_CGDB, "init_pair failed pair=%d f=%d b=%d", pair, f, b);
    }

    return result;
}

int swin_pair_content(int pair, int *fin, int *bin)
{
    int ret;
    short f, b;

    ret = pair_content(pair, &f, &b);
    if (ret == ERR) {
        clog_error(CLOG_CGDB, "pair_content failed pair=%d", pair);
    }

    *fin = f;
    *bin = b;
    return ret;
}

int swin_color_pair(int pair)
{
    return COLOR_PAIR(pair);
}

int swin_raw(void)
{
    return raw();
}