mucurses.c
Go to the documentation of this file.00001 #include <console.h>
00002 #include <curses.h>
00003 #include "mucurses.h"
00004
00005
00006
00007
00008
00009
00010
00011 FILE_LICENCE ( GPL2_OR_LATER );
00012
00013 static void _wupdcurs ( WINDOW *win ) __nonnull;
00014 void _wputch ( WINDOW *win, chtype ch, int wrap ) __nonnull;
00015 void _wputc ( WINDOW *win, char c, int wrap ) __nonnull;
00016 void _wcursback ( WINDOW *win ) __nonnull;
00017 void _wputchstr ( WINDOW *win, const chtype *chstr, int wrap, int n ) __nonnull;
00018 void _wputstr ( WINDOW *win, const char *str, int wrap, int n ) __nonnull;
00019 int wmove ( WINDOW *win, int y, int x ) __nonnull;
00020
00021 WINDOW _stdscr = {
00022 .attrs = A_DEFAULT,
00023 .ori_y = 0,
00024 .ori_x = 0,
00025 .curs_y = 0,
00026 .curs_x = 0,
00027 .scr = &_ansi_screen,
00028 };
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 static void _wupdcurs ( WINDOW *win ) {
00040 win->scr->movetoyx ( win->scr, win->ori_y + win->curs_y,
00041 win->ori_x + win->curs_x );
00042 }
00043
00044
00045
00046
00047
00048
00049
00050
00051 void _wputch ( WINDOW *win, chtype ch, int wrap ) {
00052
00053
00054 _wupdcurs(win);
00055 win->scr->putc(win->scr, ch);
00056 if ( ++(win->curs_x) - win->width == 0 ) {
00057 if ( wrap == WRAP ) {
00058 win->curs_x = 0;
00059
00060
00061
00062
00063 if ( ++(win->curs_y) - win->height == 0 )
00064 win->curs_y = 0;
00065 } else {
00066 (win->curs_x)--;
00067 }
00068 }
00069 }
00070
00071
00072
00073
00074
00075
00076
00077
00078 void _wputc ( WINDOW *win, char c, int wrap ) {
00079 _wputch ( win, ( c | win->attrs ), wrap );
00080 }
00081
00082
00083
00084
00085
00086
00087
00088 void _wcursback ( WINDOW *win ) {
00089 if ( win->curs_x == 0 ) {
00090 if ( win->curs_y == 0 )
00091 win->curs_y = win->height - 1;
00092 win->curs_x = win->width = 1;
00093 } else {
00094 win->curs_x--;
00095 }
00096
00097 _wupdcurs(win);
00098 }
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 void _wputchstr ( WINDOW *win, const chtype *chstr, int wrap, int n ) {
00109 for ( ; *chstr && n-- ; chstr++ ) {
00110 _wputch(win,*chstr,wrap);
00111 }
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 void _wputstr ( WINDOW *win, const char *str, int wrap, int n ) {
00123 for ( ; *str && n-- ; str++ ) {
00124 _wputc ( win, *str, wrap );
00125 }
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 int wmove ( WINDOW *win, int y, int x ) {
00137
00138 if ( ( (unsigned)y >= win->height ) ||
00139 ( (unsigned)x >= win->width ) ) {
00140 return ERR;
00141 }
00142
00143 win->curs_y = y;
00144 win->curs_x = x;
00145 _wupdcurs(win);
00146 return OK;
00147 }