3 * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de>
4 * Copyright (C) 2008 Ulf Jordan <jordan@chalmers.se>
5 * Copyright (C) 2008-2009 coresystems GmbH
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * This is a tiny implementation of the (n)curses library intended to be
33 * used in embedded/firmware/BIOS code where no libc or operating system
34 * environment is available and code size is very important.
37 * - Small object code.
39 * - Doesn't require a libc (no glibc/uclibc/dietlibc/klibc/newlib).
40 * - Works without any other external libraries or header files.
41 * - Works without an underlying operating system.
42 * - Doesn't use files, signals, syscalls, ttys, library calls, etc.
43 * - Doesn't do any dynamic memory allocation (no malloc() and friends).
44 * - All data structures are statically allocated.
45 * - Supports standard VGA console (80x25) and serial port console.
46 * - This includes character output and keyboard input over serial.
47 * - Supports beep() through a minimal PC speaker driver.
50 * - Only implements a small subset of the (n)curses functions.
51 * - Only implements very few sanity checks (for smaller code).
52 * - Thus: Don't do obviously stupid things in your code.
53 * - Doesn't implement the 'form', 'panel', and 'menu' extensions.
54 * - Only implements C bindings (no C++, Ada95, or others).
55 * - Doesn't include wide character support.
60 #undef _XOPEN_SOURCE_EXTENDED
61 #define _XOPEN_SOURCE_EXTENDED 1
65 /* Statically allocate all structures (no malloc())! */
66 static WINDOW window_list
[MAX_WINDOWS
];
67 static int window_count
= 0;
70 static struct ldat ldat_list
[MAX_WINDOWS
][SCREEN_Y
];
71 static int ldat_count
= 0;
73 /* One item bigger than SCREEN_X to reserve space for a NUL byte. */
74 static NCURSES_CH_T linebuf_list
[SCREEN_Y
* MAX_WINDOWS
][SCREEN_X
+ 1];
75 static int linebuf_count
= 0;
78 int COLORS
; /* Currently unused? */
79 int COLOR_PAIRS
= 255;
92 /* See terminfo(5). */
93 chtype fallback_acs_map
[128] =
95 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
96 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
97 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
98 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
99 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
100 ' ', ' ', ' ', '>', '<', '^', 'v', ' ',
101 '#', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
102 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
103 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
104 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
105 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
106 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
107 '+', ':', ' ', ' ', ' ', ' ', '\\', '#',
108 '#', '#', '+', '+', '+', '+', '+', '~',
109 '-', '-', '-', '_', '+', '+', '+', '+',
110 '|', '<', '>', '*', '!', 'f', 'o', ' ',
113 #if CONFIG(LP_SERIAL_CONSOLE)
114 #if CONFIG(LP_SERIAL_ACS_FALLBACK)
115 chtype serial_acs_map
[128];
117 /* See acsc of vt100. */
118 chtype serial_acs_map
[128] =
120 0, 0, 0, 0, 0, 0, 0, 0,
121 0, 0, 0, 0, 0, 0, 0, 0,
122 0, 0, 0, 0, 0, 0, 0, 0,
123 0, 0, 0, 0, 0, 0, 0, 0,
124 0, 0, 0, 0, 0, 0, 0, 0,
125 0, 0, 0, 0, 0, 0, 0, 0,
126 0, 0, 0, 0, 0, 0, 0, 0,
127 0, 0, 0, 0, 0, 0, 0, 0,
128 0, 0, 0, 0, 0, 0, 0, 0,
129 0, 0, 0, 0, 0, 0, 0, 0,
130 0, 0, 0, 0, 0, 0, 0, 0,
131 0, 0, 0, 0, 0, 0, 0, 0,
132 '`', 'a', 0, 0, 0, 0, 'f', 'g',
133 0, 0, 'j', 'k', 'l', 'm', 'n', 'o',
134 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
135 'x', 'y', 'z', '{', '|', '}', '~', 0,
140 #if CONFIG(LP_VIDEO_CONSOLE)
141 /* See acsc of linux. */
142 chtype console_acs_map
[128] =
144 0, 0, 0, 0, 0, 0, 0, 0,
145 0, 0, 0, 0, 0, 0, 0, 0,
146 0, 0, 0, 0, 0, 0, 0, 0,
147 0, 0, 0, 0, 0, 0, 0, 0,
148 0, 0, 0, 0, 0, 0, 0, 0,
149 0, 0, 0, '\020', '\021', '\030', '\031', 0,
150 '\333', 0, 0, 0, 0, 0, 0, 0,
151 0, 0, 0, 0, 0, 0, 0, 0,
152 0, 0, 0, 0, 0, 0, 0, 0,
153 0, 0, 0, 0, 0, 0, 0, 0,
154 0, 0, 0, 0, 0, 0, 0, 0,
155 0, 0, 0, 0, 0, 0, 0, 0,
156 '\004', '\261', 0, 0, 0, 0, '\370', '\361',
157 '\260', '\316', '\331', '\277', '\332', '\300', '\305', '~',
158 '\304', '\304', '\304', '_', '\303', '\264', '\301', '\302',
159 '\263', '\363', '\362', '\343', '\330', '\234', '\376', 0,
163 // FIXME: Ugly (and insecure!) hack!
164 char sprintf_tmp
[1024];
166 int curses_flags
= (F_ENABLE_CONSOLE
| F_ENABLE_SERIAL
);
168 /* Return bit mask for clearing color pair number if given ch has color */
169 #define COLOR_MASK(ch) (~(attr_t)((ch) & A_COLOR ? A_COLOR : 0))
171 /* Compute a rendition of the given char correct for the current context. */
172 static inline NCURSES_CH_T
render_char(WINDOW
*win
, NCURSES_CH_T ch
)
178 /* Make render_char() visible while still allowing us to inline it below. */
179 NCURSES_CH_T
_nc_render(WINDOW
*win
, NCURSES_CH_T ch
)
181 return render_char(win
, ch
);
185 * Implementations of most functions marked 'implemented' in include/curses.h:
188 // int baudrate(void) {}
191 /* TODO: Flash the screen if beeping fails? */
192 #if CONFIG(LP_SPEAKER)
193 speaker_tone(1760, 500); /* 1760 == note A6 */
197 // bool can_change_color(void) {}
198 int cbreak(void) { /* TODO */ return 0; }
199 /* D */ int clearok(WINDOW
*win
, bool flag
) { win
->_clear
= flag
; return OK
; }
200 // int color_content(short color, short *r, short *g, short *b) {}
203 #if CONFIG(LP_SERIAL_CONSOLE)
204 if (curses_flags
& F_ENABLE_SERIAL
) {
205 serial_cursor_enable(on
);
208 #if CONFIG(LP_VIDEO_CONSOLE)
209 if (curses_flags
& F_ENABLE_CONSOLE
) {
210 video_console_cursor_enable(on
);
216 // int def_prog_mode(void) {}
217 // int def_shell_mode(void) {}
218 // int delay_output(int) {}
219 // void delscreen(SCREEN *) {}
220 int delwin(WINDOW
*win
)
222 /* TODO: Don't try to delete stdscr. */
223 /* TODO: Don't delete parent windows before subwindows. */
225 // if (win->_flags & _SUBWIN)
226 // touchwin(win->_parent);
227 // else if (curscr != 0)
230 // return _nc_freewin(win);
233 WINDOW
*derwin(WINDOW
*orig
, int num_lines
, int num_columns
, int begy
, int begx
)
240 /* Make sure window fits inside the original one. */
241 if (begy
< 0 || begx
< 0 || orig
== 0 || num_lines
< 0
245 if (begy
+ num_lines
> orig
->_maxy
+ 1
246 || begx
+ num_columns
> orig
->_maxx
+ 1)
250 num_lines
= orig
->_maxy
+ 1 - begy
;
252 if (num_columns
== 0)
253 num_columns
= orig
->_maxx
+ 1 - begx
;
255 if (orig
->_flags
& _ISPAD
)
259 if ((win
= _nc_makenew(num_lines
, num_columns
, orig
->_begy
+ begy
,
260 orig
->_begx
+ begx
, flags
)) == 0)
265 WINDOW_ATTRS(win
) = WINDOW_ATTRS(orig
);
266 win
->_nc_bkgd
= orig
->_nc_bkgd
;
268 for (i
= 0; i
< num_lines
; i
++)
269 win
->_line
[i
].text
= &orig
->_line
[begy
++].text
[begx
];
278 int doupdate(void) { /* TODO */ return(0); }
279 // WINDOW * dupwin (WINDOW *) {}
280 /* D */ int echo(void) { SP
->_echo
= TRUE
; return OK
; }
287 #ifdef NCURSES_MOUSE_VERSION
290 // _nc_screen_wrap();
291 // _nc_mvcur_wrap(); /* wrap up cursor addressing */
292 // return reset_shell_mode();
295 // char erasechar (void) {}
296 // void filter (void) {}
297 // int flash(void) {}
298 int flushinp(void) { /* TODO */ return 0; }
299 // WINDOW *getwin (FILE *) {}
300 bool has_colors (void) { return(TRUE
); }
301 // bool has_ic (void) {}
302 // bool has_il (void) {}
303 // void idcok (WINDOW *, bool) {}
304 // int idlok (WINDOW *, bool) {}
305 void immedok(WINDOW
*win
, bool flag
) { win
->_immed
= flag
; }
306 /** Note: Must _not_ be called twice! */
307 WINDOW
*initscr(void)
311 // newterm(name, stdout, stdin);
314 for (i
= 0; i
< 128; i
++)
315 acs_map
[i
] = (chtype
) i
| A_ALTCHARSET
;
316 #if CONFIG(LP_SERIAL_CONSOLE)
317 if (curses_flags
& F_ENABLE_SERIAL
) {
321 #if CONFIG(LP_VIDEO_CONSOLE)
322 if (curses_flags
& F_ENABLE_CONSOLE
) {
323 /* Clear the screen and kill the cursor */
325 video_console_clear();
326 video_console_cursor_enable(0);
332 stdscr
= newwin(SCREEN_Y
, SCREEN_X
, 0, 0);
333 // TODO: curscr, newscr?
339 // int intrflush (WINDOW *,bool) {}
340 /* D */ bool isendwin(void) { return ((SP
== NULL
) ? FALSE
: SP
->_endwin
); }
341 // bool is_linetouched (WINDOW *,int) {}
342 // bool is_wintouched (WINDOW *) {}
343 // NCURSES_CONST char * keyname (int) {}
344 int keypad (WINDOW
*win
, bool flag
) { /* TODO */ return 0; }
345 // char killchar (void) {}
346 /* D */ int leaveok(WINDOW
*win
, bool flag
) { win
->_leaveok
= flag
; return OK
; }
347 // char *longname (void) {}
348 // int meta (WINDOW *,bool) {}
349 // int mvcur (int,int,int,int) {}
350 // int mvderwin (WINDOW *, int, int) {}
351 int mvprintw(int y
, int x
, const char *fmt
, ...)
356 if (move(y
, x
) == ERR
)
360 code
= vwprintw(stdscr
, fmt
, argp
);
365 // int mvscanw (int,int, NCURSES_CONST char *,...) {}
366 // int mvwin (WINDOW *,int,int) {}
367 int mvwprintw(WINDOW
*win
, int y
, int x
, const char *fmt
, ...)
372 if (wmove(win
, y
, x
) == ERR
)
376 code
= vwprintw(win
, fmt
, argp
);
381 // int mvwscanw (WINDOW *,int,int, NCURSES_CONST char *,...) {}
382 // int napms (int) {}
383 // WINDOW *newpad (int,int) {}
384 // SCREEN *newterm (NCURSES_CONST char *,FILE *,FILE *) {}
385 WINDOW
*newwin(int num_lines
, int num_columns
, int begy
, int begx
)
390 /* Use next statically allocated window. */
391 // TODO: Error handling. Yes. Please.
394 if (window_count
>= MAX_WINDOWS
)
397 win
= &window_list
[window_count
++];
399 // bool is_pad = (flags & _ISPAD);
405 win
->_maxy
= num_lines
- 1;
406 win
->_maxx
= num_columns
- 1;
409 // win->_yoffset = SP->_topstolen;
411 win
->_line
= ldat_list
[ldat_count
++];
413 /* FIXME: Is this right? Should the window attributes be normal? */
414 win
->_color
= PAIR_NUMBER(0);
415 win
->_attrs
= A_NORMAL
;
417 for (i
= 0; i
< num_lines
; i
++)
419 (NCURSES_CH_T
*)&linebuf_list
[linebuf_count
++];
423 /* D */ int nl(void) { SP
->_nl
= TRUE
; return OK
; }
424 /* D */ int noecho(void) { SP
->_echo
= FALSE
; return OK
; }
425 /* D */ int nonl(void) { SP
->_nl
= FALSE
; return OK
; }
426 // void noqiflush (void) {}
427 // int noraw (void) {}
428 /* D */ int notimeout (WINDOW
*win
, bool f
) { win
->_notimeout
= f
; return OK
; }
429 // int overlay (const WINDOW*,WINDOW *) {}
430 // int overwrite (const WINDOW*,WINDOW *) {}
431 // int pair_content (short,short*,short*) {}
432 // int pechochar (WINDOW *, const chtype) {}
433 // int pnoutrefresh (WINDOW*,int,int,int,int,int,int) {}
434 // int prefresh (WINDOW *,int,int,int,int,int,int) {}
435 int printw(const char *fmt
, ...)
441 code
= vwprintw(stdscr
, fmt
, argp
);
446 // int putwin (WINDOW *, FILE *) {}
447 // void qiflush (void) {}
449 // int resetty (void) {}
450 // int reset_prog_mode (void) {}
451 // int reset_shell_mode (void) {}
452 // int ripoffline (int, int (*)(WINDOW *, int)) {}
453 // int savetty (void) {}
454 // int scanw (NCURSES_CONST char *,...) {}
455 // int scr_dump (const char *) {}
456 // int scr_init (const char *) {}
457 /* D */ int scrollok(WINDOW
*win
, bool flag
) { win
->_scroll
= flag
; return OK
; }
458 // int scr_restore (const char *) {}
459 // int scr_set (const char *) {}
460 // SCREEN *set_term (SCREEN *) {}
461 // int slk_attroff (const chtype) {}
462 // int slk_attron (const chtype) {}
463 // int slk_attrset (const chtype) {}
464 // attr_t slk_attr (void) {}
465 // int slk_attr_set (const attr_t,short,void*) {}
466 // int slk_clear (void) {}
467 // int slk_color (short) {}
468 // int slk_init (int) {}
469 /* D */ char *slk_label(int n
)
472 // if (SP == NULL || SP->_slk == NULL || n < 1 || n > SP->_slk->labcnt)
474 return SP
->_slk
->ent
[n
- 1].ent_text
;
476 // int slk_noutrefresh (void) {}
477 // int slk_refresh (void) {}
478 // int slk_restore (void) {}
479 // int slk_set (int,const char *,int) {}
480 // int slk_touch (void) {}
482 // WINDOW *subpad (WINDOW *, int, int, int, int) {}
483 WINDOW
*subwin(WINDOW
*w
, int l
, int c
, int y
, int x
)
485 return derwin(w
, l
, c
, y
- w
->_begy
, x
- w
->_begx
);
487 // int syncok (WINDOW *, bool) {}
488 // chtype termattrs (void) {}
489 // char *termname (void) {}
490 // int typeahead (int) {}
491 int ungetch(int ch
) { /* TODO */ return ERR
; }
492 // void use_env (bool) {}
493 // int vidattr (chtype) {}
494 // int vidputs (chtype, int (*)(int)) {}
495 int vwprintw(WINDOW
*win
, const char *fmt
, va_list argp
)
497 vsprintf((char *)&sprintf_tmp
, fmt
, argp
);
499 /* TODO: Error handling? */
500 return waddstr(win
, (char *)&sprintf_tmp
);
502 // int vwscanw (WINDOW *, NCURSES_CONST char *,va_list) {}
503 int waddch(WINDOW
*win
, const chtype ch
)
507 // SetChar2(wch, ch);
509 if (win
->_line
[win
->_cury
].firstchar
== _NOCHANGE
||
510 win
->_line
[win
->_cury
].firstchar
> win
->_curx
)
511 win
->_line
[win
->_cury
].firstchar
= win
->_curx
;
513 win
->_line
[win
->_cury
].text
[win
->_curx
].chars
[0] =
514 ((ch
) & (chtype
)A_CHARTEXT
);
516 win
->_line
[win
->_cury
].text
[win
->_curx
].attr
= WINDOW_ATTRS(win
);
517 win
->_line
[win
->_cury
].text
[win
->_curx
].attr
|=
518 ((ch
) & (chtype
)A_ATTRIBUTES
);
520 if (win
->_line
[win
->_cury
].lastchar
== _NOCHANGE
||
521 win
->_line
[win
->_cury
].lastchar
< win
->_curx
)
522 win
->_line
[win
->_cury
].lastchar
= win
->_curx
;
524 win
->_curx
++; // FIXME
526 // if (win && (waddch_nosync(win, wch) != ERR)) {
527 // _nc_synchook(win);
533 // int waddchnstr (WINDOW *,const chtype *,int) {}
534 int waddnstr(WINDOW
*win
, const char *astr
, int n
)
537 const char *str
= astr
;
545 if (win
->_line
[win
->_cury
].firstchar
== _NOCHANGE
||
546 win
->_line
[win
->_cury
].firstchar
> win
->_curx
)
547 win
->_line
[win
->_cury
].firstchar
= win
->_curx
;
549 while ((n
-- > 0) && (*str
!= '\0')) {
550 // while (*str != '\0') {
551 win
->_line
[win
->_cury
].text
[win
->_curx
].chars
[0] = *str
++;
552 win
->_line
[win
->_cury
].text
[win
->_curx
].attr
= WINDOW_ATTRS(win
)
554 win
->_curx
++; // FIXME
557 // SetChar(ch, UChar(*str++), A_NORMAL);
558 // if (_nc_waddch_nosync(win, ch) == ERR) {
564 if (win
->_line
[win
->_cury
].lastchar
== _NOCHANGE
||
565 win
->_line
[win
->_cury
].lastchar
< win
->_curx
)
566 win
->_line
[win
->_cury
].lastchar
= win
->_curx
;
570 int wattr_on(WINDOW
*win
, attr_t at
, void *opts GCC_UNUSED
)
573 win
->_color
= PAIR_NUMBER(at
);
574 // toggle_attr_on(WINDOW_ATTRS(win), at);
577 int wattr_off(WINDOW
*win
, attr_t at
, void *opts GCC_UNUSED
)
581 // toggle_attr_off(WINDOW_ATTRS(win), at);
584 // int wbkgd (WINDOW *, chtype) {}
585 void wbkgdset(WINDOW
*win
, chtype ch
) { /* TODO */ }
587 int wborder(WINDOW
*win
, chtype ls
, chtype rs
, chtype ts
, chtype bs
,
588 chtype tl
, chtype tr
, chtype bl
, chtype br
)
592 if (ls
== 0) ls
= ACS_VLINE
;
593 if (rs
== 0) rs
= ACS_VLINE
;
594 if (ts
== 0) ts
= ACS_HLINE
;
595 if (bs
== 0) bs
= ACS_HLINE
;
596 if (tl
== 0) tl
= ACS_ULCORNER
;
597 if (tr
== 0) tr
= ACS_URCORNER
;
598 if (bl
== 0) bl
= ACS_LLCORNER
;
599 if (br
== 0) br
= ACS_LRCORNER
;
601 for(y
= 0; y
<= win
->_maxy
; y
++) {
604 mvwaddch(win
, y
, 0, tl
);
606 for(x
= 1; x
< win
->_maxx
; x
++)
607 mvwaddch(win
, y
, x
, ts
);
609 mvwaddch(win
, y
, win
->_maxx
, tr
);
611 else if (y
== win
->_maxy
) {
612 mvwaddch(win
, y
, 0, bl
);
614 for(x
= 1; x
< win
->_maxx
; x
++)
615 mvwaddch(win
, y
, x
, bs
);
617 mvwaddch(win
, y
, win
->_maxx
, br
);
620 mvwaddch(win
, y
, 0, ls
);
621 mvwaddch(win
, y
, win
->_maxx
, rs
);
628 // int wchgat (WINDOW *, int, attr_t, short, const void *) {}
629 /* D */ int wclear(WINDOW
*win
)
631 if (werase(win
) == ERR
)
636 // int wclrtobot (WINDOW *) {}
637 int wclrtoeol(WINDOW
*win
) { /* TODO */ return ERR
; }
638 int wcolor_set(WINDOW
*win
, short color_pair_number
, void *opts
)
640 if (!opts
&& (color_pair_number
>= 0)
641 && (color_pair_number
< COLOR_PAIRS
)) {
642 SET_WINDOW_PAIR(win
, color_pair_number
);
643 if_EXT_COLORS(win
->_color
= color_pair_number
);
648 // void wcursyncup (WINDOW *) {}
649 // int wdelch (WINDOW *) {}
650 // int wechochar (WINDOW *, const chtype) {}
651 int werase(WINDOW
*win
)
654 for (y
= 0; y
<= win
->_maxy
; y
++) {
655 for (x
= 0; x
<= win
->_maxx
; x
++) {
656 win
->_line
[y
].text
[x
].chars
[0] = ' ';
657 win
->_line
[y
].text
[x
].attr
= WINDOW_ATTRS(win
);
659 // Should we check instead?
660 win
->_line
[y
].firstchar
= 0;
661 win
->_line
[y
].lastchar
= win
->_maxx
;
665 // int wgetnstr (WINDOW *,char *,int) {}
666 int whline(WINDOW
*win
, chtype ch
, int n
)
668 NCURSES_SIZE_T start
, end
;
669 struct ldat
*line
= &(win
->_line
[win
->_cury
]);
674 if (end
> win
->_maxx
)
677 CHANGED_RANGE(line
, start
, end
);
681 //// SetChar2(wch, ACS_HLINE);
683 //// SetChar2(wch, ch);
685 wch
.chars
[0] = ((ch
) & (chtype
)A_CHARTEXT
);
686 wch
.attr
= ((ch
) & (chtype
)A_ATTRIBUTES
);
687 wch
= _nc_render(win
, wch
);
689 while (end
>= start
) {
690 line
->text
[end
] = wch
;
694 //// _nc_synchook(win);
698 /* D */ chtype
winch(WINDOW
*win
)
701 // return (CharOf(win->_line[win->_cury].text[win->_curx]) |
702 // AttrOf(win->_line[win->_cury].text[win->_curx]));
705 // int winchnstr (WINDOW *, chtype *, int) {}
706 // int winnstr (WINDOW *, char *, int) {}
707 // int winsch (WINDOW *, chtype) {}
708 // int winsdelln (WINDOW *,int) {}
709 // int winsnstr (WINDOW *, const char *,int) {}
710 /* D */ int wmove(WINDOW
*win
, int y
, int x
)
712 if (!LEGALYX(win
, y
, x
))
714 win
->_curx
= (NCURSES_SIZE_T
) x
;
715 win
->_cury
= (NCURSES_SIZE_T
) y
;
716 win
->_flags
&= ~_WRAPPED
;
717 win
->_flags
|= _HASMOVED
;
721 #define SWAP_RED_BLUE(c) \
722 (((c) & 0x4400) >> 2) | ((c) & 0xAA00) | (((c) & 0x1100) << 2)
723 int wnoutrefresh(WINDOW
*win
)
725 #if CONFIG(LP_SERIAL_CONSOLE)
727 int serial_is_bold
= 0;
728 int serial_is_reverse
= 0;
729 int serial_is_altcharset
= 0;
730 int serial_cur_pair
= 0;
738 #if CONFIG(LP_SERIAL_CONSOLE)
740 serial_end_altcharset();
743 for (y
= 0; y
<= win
->_maxy
; y
++) {
745 if (win
->_line
[y
].firstchar
== _NOCHANGE
)
748 /* Position the serial cursor */
750 #if CONFIG(LP_SERIAL_CONSOLE)
751 if (curses_flags
& F_ENABLE_SERIAL
)
752 serial_set_cursor(win
->_begy
+ y
, win
->_begx
+
753 win
->_line
[y
].firstchar
);
756 for (x
= win
->_line
[y
].firstchar
; x
<= win
->_line
[y
].lastchar
; x
++) {
757 attr_t attr
= win
->_line
[y
].text
[x
].attr
;
759 #if CONFIG(LP_SERIAL_CONSOLE)
760 if (curses_flags
& F_ENABLE_SERIAL
) {
761 ch
= win
->_line
[y
].text
[x
].chars
[0];
764 if (!serial_is_bold
) {
769 if (serial_is_bold
) {
772 /* work around serial.c
775 serial_is_reverse
= 0;
780 if (attr
& A_REVERSE
) {
781 if (!serial_is_reverse
) {
782 serial_start_reverse();
783 serial_is_reverse
= 1;
786 if (serial_is_reverse
) {
787 serial_end_reverse();
788 serial_is_reverse
= 0;
789 /* work around serial.c
798 if (attr
& A_ALTCHARSET
) {
799 if (serial_acs_map
[ch
& 0x7f]) {
800 ch
= serial_acs_map
[ch
& 0x7f];
803 ch
= fallback_acs_map
[ch
& 0x7f];
805 if (need_altcharset
&& !serial_is_altcharset
) {
806 serial_start_altcharset();
807 serial_is_altcharset
= 1;
809 if (!need_altcharset
&& serial_is_altcharset
) {
810 serial_end_altcharset();
811 serial_is_altcharset
= 0;
814 if (serial_cur_pair
!= PAIR_NUMBER(attr
)) {
815 pair_content(PAIR_NUMBER(attr
),
817 serial_set_color(fg
, bg
);
818 serial_cur_pair
= PAIR_NUMBER(attr
);
825 #if CONFIG(LP_VIDEO_CONSOLE)
827 ((int)color_pairs
[PAIR_NUMBER(attr
)]) << 8;
829 c
= SWAP_RED_BLUE(c
);
831 if (curses_flags
& F_ENABLE_CONSOLE
) {
832 ch
= win
->_line
[y
].text
[x
].chars
[0];
834 /* Handle some of the attributes. */
839 if (attr
& A_REVERSE
) {
840 unsigned char tmp
= (c
>> 8) & 0xf;
841 c
= (c
>> 4) & 0xf00;
844 if (attr
& A_ALTCHARSET
) {
845 if (console_acs_map
[ch
& 0x7f])
846 ch
= console_acs_map
[ch
& 0x7f];
848 ch
= fallback_acs_map
[ch
& 0x7f];
852 * FIXME: Somewhere along the line, the
853 * character value is getting sign-extented.
854 * For now grab just the 8 bit character,
855 * but this will break wide characters!
857 c
|= (chtype
) (ch
& 0xff);
858 video_console_putc(win
->_begy
+ y
, win
->_begx
+ x
, c
);
862 win
->_line
[y
].firstchar
= _NOCHANGE
;
863 win
->_line
[y
].lastchar
= _NOCHANGE
;
866 #if CONFIG(LP_SERIAL_CONSOLE)
867 if (curses_flags
& F_ENABLE_SERIAL
)
868 serial_set_cursor(win
->_begy
+ win
->_cury
, win
->_begx
+ win
->_curx
);
871 #if CONFIG(LP_VIDEO_CONSOLE)
872 if (curses_flags
& F_ENABLE_CONSOLE
)
873 video_console_set_cursor(win
->_begx
+ win
->_curx
, win
->_begy
+ win
->_cury
);
878 int wprintw(WINDOW
*win
, const char *fmt
, ...)
884 code
= vwprintw(win
, fmt
, argp
);
890 int wredrawln (WINDOW
*win
, int beg_line
, int num_lines
)
894 for (i
= beg_line
; i
< beg_line
+ num_lines
; i
++) {
895 win
->_line
[i
].firstchar
= 0;
896 win
->_line
[i
].lastchar
= win
->_maxx
;
902 int wrefresh(WINDOW
*win
)
905 return wnoutrefresh(win
);
911 curscr
->_clear
= TRUE
;
912 // code = doupdate();
913 } else if ((code
= wnoutrefresh(win
)) == OK
) {
915 newscr
->_clear
= TRUE
;
916 // code = doupdate();
918 * Reset the clearok() flag in case it was set for the special
919 * case in hardscroll.c (if we don't reset it here, we'll get 2
920 * refreshes because the flag is copied from stdscr to newscr).
921 * Resetting the flag shouldn't do any harm, anyway.
928 // int wscanw (WINDOW *, NCURSES_CONST char *,...) {}
929 int wscrl(WINDOW
*win
, int n
)
939 for (y
= 0; y
<= (win
->_maxy
- n
); y
++) {
940 win
->_line
[y
].firstchar
= win
->_line
[y
+ n
].firstchar
;
941 win
->_line
[y
].lastchar
= win
->_line
[y
+ n
].lastchar
;
942 for (x
= 0; x
<= win
->_maxx
; x
++) {
943 if ((win
->_line
[y
].text
[x
].chars
[0] != win
->_line
[y
+ n
].text
[x
].chars
[0]) ||
944 (win
->_line
[y
].text
[x
].attr
!= win
->_line
[y
+ n
].text
[x
].attr
)) {
945 if (win
->_line
[y
].firstchar
== _NOCHANGE
)
946 win
->_line
[y
].firstchar
= x
;
948 win
->_line
[y
].lastchar
= x
;
950 win
->_line
[y
].text
[x
].chars
[0] = win
->_line
[y
+ n
].text
[x
].chars
[0];
951 win
->_line
[y
].text
[x
].attr
= win
->_line
[y
+ n
].text
[x
].attr
;
956 for (y
= (win
->_maxy
+1 - n
); y
<= win
->_maxy
; y
++) {
957 for (x
= 0; x
<= win
->_maxx
; x
++) {
958 if ((win
->_line
[y
].text
[x
].chars
[0] != ' ') ||
959 (win
->_line
[y
].text
[x
].attr
!= A_NORMAL
)) {
960 if (win
->_line
[y
].firstchar
== _NOCHANGE
)
961 win
->_line
[y
].firstchar
= x
;
963 win
->_line
[y
].lastchar
= x
;
965 win
->_line
[y
].text
[x
].chars
[0] = ' ';
966 win
->_line
[y
].text
[x
].attr
= A_NORMAL
;
971 // _nc_scroll_window(win, n, win->_regtop, win->_regbottom, win->_nc_bkgd);
972 // _nc_synchook(win);
976 int wsetscrreg(WINDOW
*win
, int top
, int bottom
)
978 if (top
>= 0 && top
<= win
->_maxy
&& bottom
>= 0 &&
979 bottom
<= win
->_maxy
&& bottom
> top
) {
980 win
->_regtop
= (NCURSES_SIZE_T
) top
;
981 win
->_regbottom
= (NCURSES_SIZE_T
) bottom
;
986 // void wsyncdown (WINDOW *) {}
987 // void wsyncup (WINDOW *) {}
988 /* D */ void wtimeout(WINDOW
*win
, int _delay
) { win
->_delay
= _delay
; }
989 /* D */ int wtouchln(WINDOW
*win
, int y
, int n
, int changed
)
993 // if ((n < 0) || (y < 0) || (y > win->_maxy))
996 for (i
= y
; i
< y
+ n
; i
++) {
999 win
->_line
[i
].firstchar
= changed
? 0 : _NOCHANGE
;
1000 win
->_line
[i
].lastchar
= changed
? win
->_maxx
: _NOCHANGE
;
1004 // int wvline (WINDOW *,chtype,int) {}
1005 // int tigetflag (NCURSES_CONST char *) {}
1006 // int tigetnum (NCURSES_CONST char *) {}
1007 // char *tigetstr (NCURSES_CONST char *) {}
1008 // int putp (const char *) {}
1009 // #if NCURSES_TPARM_VARARGS
1010 // char *tparm (NCURSES_CONST char *, ...) {}
1012 // char *tparm (NCURSES_CONST char *, long,long,long,long,long,long,long,long,long) {}
1013 // char *tparm_varargs (NCURSES_CONST char *, ...) {}