7 * MuCurses core functions
11 FILE_LICENCE ( GPL2_OR_LATER
);
13 static void _wupdcurs ( WINDOW
*win
) __nonnull
;
14 void _wputch ( WINDOW
*win
, chtype ch
, int wrap
) __nonnull
;
15 void _wputc ( WINDOW
*win
, char c
, int wrap
) __nonnull
;
16 void _wcursback ( WINDOW
*win
) __nonnull
;
17 void _wputchstr ( WINDOW
*win
, const chtype
*chstr
, int wrap
, int n
) __nonnull
;
18 void _wputstr ( WINDOW
*win
, const char *str
, int wrap
, int n
) __nonnull
;
19 int wmove ( WINDOW
*win
, int y
, int x
) __nonnull
;
35 * Update cursor position
37 * @v *win window in which to update position
39 static void _wupdcurs ( WINDOW
*win
) {
40 win
->scr
->movetoyx ( win
->scr
, win
->ori_y
+ win
->curs_y
,
41 win
->ori_x
+ win
->curs_x
);
45 * Write a single character rendition to a window
47 * @v *win window in which to write
48 * @v ch character rendition to write
49 * @v wrap wrap "switch"
51 void _wputch ( WINDOW
*win
, chtype ch
, int wrap
) {
52 /* make sure we set the screen cursor to the right position
55 win
->scr
->putc(win
->scr
, ch
);
56 if ( ++(win
->curs_x
) - win
->width
== 0 ) {
59 /* specification says we should really scroll,
60 but we have no buffer to scroll with, so we
61 can only overwrite back at the beginning of
63 if ( ++(win
->curs_y
) - win
->height
== 0 )
72 * Write a single character to a window
74 * @v *win window in which to write
75 * @v c character rendition to write
76 * @v wrap wrap "switch"
78 void _wputc ( WINDOW
*win
, char c
, int wrap
) {
79 _wputch ( win
, ( c
| win
->attrs
), wrap
);
83 * Retreat the cursor back one position (useful for a whole host of
86 * @v *win window in which to retreat
88 void _wcursback ( WINDOW
*win
) {
89 if ( win
->curs_x
== 0 ) {
90 if ( win
->curs_y
== 0 )
91 win
->curs_y
= win
->height
- 1;
92 win
->curs_x
= win
->width
= 1;
101 * Write a chtype string to a window
103 * @v *win window in which to write
104 * @v *chstr chtype string
105 * @v wrap wrap "switch"
106 * @v n write at most n chtypes
108 void _wputchstr ( WINDOW
*win
, const chtype
*chstr
, int wrap
, int n
) {
109 for ( ; *chstr
&& n
-- ; chstr
++ ) {
110 _wputch(win
,*chstr
,wrap
);
115 * Write a standard c-style string to a window
117 * @v *win window in which to write
119 * @v wrap wrap "switch"
120 * @v n write at most n chars from *str
122 void _wputstr ( WINDOW
*win
, const char *str
, int wrap
, int n
) {
123 for ( ; *str
&& n
-- ; str
++ ) {
124 _wputc ( win
, *str
, wrap
);
129 * Move a window's cursor to the specified position
131 * @v *win window to be operated on
134 * @ret rc return status code
136 int wmove ( WINDOW
*win
, int y
, int x
) {
137 /* chech for out-of-bounds errors */
138 if ( ( (unsigned)y
>= win
->height
) ||
139 ( (unsigned)x
>= win
->width
) ) {