You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

curses.h 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. #ifndef CURSES_H
  2. #define CURSES_H
  3. #include <stdint.h>
  4. #include <stdbool.h>
  5. #include <stdarg.h>
  6. #include <ipxe/console.h>
  7. /** @file
  8. *
  9. * MuCurses header file
  10. *
  11. */
  12. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  13. #undef ERR
  14. #define ERR (-1)
  15. #undef FALSE
  16. #define FALSE (0)
  17. #undef OK
  18. #define OK (0)
  19. #undef TRUE
  20. #define TRUE (1)
  21. typedef uint32_t chtype;
  22. typedef uint32_t attr_t;
  23. /** Curses SCREEN object */
  24. typedef struct _curses_screen {
  25. /** Current cursor position */
  26. unsigned int curs_x, curs_y;
  27. /** Current attribute */
  28. attr_t attrs;
  29. void ( *init ) ( struct _curses_screen *scr );
  30. void ( *exit ) ( struct _curses_screen *scr );
  31. /**
  32. * Erase screen
  33. *
  34. * @v scr screen on which to operate
  35. * @v attrs attributes
  36. */
  37. void ( * erase ) ( struct _curses_screen *scr, attr_t attrs );
  38. /**
  39. * Move cursor to position specified by x,y coords
  40. *
  41. * @v scr screen on which to operate
  42. * @v y Y position
  43. * @v x X position
  44. */
  45. void ( * movetoyx ) ( struct _curses_screen *scr,
  46. unsigned int y, unsigned int x );
  47. /**
  48. * Write character to current cursor position
  49. *
  50. * @v scr screen on which to operate
  51. * @v c character to be written
  52. */
  53. void ( * putc ) ( struct _curses_screen *scr, chtype c );
  54. /**
  55. * Pop a character from the keyboard input stream
  56. *
  57. * @v scr screen on which to operate
  58. * @ret c popped character
  59. */
  60. int ( * getc ) ( struct _curses_screen *scr );
  61. /**
  62. * Checks to see whether a character is waiting in the input stream
  63. *
  64. * @v scr screen on which to operate
  65. * @ret TRUE character waiting in stream
  66. * @ret FALSE no character waiting in stream
  67. */
  68. bool ( *peek ) ( struct _curses_screen *scr );
  69. /**
  70. * Set cursor visibility
  71. *
  72. * @v scr screen on which to operate
  73. * @v visibility cursor visibility
  74. */
  75. void ( * cursor ) ( struct _curses_screen *scr, int visibility );
  76. } SCREEN;
  77. /** Curses Window struct */
  78. typedef struct _curses_window {
  79. /** screen with which window associates */
  80. SCREEN *scr;
  81. /** window attributes */
  82. attr_t attrs;
  83. /** window origin coordinates */
  84. unsigned int ori_x, ori_y;
  85. /** window cursor position */
  86. unsigned int curs_x, curs_y;
  87. /** window dimensions */
  88. unsigned int width, height;
  89. /** parent window */
  90. struct _curses_window *parent;
  91. /** windows that share the same parent as this one */
  92. //struct list_head siblings;
  93. /** windows der'd or sub'd from this one */
  94. //struct list_head children;
  95. } WINDOW;
  96. extern WINDOW _stdscr;
  97. #define stdscr ( &_stdscr )
  98. #define COLS console_width
  99. #define LINES console_height
  100. #define MUCURSES_BITS( mask, shift ) (( mask ) << (shift))
  101. #define CPAIR_SHIFT 8
  102. #define ATTRS_SHIFT 16
  103. #define WA_DEFAULT ( 0x0000 << ATTRS_SHIFT )
  104. #define WA_ALTCHARSET ( 0x0001 << ATTRS_SHIFT )
  105. #define WA_BLINK ( 0x0002 << ATTRS_SHIFT )
  106. #define WA_BOLD ( 0x0004 << ATTRS_SHIFT )
  107. #define WA_DIM ( 0x0008 << ATTRS_SHIFT )
  108. #define WA_INVIS ( 0x0010 << ATTRS_SHIFT )
  109. #define WA_PROTECT ( 0x0020 << ATTRS_SHIFT )
  110. #define WA_REVERSE ( 0x0040 << ATTRS_SHIFT )
  111. #define WA_STANDOUT ( 0x0080 << ATTRS_SHIFT )
  112. #define WA_UNDERLINE ( 0x0100 << ATTRS_SHIFT )
  113. #define WA_HORIZONTAL ( 0x0200 << ATTRS_SHIFT )
  114. #define WA_VERTICAL ( 0x0400 << ATTRS_SHIFT )
  115. #define WA_LEFT ( 0x0800 << ATTRS_SHIFT )
  116. #define WA_RIGHT ( 0x1000 << ATTRS_SHIFT )
  117. #define WA_LOW ( 0x2000 << ATTRS_SHIFT )
  118. #define WA_TOP ( 0x4000 << ATTRS_SHIFT )
  119. #define A_DEFAULT WA_DEFAULT
  120. #define A_ALTCHARSET WA_ALTCHARSET
  121. #define A_BLINK WA_BLINK
  122. #define A_BOLD WA_BOLD
  123. #define A_DIM WA_DIM
  124. #define A_INVIS WA_INVIS
  125. #define A_PROTECT WA_PROTECT
  126. #define A_REVERSE WA_REVERSE
  127. #define A_STANDOUT WA_STANDOUT
  128. #define A_UNDERLINE WA_UNDERLINE
  129. #define A_ATTRIBUTES ( 0xffff << ATTRS_SHIFT )
  130. #define A_CHARTEXT ( 0xff )
  131. #define A_COLOUR ( 0xff << CPAIR_SHIFT )
  132. #define A_COLOR A_COLOUR
  133. #define COLOUR_PAIR(n) ( (n) << CPAIR_SHIFT )
  134. #define COLOR_PAIR(n) COLOUR_PAIR(n)
  135. #define PAIR_NUMBER(attrs) ( ( (attrs) & A_COLOUR ) >> CPAIR_SHIFT )
  136. #define COLOUR_PAIRS 8 /* Arbitrary limit */
  137. #define COLOR_PAIRS COLOUR_PAIRS
  138. #define ACS_ULCORNER '+'
  139. #define ACS_LLCORNER '+'
  140. #define ACS_URCORNER '+'
  141. #define ACS_LRCORNER '+'
  142. #define ACS_RTEE '+'
  143. #define ACS_LTEE '+'
  144. #define ACS_BTEE '+'
  145. #define ACS_TTEE '+'
  146. #define ACS_HLINE '-'
  147. #define ACS_VLINE '|'
  148. #define ACS_PLUS '+'
  149. #define ACS_S1 '-'
  150. #define ACS_S9 '_'
  151. #define ACS_DIAMOND '+'
  152. #define ACS_CKBOARD ':'
  153. #define ACS_DEGREE '\''
  154. #define ACS_PLMINUS '#'
  155. #define ACS_BULLET 'o'
  156. #define ACS_LARROW '<'
  157. #define ACS_RARROW '>'
  158. #define ACS_DARROW 'v'
  159. #define ACS_UARROW '^'
  160. #define ACS_BOARD '#'
  161. #define ACS_LANTERN '#'
  162. #define ACS_BLOCK '#'
  163. #define COLOUR_BLACK 0
  164. #define COLOUR_RED 1
  165. #define COLOUR_GREEN 2
  166. #define COLOUR_YELLOW 3
  167. #define COLOUR_BLUE 4
  168. #define COLOUR_MAGENTA 5
  169. #define COLOUR_CYAN 6
  170. #define COLOUR_WHITE 7
  171. #define COLOURS 7
  172. #define COLOUR_FG 30
  173. #define COLOUR_BG 40
  174. #define COLOR_FG COLOUR_FG
  175. #define COLOR_BG COLOUR_BG
  176. #define COLOR_BLACK COLOUR_BLACK
  177. #define COLOR_BLUE COLOUR_BLUE
  178. #define COLOR_GREEN COLOUR_GREEN
  179. #define COLOR_CYAN COLOUR_CYAN
  180. #define COLOR_RED COLOUR_RED
  181. #define COLOR_MAGENTA COLOUR_MAGENTA
  182. #define COLOR_YELLOW COLOUR_YELLOW
  183. #define COLOR_WHITE COLOUR_WHITE
  184. #define COLORS COLOURS
  185. /*
  186. * KEY code constants are define in ipxe/keys.h
  187. */
  188. #include <ipxe/keys.h>
  189. //extern int addch ( const chtype * );
  190. //extern int addchnstr ( const chtype *, int );
  191. //extern int addchstr ( const chtype * );
  192. //extern int addnstr ( const char *, int );
  193. //extern int addstr ( const char * );
  194. //extern int attroff ( int );
  195. //extern int attron ( int );
  196. //extern int attrset ( int );
  197. //extern int attr_get ( attr_t *, short *, void * );
  198. //extern int attr_off ( attr_t, void * );
  199. //extern int attr_on ( attr_t, void * );
  200. //extern int attr_set ( attr_t, short, void * );
  201. extern int baudrate ( void );
  202. extern int beep ( void );
  203. //extern void bkgdset ( chtype );
  204. /*extern int border ( chtype, chtype, chtype, chtype, chtype, chtype, chtype,
  205. chtype );*/
  206. extern int box ( WINDOW *, chtype, chtype ) __nonnull;
  207. //extern bool can_change_colour ( void );
  208. #define can_change_color() can_change_colour()
  209. extern int cbreak ( void );
  210. //extern int clrtobot ( void );
  211. //extern int clrtoeol ( void );
  212. extern int colour_content ( short, short *, short *, short * ) __nonnull;
  213. #define color_content( c, r, g, b ) colour_content( (c), (r), (g), (b) )
  214. //extern int colour_set ( short, void * );
  215. #define color_set( cpno, opts ) colour_set( (cpno), (opts) )
  216. extern int copywin ( const WINDOW *, WINDOW *, int, int, int,
  217. int, int, int, int );
  218. extern int curs_set ( int );
  219. extern int def_prog_mode ( void );
  220. extern int def_shell_mode ( void );
  221. extern int delay_output ( int );
  222. //extern int delch ( void );
  223. //extern int deleteln ( void );
  224. extern void delscreen ( SCREEN * );
  225. extern int delwin ( WINDOW * ) __nonnull;
  226. extern WINDOW *derwin ( WINDOW *, int, int, int, int ) __nonnull;
  227. //extern int doupdate ( void );
  228. extern WINDOW *dupwin ( WINDOW * ) __nonnull;
  229. extern int echo ( void );
  230. extern int echochar ( const chtype );
  231. extern int endwin ( void );
  232. extern char erasechar ( void );
  233. extern int erase ( void );
  234. extern void filter ( void );
  235. extern int flash ( void );
  236. extern int flushinp ( void );
  237. extern __pure chtype getbkgd ( WINDOW * ) __nonnull;
  238. //extern int getch ( void );
  239. //extern int getnstr ( char *, int );
  240. //extern int getstr ( char * );
  241. extern int halfdelay ( int );
  242. //extern bool has_colors ( void );
  243. extern bool has_ic ( void );
  244. extern bool has_il ( void );
  245. //extern int hline ( chtype, int );
  246. extern void idcok ( WINDOW *, bool );
  247. extern int idlok ( WINDOW *, bool );
  248. //extern void immedok ( WINDOW *, bool );
  249. //extern chtype inch ( void );
  250. //extern int inchnstr ( chtype *, int );
  251. //extern int inchstr ( chtype * );
  252. extern WINDOW *initscr ( void );
  253. extern int init_colour ( short, short, short, short );
  254. #define init_color ( c, r, g, b ) init_colour ( (c), (r), (g), (b) )
  255. extern int init_pair ( short, short, short );
  256. //extern int innstr ( char *, int );
  257. //extern int insch ( chtype );
  258. //extern int insnstr ( const char *, int );
  259. //extern int insstr ( const char * );
  260. //extern int instr ( char * );
  261. extern int intrflush ( WINDOW *, bool );
  262. extern bool isendwin ( void );
  263. //extern bool is_linetouched ( WINDOW *, int );
  264. //extern bool is_wintouched ( WINDOW * );
  265. extern char *keyname ( int );
  266. extern int keypad ( WINDOW *, bool );
  267. extern char killchar ( void );
  268. extern int leaveok ( WINDOW *, bool );
  269. extern char *longname ( void );
  270. extern int meta ( WINDOW *, bool );
  271. //extern int move ( int, int );
  272. //extern int mvaddch ( int, int, const chtype );
  273. //extern int mvaddchnstr ( int, int, const chtype *, int );
  274. //extern int mvaddchstr ( int, int, const chtype * );
  275. //extern int mvaddnstr ( int, int, const char *, int );
  276. //extern int mvaddstr ( int, int, const char * );
  277. extern int mvcur ( int, int, int, int );
  278. //extern int mvdelch ( int, int );
  279. extern int mvderwin ( WINDOW *, int, int );
  280. //extern int mvgetch ( int, int );
  281. //extern int mvgetnstr ( int, int, char *, int );
  282. //extern int mvgetstr ( int, int, char * );
  283. //extern int mvhline ( int, int, chtype, int );
  284. //extern chtype mvinch ( int, int );
  285. //extern int mvinchnstr ( int, int, chtype *, int );
  286. //extern int mvinchstr ( int, int, chtype * );
  287. //extern int mvinnstr ( int, int, char *, int );
  288. //extern int mvinsch ( int, int, chtype );
  289. //extern int mvinsnstr ( int, int, const char *, int );
  290. //extern int mvinsstr ( int, int, const char * );
  291. //extern int mvinstr ( int, int, char * );
  292. //extern int mvprintw ( int, int, char *, ... );
  293. //extern int mvscanw ( int, int, char *, ... );
  294. //extern int mvvline ( int, int, chtype, int );
  295. //extern int mvwaddch ( WINDOW *, int, int, const chtype );
  296. //extern int mvwaddchnstr ( WINDOW *, int, int, const chtype *, int );
  297. //extern int mvwaddchstr ( WINDOW *, int, int, const chtype * );
  298. //extern int mvwaddnstr ( WINDOW *, int, int, const char *, int );
  299. //extern int mvwaddstr ( WINDOW *, int, int, const char * );
  300. //extern int mvwdelch ( WINDOW *, int, int );
  301. //extern int mvwgetch ( WINDOW *, int, int );
  302. //extern int mvwgetnstr ( WINDOW *, int, int, char *, int );
  303. //extern int mvwgetstr ( WINDOW *, int, int, char * );
  304. //extern int mvwhline ( WINDOW *, int, int, chtype, int );
  305. extern int mvwin ( WINDOW *, int, int ) __nonnull;
  306. //extern chtype mvwinch ( WINDOW *, int, int );
  307. //extern int mvwinchnstr ( WINDOW *, int, int, chtype *, int );
  308. //extern int mvwinchstr ( WINDOW *, int, int, chtype * );
  309. //extern int mvwinnstr ( WINDOW *, int, int, char *, int );
  310. //extern int mvwinsch ( WINDOW *, int, int, chtype );
  311. //extern int mvwinsnstr ( WINDOW *, int, int, const char *, int );
  312. //extern int mvwinsstr ( WINDOW *, int, int, const char * );
  313. //extern int mvwinstr ( WINDOW *, int, int, char * );
  314. //extern int mvwprintw ( WINDOW *, int, int, char *, ... );
  315. //extern int mvwscanw ( WINDOW *, int, int, char *, ... );
  316. //extern int mvwvline ( WINDOW *, int, int, chtype, int );
  317. extern int napms ( int );
  318. //extern WINDOW *newpad ( int, int );
  319. extern WINDOW *newwin ( int, int, int, int );
  320. extern int nl ( void );
  321. extern int nocbreak ( void );
  322. extern int nodelay ( WINDOW *, bool );
  323. extern int noecho ( void );
  324. extern int nonl ( void );
  325. extern void noqiflush ( void );
  326. extern int noraw ( void );
  327. extern int notimeout ( WINDOW *, bool );
  328. extern int overlay ( const WINDOW *, WINDOW * );
  329. extern int overwrite ( const WINDOW *, WINDOW * );
  330. extern int pair_content ( short, short *, short * ) __nonnull;
  331. //extern int pechochar ( WINDOW *, chtype );
  332. //extern int pnoutrefresh ( WINDOW *, int, int, int, int, int, int );
  333. //extern int prefresh ( WINDOW *, int, int, int, int, int, int );
  334. extern int printw ( char *, ... );
  335. extern int putp ( const char * );
  336. extern void qiflush ( void );
  337. extern int raw ( void );
  338. //extern int redrawwin ( WINDOW * );
  339. //extern int refresh ( void );
  340. extern int reset_prog_mode ( void );
  341. extern int reset_shell_mode ( void );
  342. extern int resetty ( void );
  343. extern int ripoffline ( int, int (*) ( WINDOW *, int) );
  344. extern int savetty ( void );
  345. //extern int scanw ( char *, ... );
  346. //extern int scrl ( int );
  347. //extern int scroll ( WINDOW * );
  348. //extern int scrollok ( WINDOW *, bool );
  349. //extern int setscrreg ( int, int );
  350. extern SCREEN *set_term ( SCREEN * );
  351. extern int setupterm ( char *, int, int * );
  352. extern int slk_attr_off ( const attr_t, void * );
  353. extern int slk_attroff ( const chtype );
  354. extern int slk_attr_on ( const attr_t, void * );
  355. extern int slk_attron ( const chtype );
  356. extern int slk_attr_set ( const attr_t, short, void * );
  357. extern int slk_attrset ( const chtype );
  358. extern int slk_clear ( void );
  359. extern int slk_colour ( short );
  360. #define slk_color( c ) slk_colour( (c) )
  361. extern int slk_init ( int );
  362. extern char *slk_label ( int );
  363. extern int slk_noutrefresh ( void );
  364. //extern int slk_refresh ( void );
  365. extern int slk_restore ( void );
  366. extern int slk_set ( int, const char *, int ) __nonnull;
  367. extern int slk_touch ( void );
  368. extern int standend ( void );
  369. extern int standout ( void );
  370. //extern int start_colour ( void );
  371. #define start_color() start_colour()
  372. //extern WINDOW *subpad ( WINDOW *, int, int, int, int );
  373. extern WINDOW *subwin ( WINDOW *, int, int, int, int ) __nonnull;
  374. extern int syncok ( WINDOW *, bool );
  375. extern chtype termattrs ( void );
  376. extern attr_t term_attrs ( void );
  377. extern char *termname ( void );
  378. extern int tigetflag ( char * );
  379. extern int tigetnum ( char * );
  380. extern char *tigetstr ( char * );
  381. extern void timeout ( int );
  382. //extern int touchline ( WINDOW *, int, int );
  383. //extern int touchwin ( WINDOW * );
  384. extern char *tparm ( char *, long, long, long, long, long, long, long, long,
  385. long );
  386. extern int typeahead ( int );
  387. //extern int ungetch ( int );
  388. //extern int untouchwin ( WINDOW * );
  389. extern void use_env ( bool );
  390. extern int vid_attr ( attr_t, short, void * );
  391. extern int vidattr ( chtype );
  392. extern int vid_puts ( attr_t, short, void *, int ( *) ( int) );
  393. extern int vidputs ( chtype, int ( *) ( int) );
  394. //extern int vline ( chtype, int );
  395. //extern int vwprintw ( WINDOW *, const char *, va_list );
  396. extern int vw_printw ( WINDOW *, const char *, va_list ) __nonnull;
  397. //extern int vwscanw ( WINDOW *, char *, va_list );
  398. //extern int vw_scanw ( WINDOW *, char *, va_list );
  399. extern int waddch ( WINDOW *, const chtype ) __nonnull;
  400. extern int waddchnstr ( WINDOW *, const chtype *, int ) __nonnull;
  401. //extern int waddchstr ( WINDOW *, const chtype * );
  402. extern int waddnstr ( WINDOW *, const char *, int ) __nonnull;
  403. //extern int waddstr ( WINDOW *, const char * );
  404. extern int wattroff ( WINDOW *, int ) __nonnull;
  405. extern int wattron ( WINDOW *, int ) __nonnull;
  406. extern int wattrset ( WINDOW *, int ) __nonnull;
  407. extern int wattr_get ( WINDOW *, attr_t *, short *, void * )
  408. __attribute__ (( nonnull (1, 2, 3)));
  409. extern int wattr_off ( WINDOW *, attr_t, void * )
  410. __attribute__ (( nonnull (1)));
  411. extern int wattr_on ( WINDOW *, attr_t, void * )
  412. __attribute__ (( nonnull (1)));
  413. extern int wattr_set ( WINDOW *, attr_t, short, void * )
  414. __attribute__ (( nonnull (1)));
  415. //extern void wbkgdset ( WINDOW *, chtype );
  416. extern int wborder ( WINDOW *, chtype, chtype, chtype, chtype, chtype, chtype,
  417. chtype, chtype ) __nonnull;
  418. extern int wclrtobot ( WINDOW * ) __nonnull;
  419. extern int wclrtoeol ( WINDOW * ) __nonnull;
  420. extern void wcursyncup ( WINDOW * );
  421. extern int wcolour_set ( WINDOW *, short, void * )
  422. __attribute__ (( nonnull (1)));
  423. #define wcolor_set(w,s,v) wcolour_set((w),(s),(v))
  424. extern int wdelch ( WINDOW * ) __nonnull;
  425. extern int wdeleteln ( WINDOW * ) __nonnull;
  426. extern int wechochar ( WINDOW *, const chtype );
  427. extern int werase ( WINDOW * ) __nonnull;
  428. extern int wgetch ( WINDOW * );
  429. extern int wgetnstr ( WINDOW *, char *, int );
  430. //extern int wgetstr ( WINDOW *, char * );
  431. extern int whline ( WINDOW *, chtype, int ) __nonnull;
  432. //extern chtype winch ( WINDOW * );
  433. //extern int winchnstr ( WINDOW *, chtype *, int );
  434. //extern int winchstr ( WINDOW *, chtype * );
  435. //extern int winnstr ( WINDOW *, char *, int );
  436. //extern int winsch ( WINDOW *, chtype );
  437. //extern int winsnstr ( WINDOW *, const char *, int );
  438. //extern int winsstr ( WINDOW *, const char * );
  439. //extern int winstr ( WINDOW *, char * );
  440. extern int wmove ( WINDOW *, int, int );
  441. //extern int wnoutrefresh ( WINDOW * );
  442. extern int wprintw ( WINDOW *, const char *, ... ) __nonnull;
  443. //extern int wredrawln ( WINDOW *, int, int );
  444. //extern int wrefresh ( WINDOW * );
  445. //extern int wscanw ( WINDOW *, char *, ... );
  446. //extern int wscrl ( WINDOW *, int );
  447. //extern int wsetscrreg ( WINDOW *, int, int );
  448. //extern int wstandend ( WINDOW * );
  449. //extern int wstandout ( WINDOW * );
  450. extern void wsyncup ( WINDOW * );
  451. extern void wsyncdown ( WINDOW * );
  452. extern void wtimeout ( WINDOW *, int );
  453. //extern int wtouchln ( WINDOW *, int, int, int );
  454. extern int wvline ( WINDOW *, chtype, int ) __nonnull;
  455. /*
  456. * There is frankly a ridiculous amount of redundancy within the
  457. * curses API - ncurses decided to get around this by using #define
  458. * macros, but I've decided to be type-safe and implement them all as
  459. * static inlines instead...
  460. */
  461. static inline int addch ( const chtype ch ) {
  462. return waddch( stdscr, ch );
  463. }
  464. static inline int addchnstr ( const chtype *chstr, int n ) {
  465. return waddchnstr ( stdscr, chstr, n );
  466. }
  467. static inline int addchstr ( const chtype *chstr ) {
  468. return waddchnstr ( stdscr, chstr, -1 );
  469. }
  470. static inline int addnstr ( const char *str, int n ) {
  471. return waddnstr ( stdscr, str, n );
  472. }
  473. static inline int addstr ( const char *str ) {
  474. return waddnstr ( stdscr, str, -1 );
  475. }
  476. static inline int attroff ( int attrs ) {
  477. return wattroff ( stdscr, attrs );
  478. }
  479. static inline int attron ( int attrs ) {
  480. return wattron ( stdscr, attrs );
  481. }
  482. static inline int attrset ( int attrs ) {
  483. return wattrset ( stdscr, attrs );
  484. }
  485. static inline int attr_get ( attr_t *attrs, short *pair, void *opts ) {
  486. return wattr_get ( stdscr, attrs, pair, opts );
  487. }
  488. static inline int attr_off ( attr_t attrs, void *opts ) {
  489. return wattr_off ( stdscr, attrs, opts );
  490. }
  491. static inline int attr_on ( attr_t attrs, void *opts ) {
  492. return wattr_on ( stdscr, attrs, opts );
  493. }
  494. static inline int attr_set ( attr_t attrs, short cpair, void *opts ) {
  495. return wattr_set ( stdscr, attrs, cpair, opts );
  496. }
  497. static inline void bkgdset ( chtype ch ) {
  498. wattrset ( stdscr, ch );
  499. }
  500. static inline int border ( chtype ls, chtype rs, chtype ts, chtype bs,
  501. chtype tl, chtype tr, chtype bl, chtype br ) {
  502. return wborder ( stdscr, ls, rs, ts, bs, tl, tr, bl, br );
  503. }
  504. static inline bool can_change_colour ( void ) {
  505. return FALSE;
  506. }
  507. static inline int clrtobot ( void ) {
  508. return wclrtobot( stdscr );
  509. }
  510. static inline int clrtoeol ( void ) {
  511. return wclrtoeol( stdscr );
  512. }
  513. static inline int colour_set ( short colour_pair_number, void *opts ) {
  514. return wcolour_set ( stdscr, colour_pair_number, opts );
  515. }
  516. static inline int delch ( void ) {
  517. return wdelch ( stdscr );
  518. }
  519. static inline int deleteln ( void ) {
  520. return wdeleteln( stdscr );
  521. }
  522. static inline int getch ( void ) {
  523. return wgetch ( stdscr );
  524. }
  525. static inline int getnstr ( char *str, int n ) {
  526. return wgetnstr ( stdscr, str, n );
  527. }
  528. static inline int getstr ( char *str ) {
  529. return wgetnstr ( stdscr, str, -1 );
  530. }
  531. static inline bool has_colors ( void ) {
  532. return TRUE;
  533. }
  534. static inline int has_key ( int kc __unused ) {
  535. return TRUE;
  536. }
  537. static inline int hline ( chtype ch, int n ) {
  538. return whline ( stdscr, ch, n );
  539. }
  540. static inline int move ( int y, int x ) {
  541. return wmove ( stdscr, y, x );
  542. }
  543. static inline int mvaddch ( int y, int x, const chtype ch ) {
  544. return ( wmove ( stdscr, y, x ) == OK
  545. ? waddch( stdscr, ch ) : ERR );
  546. }
  547. static inline int mvaddchnstr ( int y, int x, const chtype *chstr, int n ) {
  548. return ( wmove ( stdscr, y, x ) == OK
  549. ? waddchnstr ( stdscr, chstr, n ) : ERR );
  550. }
  551. static inline int mvaddchstr ( int y, int x, const chtype *chstr ) {
  552. return ( wmove ( stdscr, y, x ) == OK
  553. ? waddchnstr ( stdscr, chstr, -1 ) : ERR );
  554. }
  555. static inline int mvaddnstr ( int y, int x, const char *str, int n ) {
  556. return ( wmove ( stdscr, y, x ) == OK
  557. ? waddnstr ( stdscr, str, n ) : ERR );
  558. }
  559. static inline int mvaddstr ( int y, int x, const char *str ) {
  560. return ( wmove ( stdscr, y, x ) == OK
  561. ? waddnstr ( stdscr, str, -1 ) : ERR );
  562. }
  563. static inline int mvdelch ( int y, int x ) {
  564. return ( wmove ( stdscr, y, x ) == OK
  565. ? wdelch ( stdscr ) : ERR );
  566. }
  567. static inline int mvgetch ( int y, int x ) {
  568. return ( wmove ( stdscr, y, x ) == OK
  569. ? wgetch ( stdscr ) : ERR );
  570. }
  571. static inline int mvgetnstr ( int y, int x, char *str, int n ) {
  572. return ( wmove ( stdscr, y, x ) == OK
  573. ? wgetnstr ( stdscr, str, n ) : ERR );
  574. }
  575. static inline int mvgetstr ( int y, int x, char *str ) {
  576. return ( wmove ( stdscr, y, x ) == OK
  577. ? wgetnstr ( stdscr, str, -1 ) : ERR );
  578. }
  579. static inline int mvhline ( int y, int x, chtype ch, int n ) {
  580. return ( wmove ( stdscr, y, x ) == OK
  581. ? whline ( stdscr, ch, n ) : ERR );
  582. }
  583. // OK, so maybe a few I did with macros...
  584. #define mvprintw( y, x, fmt, ... ) \
  585. ( wmove(stdscr,(y),(x)) == OK \
  586. ? wprintw( stdscr,(fmt), ## __VA_ARGS__ ) : ERR )
  587. static inline int mvvline ( int y, int x, chtype ch, int n ) {
  588. return ( wmove ( stdscr, y, x ) == OK
  589. ? wvline ( stdscr, ch, n ) : ERR );
  590. }
  591. static inline int mvwaddch ( WINDOW *win, int y, int x, const chtype ch ) {
  592. return ( wmove( win, y, x ) == OK
  593. ? waddch ( win, ch ) : ERR );
  594. }
  595. static inline int mvwaddchnstr ( WINDOW *win, int y, int x, const chtype *chstr, int n ) {
  596. return ( wmove ( win, y, x ) == OK
  597. ? waddchnstr ( win, chstr, n ) : ERR );
  598. }
  599. static inline int mvwaddchstr ( WINDOW *win, int y, int x, const chtype *chstr ) {
  600. return ( wmove ( win, y, x ) == OK
  601. ? waddchnstr ( win, chstr, -1 ) : ERR );
  602. }
  603. static inline int mvwaddnstr ( WINDOW *win, int y, int x, const char *str, int n ) {
  604. return ( wmove ( win, y, x ) == OK
  605. ? waddnstr ( win, str, n ) : ERR );
  606. }
  607. static inline int mvwaddstr ( WINDOW *win, int y, int x, const char *str ) {
  608. return ( wmove ( win, y, x ) == OK
  609. ? waddnstr ( win, str, -1 ) : ERR );
  610. }
  611. static inline int mvwdelch ( WINDOW *win, int y, int x ) {
  612. return ( wmove ( win, y, x ) == OK
  613. ? wdelch ( win ) : ERR );
  614. }
  615. static inline int mvwgetch ( WINDOW *win, int y, int x ) {
  616. return ( wmove ( win, y, x ) == OK
  617. ? wgetch ( win ) : ERR );
  618. }
  619. static inline int mvwgetnstr ( WINDOW *win, int y, int x, char *str, int n ) {
  620. return ( wmove ( win, y, x ) == OK
  621. ? wgetnstr ( win, str, n ) : ERR );
  622. }
  623. static inline int mvwgetstr ( WINDOW *win, int y, int x, char *str ) {
  624. return ( wmove ( win, y, x ) == OK
  625. ? wgetnstr ( win, str, -1 ) : ERR );
  626. }
  627. static inline int mvwhline ( WINDOW *win, int y, int x, chtype ch, int n ) {
  628. return ( wmove ( win, y, x ) == OK
  629. ? whline ( win, ch, n ) : ERR );
  630. }
  631. #define mvwprintw( win, y, x, fmt, ... ) \
  632. ( wmove((win),(y),(x)) == OK \
  633. ? wprintw((win),(fmt), ## __VA_ARGS__) : ERR )
  634. static inline int mvwvline ( WINDOW *win, int y, int x, chtype ch, int n ) {
  635. return ( wmove ( win, y, x ) == OK
  636. ? wvline ( win, ch, n ) : ERR );
  637. }
  638. #define printw( fmt, ... ) wprintw(stdscr,(fmt), ## __VA_ARGS__ )
  639. static inline int slk_refresh ( void ) {
  640. if ( slk_clear() == OK )
  641. return slk_restore();
  642. else
  643. return ERR;
  644. }
  645. #define standend() wstandend( stdscr )
  646. #define standout() wstandout( stdscr )
  647. static inline int start_colour ( void ) {
  648. return OK;
  649. }
  650. static inline int vline ( chtype ch, int n ) {
  651. return wvline ( stdscr, ch, n );
  652. }
  653. // marked for removal
  654. static inline int vwprintw ( WINDOW *win, const char *fmt, va_list varglist ) {
  655. return vw_printw ( win, fmt, varglist );
  656. }
  657. static inline int waddchstr ( WINDOW *win, const chtype *chstr ) {
  658. return waddchnstr ( win, chstr, -1 );
  659. }
  660. static inline int waddstr ( WINDOW *win, const char *str ) {
  661. return waddnstr ( win, str, -1 );
  662. }
  663. static inline int wbkgdset ( WINDOW *win, chtype ch ) {
  664. return wattrset( win, ch );
  665. }
  666. static inline int wgetstr ( WINDOW *win, char *str ) {
  667. return wgetnstr ( win, str, -1 );
  668. }
  669. static inline int wstandend ( WINDOW *win ) {
  670. return wattrset ( win, A_DEFAULT );
  671. }
  672. static inline int wstandout ( WINDOW *win ) {
  673. return wattrset ( win, A_STANDOUT );
  674. }
  675. #endif /* CURSES_H */