6 * MuCurses core functions
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
12 static void _wupdcurs ( WINDOW *win ) __nonnull;
13 void _wputch ( WINDOW *win, chtype ch, int wrap ) __nonnull;
14 void _wputc ( WINDOW *win, char c, int wrap ) __nonnull;
15 void _wcursback ( WINDOW *win ) __nonnull;
16 void _wputchstr ( WINDOW *win, const chtype *chstr, int wrap, int n ) __nonnull;
17 void _wputstr ( WINDOW *win, const char *str, int wrap, int n ) __nonnull;
18 int wmove ( WINDOW *win, int y, int x ) __nonnull;
34 * Update cursor position
36 * @v *win window in which to update position
38 static void _wupdcurs ( WINDOW *win ) {
39 win->scr->movetoyx ( win->scr, win->ori_y + win->curs_y,
40 win->ori_x + win->curs_x );
44 * Write a single character rendition to a window
46 * @v *win window in which to write
47 * @v ch character rendition to write
48 * @v wrap wrap "switch"
50 void _wputch ( WINDOW *win, chtype ch, int wrap ) {
51 /* make sure we set the screen cursor to the right position
54 win->scr->putc(win->scr, ch);
55 if ( ++(win->curs_x) - win->width == 0 ) {
58 /* specification says we should really scroll,
59 but we have no buffer to scroll with, so we
60 can only overwrite back at the beginning of
62 if ( ++(win->curs_y) - win->height == 0 )
71 * Write a single character to a window
73 * @v *win window in which to write
74 * @v c character rendition to write
75 * @v wrap wrap "switch"
77 void _wputc ( WINDOW *win, char c, int wrap ) {
78 _wputch ( win, ( ( ( unsigned char ) c ) | win->attrs ), wrap );
82 * Retreat the cursor back one position (useful for a whole host of
85 * @v *win window in which to retreat
87 void _wcursback ( WINDOW *win ) {
88 if ( win->curs_x == 0 ) {
89 if ( win->curs_y == 0 )
90 win->curs_y = win->height - 1;
91 win->curs_x = win->width = 1;
100 * Write a chtype string to a window
102 * @v *win window in which to write
103 * @v *chstr chtype string
104 * @v wrap wrap "switch"
105 * @v n write at most n chtypes
107 void _wputchstr ( WINDOW *win, const chtype *chstr, int wrap, int n ) {
108 for ( ; *chstr && n-- ; chstr++ ) {
109 _wputch(win,*chstr,wrap);
114 * Write a standard c-style string to a window
116 * @v *win window in which to write
118 * @v wrap wrap "switch"
119 * @v n write at most n chars from *str
121 void _wputstr ( WINDOW *win, const char *str, int wrap, int n ) {
122 for ( ; *str && n-- ; str++ ) {
123 _wputc ( win, *str, wrap );
128 * Move a window's cursor to the specified position
130 * @v *win window to be operated on
133 * @ret rc return status code
135 int wmove ( WINDOW *win, int y, int x ) {
136 /* chech for out-of-bounds errors */
137 if ( ( (unsigned)y >= win->height ) ||
138 ( (unsigned)x >= win->width ) ) {
149 * Set cursor visibility
151 * @v visibility cursor visibility
153 int curs_set ( int visibility ) {
154 stdscr->scr->cursor ( stdscr->scr, visibility );