curses.h 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. #ifndef CURSES_H
  2. #define CURSES_H
  3. #include <stdint.h>
  4. #include <stdarg.h>
  5. /** @file
  6. *
  7. * MuCurses header file
  8. *
  9. */
  10. #undef ERR
  11. #define ERR (-1)
  12. #undef FALSE
  13. #define FALSE (0)
  14. #undef OK
  15. #define OK (0)
  16. #undef TRUE
  17. #define TRUE (1)
  18. typedef int bool;
  19. typedef uint32_t chtype;
  20. typedef uint32_t attr_t;
  21. /** Curses SCREEN object */
  22. typedef struct _curses_screen {
  23. /** Current cursor position */
  24. unsigned int curs_x, curs_y;
  25. /** Current attribute */
  26. attr_t attrs;
  27. void ( *init ) ( struct _curses_screen *scr );
  28. void ( *exit ) ( struct _curses_screen *scr );
  29. /**
  30. * Move cursor to position specified by x,y coords
  31. *
  32. * @v scr screen on which to operate
  33. * @v y Y position
  34. * @v x X position
  35. */
  36. void ( * movetoyx ) ( struct _curses_screen *scr,
  37. unsigned int y, unsigned int x );
  38. /**
  39. * Write character to current cursor position
  40. *
  41. * @v scr screen on which to operate
  42. * @v c character to be written
  43. */
  44. void ( * putc ) ( struct _curses_screen *scr, chtype c );
  45. /**
  46. * Pop a character from the keyboard input stream
  47. *
  48. * @v scr screen on which to operate
  49. * @ret c popped character
  50. */
  51. int ( * getc ) ( struct _curses_screen *scr );
  52. /**
  53. * Checks to see whether a character is waiting in the input stream
  54. *
  55. * @v scr screen on which to operate
  56. * @ret TRUE character waiting in stream
  57. * @ret FALSE no character waiting in stream
  58. */
  59. bool ( *peek ) ( struct _curses_screen *scr );
  60. } SCREEN;
  61. /** Curses Window struct */
  62. typedef struct _curses_window {
  63. /** screen with which window associates */
  64. SCREEN *scr;
  65. /** window attributes */
  66. attr_t attrs;
  67. /** window origin coordinates */
  68. unsigned int ori_x, ori_y;
  69. /** window cursor position */
  70. unsigned int curs_x, curs_y;
  71. /** window dimensions */
  72. unsigned int width, height;
  73. /** parent window */
  74. struct _curses_window *parent;
  75. /** windows that share the same parent as this one */
  76. //struct list_head siblings;
  77. /** windows der'd or sub'd from this one */
  78. //struct list_head children;
  79. } WINDOW;
  80. extern WINDOW _stdscr;
  81. extern unsigned short _COLS;
  82. extern unsigned short _LINES;
  83. #define stdscr ( &_stdscr )
  84. #define COLS _COLS
  85. #define LINES _LINES
  86. #define MUCURSES_BITS( mask, shift ) (( mask ) << (shift))
  87. #define CPAIR_SHIFT 8
  88. #define ATTRS_SHIFT 16
  89. #define WA_DEFAULT ( 0x0000 << ATTRS_SHIFT )
  90. #define WA_ALTCHARSET ( 0x0001 << ATTRS_SHIFT )
  91. #define WA_BLINK ( 0x0002 << ATTRS_SHIFT )
  92. #define WA_BOLD ( 0x0004 << ATTRS_SHIFT )
  93. #define WA_DIM ( 0x0008 << ATTRS_SHIFT )
  94. #define WA_INVIS ( 0x0010 << ATTRS_SHIFT )
  95. #define WA_PROTECT ( 0x0020 << ATTRS_SHIFT )
  96. #define WA_REVERSE ( 0x0040 << ATTRS_SHIFT )
  97. #define WA_STANDOUT ( 0x0080 << ATTRS_SHIFT )
  98. #define WA_UNDERLINE ( 0x0100 << ATTRS_SHIFT )
  99. #define WA_HORIZONTAL ( 0x0200 << ATTRS_SHIFT )
  100. #define WA_VERTICAL ( 0x0400 << ATTRS_SHIFT )
  101. #define WA_LEFT ( 0x0800 << ATTRS_SHIFT )
  102. #define WA_RIGHT ( 0x1000 << ATTRS_SHIFT )
  103. #define WA_LOW ( 0x2000 << ATTRS_SHIFT )
  104. #define WA_TOP ( 0x4000 << ATTRS_SHIFT )
  105. #define A_DEFAULT WA_DEFAULT
  106. #define A_ALTCHARSET WA_ALTCHARSET
  107. #define A_BLINK WA_BLINK
  108. #define A_BOLD WA_BOLD
  109. #define A_DIM WA_DIM
  110. #define A_INVIS WA_INVIS
  111. #define A_PROTECT WA_PROTECT
  112. #define A_REVERSE WA_REVERSE
  113. #define A_STANDOUT WA_STANDOUT
  114. #define A_UNDERLINE WA_UNDERLINE
  115. #define A_ATTRIBUTES ( 0xffff << ATTRS_SHIFT )
  116. #define A_CHARTEXT ( 0xff )
  117. #define A_COLOUR ( 0xff << CPAIR_SHIFT )
  118. #define A_COLOR A_COLOUR
  119. #define COLOUR_PAIR(n) ( (n) << CPAIR_SHIFT )
  120. #define COLOR_PAIR(n) COLOUR_PAIR(n)
  121. #define PAIR_NUMBER(attrs) ( ( (attrs) & A_COLOUR ) >> CPAIR_SHIFT )
  122. #define COLOUR_PAIRS 8 /* Arbitrary limit */
  123. #define COLOR_PAIRS COLOUR_PAIRS
  124. #define ACS_ULCORNER '+'
  125. #define ACS_LLCORNER '+'
  126. #define ACS_URCORNER '+'
  127. #define ACS_LRCORNER '+'
  128. #define ACS_RTEE '+'
  129. #define ACS_LTEE '+'
  130. #define ACS_BTEE '+'
  131. #define ACS_TTEE '+'
  132. #define ACS_HLINE '-'
  133. #define ACS_VLINE '|'
  134. #define ACS_PLUS '+'
  135. #define ACS_S1 '-'
  136. #define ACS_S9 '_'
  137. #define ACS_DIAMOND '+'
  138. #define ACS_CKBOARD ':'
  139. #define ACS_DEGREE '\''
  140. #define ACS_PLMINUS '#'
  141. #define ACS_BULLET 'o'
  142. #define ACS_LARROW '<'
  143. #define ACS_RARROW '>'
  144. #define ACS_DARROW 'v'
  145. #define ACS_UARROW '^'
  146. #define ACS_BOARD '#'
  147. #define ACS_LANTERN '#'
  148. #define ACS_BLOCK '#'
  149. #define COLOUR_BLACK 0
  150. #define COLOUR_RED 1
  151. #define COLOUR_GREEN 2
  152. #define COLOUR_YELLOW 3
  153. #define COLOUR_BLUE 4
  154. #define COLOUR_MAGENTA 5
  155. #define COLOUR_CYAN 6
  156. #define COLOUR_WHITE 7
  157. #define COLOURS 7
  158. #define COLOUR_FG 30
  159. #define COLOUR_BG 40
  160. #define COLOR_FG COLOUR_FG
  161. #define COLOR_BG COLOUR_BG
  162. #define COLOR_BLACK COLOUR_BLACK
  163. #define COLOR_BLUE COLOUR_BLUE
  164. #define COLOR_GREEN COLOUR_GREEN
  165. #define COLOR_CYAN COLOUR_CYAN
  166. #define COLOR_RED COLOUR_RED
  167. #define COLOR_MAGENTA COLOUR_MAGENTA
  168. #define COLOR_YELLOW COLOUR_YELLOW
  169. #define COLOR_WHITE COLOUR_WHITE
  170. #define COLORS COLOURS
  171. /*
  172. * KEY code constants
  173. */
  174. #define KEY_BREAK 0401 /**< Break key */
  175. #define KEY_DOWN 0402 /**< down-arrow key */
  176. #define KEY_UP 0403 /**< up-arrow key */
  177. #define KEY_LEFT 0404 /**< left-arrow key */
  178. #define KEY_RIGHT 0405 /**< right-arrow key */
  179. #define KEY_HOME 0406 /**< home key */
  180. #define KEY_BACKSPACE 0407 /**< backspace key */
  181. #define KEY_F0 0410 /**< Function keys. Space for 64 */
  182. #define KEY_F(n) (KEY_F0+(n)) /**< Value of function key n */
  183. #define KEY_DL 0510 /**< delete-line key */
  184. #define KEY_IL 0511 /**< insert-line key */
  185. #define KEY_DC 0512 /**< delete-character key */
  186. #define KEY_IC 0513 /**< insert-character key */
  187. #define KEY_EIC 0514 /**< sent by rmir or smir in insert mode */
  188. #define KEY_CLEAR 0515 /**< clear-screen or erase key */
  189. #define KEY_EOS 0516 /**< clear-to-end-of-screen key */
  190. #define KEY_EOL 0517 /**< clear-to-end-of-line key */
  191. #define KEY_SF 0520 /**< scroll-forward key */
  192. #define KEY_SR 0521 /**< scroll-backward key */
  193. #define KEY_NPAGE 0522 /**< next-page key */
  194. #define KEY_PPAGE 0523 /**< previous-page key */
  195. #define KEY_STAB 0524 /**< set-tab key */
  196. #define KEY_CTAB 0525 /**< clear-tab key */
  197. #define KEY_CATAB 0526 /**< clear-all-tabs key */
  198. #define KEY_ENTER 0527 /**< enter/send key */
  199. #define KEY_PRINT 0532 /**< print key */
  200. #define KEY_LL 0533 /**< lower-left key (home down) */
  201. #define KEY_A1 0534 /**< upper left of keypad */
  202. #define KEY_A3 0535 /**< upper right of keypad */
  203. #define KEY_B2 0536 /**< center of keypad */
  204. #define KEY_C1 0537 /**< lower left of keypad */
  205. #define KEY_C3 0540 /**< lower right of keypad */
  206. #define KEY_BTAB 0541 /**< back-tab key */
  207. #define KEY_BEG 0542 /**< begin key */
  208. #define KEY_CANCEL 0543 /**< cancel key */
  209. #define KEY_CLOSE 0544 /**< close key */
  210. #define KEY_COMMAND 0545 /**< command key */
  211. #define KEY_COPY 0546 /**< copy key */
  212. #define KEY_CREATE 0547 /**< create key */
  213. #define KEY_END 0550 /**< end key */
  214. #define KEY_EXIT 0551 /**< exit key */
  215. #define KEY_FIND 0552 /**< find key */
  216. #define KEY_HELP 0553 /**< help key */
  217. #define KEY_MARK 0554 /**< mark key */
  218. #define KEY_MESSAGE 0555 /**< message key */
  219. #define KEY_MOVE 0556 /**< move key */
  220. #define KEY_NEXT 0557 /**< next key */
  221. #define KEY_OPEN 0560 /**< open key */
  222. #define KEY_OPTIONS 0561 /**< options key */
  223. #define KEY_PREVIOUS 0562 /**< previous key */
  224. #define KEY_REDO 0563 /**< redo key */
  225. #define KEY_REFERENCE 0564 /**< reference key */
  226. #define KEY_REFRESH 0565 /**< refresh key */
  227. #define KEY_REPLACE 0566 /**< replace key */
  228. #define KEY_RESTART 0567 /**< restart key */
  229. #define KEY_RESUME 0570 /**< resume key */
  230. #define KEY_SAVE 0571 /**< save key */
  231. #define KEY_SBEG 0572 /**< shifted begin key */
  232. #define KEY_SCANCEL 0573 /**< shifted cancel key */
  233. #define KEY_SCOMMAND 0574 /**< shifted command key */
  234. #define KEY_SCOPY 0575 /**< shifted copy key */
  235. #define KEY_SCREATE 0576 /**< shifted create key */
  236. #define KEY_SDC 0577 /**< shifted delete-character key */
  237. #define KEY_SDL 0600 /**< shifted delete-line key */
  238. #define KEY_SELECT 0601 /**< select key */
  239. #define KEY_SEND 0602 /**< shifted end key */
  240. #define KEY_SEOL 0603 /**< shifted clear-to-end-of-line key */
  241. #define KEY_SEXIT 0604 /**< shifted exit key */
  242. #define KEY_SFIND 0605 /**< shifted find key */
  243. #define KEY_SHELP 0606 /**< shifted help key */
  244. #define KEY_SHOME 0607 /**< shifted home key */
  245. #define KEY_SIC 0610 /**< shifted insert-character key */
  246. #define KEY_SLEFT 0611 /**< shifted left-arrow key */
  247. #define KEY_SMESSAGE 0612 /**< shifted message key */
  248. #define KEY_SMOVE 0613 /**< shifted move key */
  249. #define KEY_SNEXT 0614 /**< shifted next key */
  250. #define KEY_SOPTIONS 0615 /**< shifted options key */
  251. #define KEY_SPREVIOUS 0616 /**< shifted previous key */
  252. #define KEY_SPRINT 0617 /**< shifted print key */
  253. #define KEY_SREDO 0620 /**< shifted redo key */
  254. #define KEY_SREPLACE 0621 /**< shifted replace key */
  255. #define KEY_SRIGHT 0622 /**< shifted right-arrow key */
  256. #define KEY_SRSUME 0623 /**< shifted resume key */
  257. #define KEY_SSAVE 0624 /**< shifted save key */
  258. #define KEY_SSUSPEND 0625 /**< shifted suspend key */
  259. #define KEY_SUNDO 0626 /**< shifted undo key */
  260. #define KEY_SUSPEND 0627 /**< suspend key */
  261. #define KEY_UNDO 0630 /**< undo key */
  262. #define KEY_RESIZE 0632 /**< Terminal resize event */
  263. #define KEY_EVENT 0633 /**< We were interrupted by an event */
  264. #define KEY_MAX 0777 /* Maximum key value is 0633 */
  265. //extern int addch ( const chtype * );
  266. //extern int addchnstr ( const chtype *, int );
  267. //extern int addchstr ( const chtype * );
  268. //extern int addnstr ( const char *, int );
  269. //extern int addstr ( const char * );
  270. //extern int attroff ( int );
  271. //extern int attron ( int );
  272. //extern int attrset ( int );
  273. extern int attr_get ( attr_t *, short *, void * );
  274. extern int attr_off ( attr_t, void * );
  275. extern int attr_on ( attr_t, void * );
  276. extern int attr_set ( attr_t, short, void * );
  277. extern int baudrate ( void );
  278. extern int beep ( void );
  279. //extern void bkgdset ( chtype );
  280. /*extern int border ( chtype, chtype, chtype, chtype, chtype, chtype, chtype,
  281. chtype );*/
  282. extern int box ( WINDOW *, chtype, chtype );
  283. //extern bool can_change_colour ( void );
  284. #define can_change_color() can_change_colour()
  285. extern int cbreak ( void );
  286. //extern int clrtobot ( void );
  287. //extern int clrtoeol ( void );
  288. extern int colour_content ( short, short *, short *, short * );
  289. #define color_content( c, r, g, b ) colour_content( (c), (r), (g), (b) )
  290. //extern int colour_set ( short, void * );
  291. #define color_set( cpno, opts ) colour_set( (cpno), (opts) )
  292. extern int copywin ( const WINDOW *, WINDOW *, int, int, int,
  293. int, int, int, int );
  294. extern int curs_set ( int );
  295. extern int def_prog_mode ( void );
  296. extern int def_shell_mode ( void );
  297. extern int delay_output ( int );
  298. //extern int delch ( void );
  299. //extern int deleteln ( void );
  300. extern void delscreen ( SCREEN * );
  301. extern int delwin ( WINDOW * );
  302. extern WINDOW *derwin ( WINDOW *, int, int, int, int );
  303. //extern int doupdate ( void );
  304. extern WINDOW *dupwin ( WINDOW * );
  305. extern int echo ( void );
  306. extern int echochar ( const chtype );
  307. extern int endwin ( void );
  308. extern char erasechar ( void );
  309. //extern int erase ( void );
  310. extern void filter ( void );
  311. extern int flash ( void );
  312. extern int flushinp ( void );
  313. extern chtype getbkgd ( WINDOW * );
  314. //extern int getch ( void );
  315. //extern int getnstr ( char *, int );
  316. //extern int getstr ( char * );
  317. extern int halfdelay ( int );
  318. //extern bool has_colors ( void );
  319. extern bool has_ic ( void );
  320. extern bool has_il ( void );
  321. //extern int hline ( chtype, int );
  322. extern void idcok ( WINDOW *, bool );
  323. extern int idlok ( WINDOW *, bool );
  324. //extern void immedok ( WINDOW *, bool );
  325. //extern chtype inch ( void );
  326. //extern int inchnstr ( chtype *, int );
  327. //extern int inchstr ( chtype * );
  328. extern WINDOW *initscr ( void );
  329. extern int init_colour ( short, short, short, short );
  330. #define init_color ( c, r, g, b ) init_colour ( (c), (r), (g), (b) )
  331. extern int init_pair ( short, short, short );
  332. //extern int innstr ( char *, int );
  333. //extern int insch ( chtype );
  334. //extern int insnstr ( const char *, int );
  335. //extern int insstr ( const char * );
  336. //extern int instr ( char * );
  337. extern int intrflush ( WINDOW *, bool );
  338. extern bool isendwin ( void );
  339. //extern bool is_linetouched ( WINDOW *, int );
  340. //extern bool is_wintouched ( WINDOW * );
  341. extern char *keyname ( int );
  342. extern int keypad ( WINDOW *, bool );
  343. extern char killchar ( void );
  344. extern int leaveok ( WINDOW *, bool );
  345. extern char *longname ( void );
  346. extern int meta ( WINDOW *, bool );
  347. //extern int move ( int, int );
  348. //extern int mvaddch ( int, int, const chtype );
  349. //extern int mvaddchnstr ( int, int, const chtype *, int );
  350. //extern int mvaddchstr ( int, int, const chtype * );
  351. //extern int mvaddnstr ( int, int, const char *, int );
  352. //extern int mvaddstr ( int, int, const char * );
  353. extern int mvcur ( int, int, int, int );
  354. //extern int mvdelch ( int, int );
  355. extern int mvderwin ( WINDOW *, int, int );
  356. //extern int mvgetch ( int, int );
  357. //extern int mvgetnstr ( int, int, char *, int );
  358. //extern int mvgetstr ( int, int, char * );
  359. //extern int mvhline ( int, int, chtype, int );
  360. //extern chtype mvinch ( int, int );
  361. //extern int mvinchnstr ( int, int, chtype *, int );
  362. //extern int mvinchstr ( int, int, chtype * );
  363. //extern int mvinnstr ( int, int, char *, int );
  364. //extern int mvinsch ( int, int, chtype );
  365. //extern int mvinsnstr ( int, int, const char *, int );
  366. //extern int mvinsstr ( int, int, const char * );
  367. //extern int mvinstr ( int, int, char * );
  368. //extern int mvprintw ( int, int, char *, ... );
  369. //extern int mvscanw ( int, int, char *, ... );
  370. //extern int mvvline ( int, int, chtype, int );
  371. //extern int mvwaddch ( WINDOW *, int, int, const chtype );
  372. //extern int mvwaddchnstr ( WINDOW *, int, int, const chtype *, int );
  373. //extern int mvwaddchstr ( WINDOW *, int, int, const chtype * );
  374. //extern int mvwaddnstr ( WINDOW *, int, int, const char *, int );
  375. //extern int mvwaddstr ( WINDOW *, int, int, const char * );
  376. //extern int mvwdelch ( WINDOW *, int, int );
  377. //extern int mvwgetch ( WINDOW *, int, int );
  378. //extern int mvwgetnstr ( WINDOW *, int, int, char *, int );
  379. //extern int mvwgetstr ( WINDOW *, int, int, char * );
  380. //extern int mvwhline ( WINDOW *, int, int, chtype, int );
  381. extern int mvwin ( WINDOW *, int, int );
  382. //extern chtype mvwinch ( WINDOW *, int, int );
  383. //extern int mvwinchnstr ( WINDOW *, int, int, chtype *, int );
  384. //extern int mvwinchstr ( WINDOW *, int, int, chtype * );
  385. //extern int mvwinnstr ( WINDOW *, int, int, char *, int );
  386. //extern int mvwinsch ( WINDOW *, int, int, chtype );
  387. //extern int mvwinsnstr ( WINDOW *, int, int, const char *, int );
  388. //extern int mvwinsstr ( WINDOW *, int, int, const char * );
  389. //extern int mvwinstr ( WINDOW *, int, int, char * );
  390. //extern int mvwprintw ( WINDOW *, int, int, char *, ... );
  391. //extern int mvwscanw ( WINDOW *, int, int, char *, ... );
  392. //extern int mvwvline ( WINDOW *, int, int, chtype, int );
  393. extern int napms ( int );
  394. //extern WINDOW *newpad ( int, int );
  395. extern WINDOW *newwin ( int, int, int, int );
  396. extern int nl ( void );
  397. extern int nocbreak ( void );
  398. extern int nodelay ( WINDOW *, bool );
  399. extern int noecho ( void );
  400. extern int nonl ( void );
  401. extern void noqiflush ( void );
  402. extern int noraw ( void );
  403. extern int notimeout ( WINDOW *, bool );
  404. extern int overlay ( const WINDOW *, WINDOW * );
  405. extern int overwrite ( const WINDOW *, WINDOW * );
  406. extern int pair_content ( short, short *, short * );
  407. //extern int pechochar ( WINDOW *, chtype );
  408. //extern int pnoutrefresh ( WINDOW *, int, int, int, int, int, int );
  409. //extern int prefresh ( WINDOW *, int, int, int, int, int, int );
  410. extern int printw ( char *, ... );
  411. extern int putp ( const char * );
  412. extern void qiflush ( void );
  413. extern int raw ( void );
  414. //extern int redrawwin ( WINDOW * );
  415. //extern int refresh ( void );
  416. extern int reset_prog_mode ( void );
  417. extern int reset_shell_mode ( void );
  418. extern int resetty ( void );
  419. extern int ripoffline ( int, int (*) ( WINDOW *, int) );
  420. extern int savetty ( void );
  421. //extern int scanw ( char *, ... );
  422. //extern int scrl ( int );
  423. //extern int scroll ( WINDOW * );
  424. //extern int scrollok ( WINDOW *, bool );
  425. //extern int setscrreg ( int, int );
  426. extern SCREEN *set_term ( SCREEN * );
  427. extern int setupterm ( char *, int, int * );
  428. extern int slk_attr_off ( const attr_t, void * );
  429. extern int slk_attroff ( const chtype );
  430. extern int slk_attr_on ( const attr_t, void * );
  431. extern int slk_attron ( const chtype );
  432. extern int slk_attr_set ( const attr_t, short, void * );
  433. extern int slk_attrset ( const chtype );
  434. extern int slk_clear ( void );
  435. extern int slk_colour ( short );
  436. #define slk_color( c ) slk_colour( (c) )
  437. extern int slk_init ( int );
  438. extern char *slk_label ( int );
  439. extern int slk_noutrefresh ( void );
  440. //extern int slk_refresh ( void );
  441. extern int slk_restore ( void );
  442. extern int slk_set ( int, const char *, int );
  443. extern int slk_touch ( void );
  444. extern int standend ( void );
  445. extern int standout ( void );
  446. //extern int start_colour ( void );
  447. #define start_color() start_colour()
  448. //extern WINDOW *subpad ( WINDOW *, int, int, int, int );
  449. extern WINDOW *subwin ( WINDOW *, int, int, int, int );
  450. extern int syncok ( WINDOW *, bool );
  451. extern chtype termattrs ( void );
  452. extern attr_t term_attrs ( void );
  453. extern char *termname ( void );
  454. extern int tigetflag ( char * );
  455. extern int tigetnum ( char * );
  456. extern char *tigetstr ( char * );
  457. extern void timeout ( int );
  458. //extern int touchline ( WINDOW *, int, int );
  459. //extern int touchwin ( WINDOW * );
  460. extern char *tparm ( char *, long, long, long, long, long, long, long, long,
  461. long );
  462. extern int typeahead ( int );
  463. //extern int ungetch ( int );
  464. //extern int untouchwin ( WINDOW * );
  465. extern void use_env ( bool );
  466. extern int vid_attr ( attr_t, short, void * );
  467. extern int vidattr ( chtype );
  468. extern int vid_puts ( attr_t, short, void *, int ( *) ( int) );
  469. extern int vidputs ( chtype, int ( *) ( int) );
  470. //extern int vline ( chtype, int );
  471. //extern int vwprintw ( WINDOW *, const char *, va_list );
  472. extern int vw_printw ( WINDOW *, const char *, va_list );
  473. //extern int vwscanw ( WINDOW *, char *, va_list );
  474. //extern int vw_scanw ( WINDOW *, char *, va_list );
  475. extern int waddch ( WINDOW *, const chtype );
  476. extern int waddchnstr ( WINDOW *, const chtype *, int );
  477. //extern int waddchstr ( WINDOW *, const chtype * );
  478. extern int waddnstr ( WINDOW *, const char *, int );
  479. //extern int waddstr ( WINDOW *, const char * );
  480. extern int wattroff ( WINDOW *, int );
  481. extern int wattron ( WINDOW *, int );
  482. extern int wattrset ( WINDOW *, int );
  483. extern int wattr_get ( WINDOW *, attr_t *, short *, void * );
  484. extern int wattr_off ( WINDOW *, attr_t, void * );
  485. extern int wattr_on ( WINDOW *, attr_t, void * );
  486. extern int wattr_set ( WINDOW *, attr_t, short, void * );
  487. //extern void wbkgdset ( WINDOW *, chtype );
  488. extern int wborder ( WINDOW *, chtype, chtype, chtype, chtype, chtype, chtype,
  489. chtype, chtype );
  490. extern int wclrtobot ( WINDOW * );
  491. extern int wclrtoeol ( WINDOW * );
  492. extern void wcursyncup ( WINDOW * );
  493. extern int wcolour_set ( WINDOW *, short, void * );
  494. #define wcolor_set(w,s,v) wcolour_set((w),(s),(v))
  495. extern int wdelch ( WINDOW * );
  496. extern int wdeleteln ( WINDOW * );
  497. extern int wechochar ( WINDOW *, const chtype );
  498. extern int werase ( WINDOW * );
  499. extern int wgetch ( WINDOW * );
  500. extern int wgetnstr ( WINDOW *, char *, int );
  501. //extern int wgetstr ( WINDOW *, char * );
  502. extern int whline ( WINDOW *, chtype, int );
  503. //extern chtype winch ( WINDOW * );
  504. //extern int winchnstr ( WINDOW *, chtype *, int );
  505. //extern int winchstr ( WINDOW *, chtype * );
  506. //extern int winnstr ( WINDOW *, char *, int );
  507. //extern int winsch ( WINDOW *, chtype );
  508. //extern int winsnstr ( WINDOW *, const char *, int );
  509. //extern int winsstr ( WINDOW *, const char * );
  510. //extern int winstr ( WINDOW *, char * );
  511. extern int wmove ( WINDOW *, int, int );
  512. //extern int wnoutrefresh ( WINDOW * );
  513. extern int wprintw ( WINDOW *, const char *, ... );
  514. //extern int wredrawln ( WINDOW *, int, int );
  515. //extern int wrefresh ( WINDOW * );
  516. //extern int wscanw ( WINDOW *, char *, ... );
  517. //extern int wscrl ( WINDOW *, int );
  518. //extern int wsetscrreg ( WINDOW *, int, int );
  519. //extern int wstandend ( WINDOW * );
  520. //extern int wstandout ( WINDOW * );
  521. extern void wsyncup ( WINDOW * );
  522. extern void wsyncdown ( WINDOW * );
  523. extern void wtimeout ( WINDOW *, int );
  524. //extern int wtouchln ( WINDOW *, int, int, int );
  525. extern int wvline ( WINDOW *, chtype, int );
  526. /*
  527. * There is frankly a ridiculous amount of redundancy within the
  528. * curses API - ncurses decided to get around this by using #define
  529. * macros, but I've decided to be type-safe and implement them all as
  530. * static inlines instead...
  531. */
  532. static inline int addch ( const chtype ch ) {
  533. return waddch( stdscr, ch );
  534. }
  535. static inline int addchnstr ( const chtype *chstr, int n ) {
  536. return waddchnstr ( stdscr, chstr, n );
  537. }
  538. static inline int addchstr ( const chtype *chstr ) {
  539. return waddchnstr ( stdscr, chstr, -1 );
  540. }
  541. static inline int addnstr ( const char *str, int n ) {
  542. return waddnstr ( stdscr, str, n );
  543. }
  544. static inline int addstr ( const char *str ) {
  545. return waddnstr ( stdscr, str, -1 );
  546. }
  547. static inline int attroff ( int attrs ) {
  548. return wattroff ( stdscr, attrs );
  549. }
  550. static inline int attron ( int attrs ) {
  551. return wattron ( stdscr, attrs );
  552. }
  553. static inline int attrset ( int attrs ) {
  554. return wattrset ( stdscr, attrs );
  555. }
  556. static inline void bkgdset ( chtype ch ) {
  557. wattrset ( stdscr, ch );
  558. }
  559. static inline int border ( chtype ls, chtype rs, chtype ts, chtype bs,
  560. chtype tl, chtype tr, chtype bl, chtype br ) {
  561. return wborder ( stdscr, ls, rs, ts, bs, tl, tr, bl, br );
  562. }
  563. static inline bool can_change_colour ( void ) {
  564. return FALSE;
  565. }
  566. static inline int clrtobot ( void ) {
  567. return wclrtobot( stdscr );
  568. }
  569. static inline int clrtoeol ( void ) {
  570. return wclrtoeol( stdscr );
  571. }
  572. static inline int colour_set ( short colour_pair_number, void *opts ) {
  573. return wcolour_set ( stdscr, colour_pair_number, opts );
  574. }
  575. static inline int delch ( void ) {
  576. return wdelch ( stdscr );
  577. }
  578. static inline int deleteln ( void ) {
  579. return wdeleteln( stdscr );
  580. }
  581. static inline int erase ( void ) {
  582. return werase ( stdscr );
  583. }
  584. static inline int getch ( void ) {
  585. return wgetch ( stdscr );
  586. }
  587. static inline int getnstr ( char *str, int n ) {
  588. return wgetnstr ( stdscr, str, n );
  589. }
  590. static inline int getstr ( char *str ) {
  591. return wgetnstr ( stdscr, str, -1 );
  592. }
  593. static inline bool has_colors ( void ) {
  594. return TRUE;
  595. }
  596. static inline int hline ( chtype ch, int n ) {
  597. return whline ( stdscr, ch, n );
  598. }
  599. static inline int move ( int y, int x ) {
  600. return wmove ( stdscr, y, x );
  601. }
  602. static inline int mvaddch ( int y, int x, const chtype ch ) {
  603. return ( wmove ( stdscr, y, x ) == OK
  604. ? waddch( stdscr, ch ) : ERR );
  605. }
  606. static inline int mvaddchnstr ( int y, int x, const chtype *chstr, int n ) {
  607. return ( wmove ( stdscr, y, x ) == OK
  608. ? waddchnstr ( stdscr, chstr, n ) : ERR );
  609. }
  610. static inline int mvaddchstr ( int y, int x, const chtype *chstr ) {
  611. return ( wmove ( stdscr, y, x ) == OK
  612. ? waddchnstr ( stdscr, chstr, -1 ) : ERR );
  613. }
  614. static inline int mvaddnstr ( int y, int x, const char *str, int n ) {
  615. return ( wmove ( stdscr, y, x ) == OK
  616. ? waddnstr ( stdscr, str, n ) : ERR );
  617. }
  618. static inline int mvaddstr ( int y, int x, const char *str ) {
  619. return ( wmove ( stdscr, y, x ) == OK
  620. ? waddnstr ( stdscr, str, -1 ) : ERR );
  621. }
  622. static inline int mvdelch ( int y, int x ) {
  623. return ( wmove ( stdscr, y, x ) == OK
  624. ? wdelch ( stdscr ) : ERR );
  625. }
  626. static inline int mvgetch ( int y, int x ) {
  627. return ( wmove ( stdscr, y, x ) == OK
  628. ? wgetch ( stdscr ) : ERR );
  629. }
  630. static inline int mvgetnstr ( int y, int x, char *str, int n ) {
  631. return ( wmove ( stdscr, y, x ) == OK
  632. ? wgetnstr ( stdscr, str, n ) : ERR );
  633. }
  634. static inline int mvgetstr ( int y, int x, char *str ) {
  635. return ( wmove ( stdscr, y, x ) == OK
  636. ? wgetnstr ( stdscr, str, -1 ) : ERR );
  637. }
  638. static inline int mvhline ( int y, int x, chtype ch, int n ) {
  639. return ( wmove ( stdscr, y, x ) == OK
  640. ? whline ( stdscr, ch, n ) : ERR );
  641. }
  642. // OK, so maybe a few I did with macros...
  643. #define mvprintw( y, x, fmt, ... ) \
  644. ( wmove(stdscr,(y),(x)) == OK \
  645. ? wprintw( stdscr,(fmt), ## __VA_ARGS__ ) : ERR )
  646. static inline int mvvline ( int y, int x, chtype ch, int n ) {
  647. return ( wmove ( stdscr, y, x ) == OK
  648. ? wvline ( stdscr, ch, n ) : ERR );
  649. }
  650. static inline int mvwaddch ( WINDOW *win, int y, int x, const chtype ch ) {
  651. return ( wmove( win, y, x ) == OK
  652. ? waddch ( win, ch ) : ERR );
  653. }
  654. static inline int mvwaddchnstr ( WINDOW *win, int y, int x, const chtype *chstr, int n ) {
  655. return ( wmove ( win, y, x ) == OK
  656. ? waddchnstr ( win, chstr, n ) : ERR );
  657. }
  658. static inline int mvwaddchstr ( WINDOW *win, int y, int x, const chtype *chstr ) {
  659. return ( wmove ( win, y, x ) == OK
  660. ? waddchnstr ( win, chstr, -1 ) : ERR );
  661. }
  662. static inline int mvwaddnstr ( WINDOW *win, int y, int x, const char *str, int n ) {
  663. return ( wmove ( win, y, x ) == OK
  664. ? waddnstr ( win, str, n ) : ERR );
  665. }
  666. static inline int mvwaddstr ( WINDOW *win, int y, int x, const char *str ) {
  667. return ( wmove ( win, y, x ) == OK
  668. ? waddnstr ( win, str, -1 ) : ERR );
  669. }
  670. static inline int mvwdelch ( WINDOW *win, int y, int x ) {
  671. return ( wmove ( win, y, x ) == OK
  672. ? wdelch ( win ) : ERR );
  673. }
  674. static inline int mvwgetch ( WINDOW *win, int y, int x ) {
  675. return ( wmove ( win, y, x ) == OK
  676. ? wgetch ( win ) : ERR );
  677. }
  678. static inline int mvwgetnstr ( WINDOW *win, int y, int x, char *str, int n ) {
  679. return ( wmove ( win, y, x ) == OK
  680. ? wgetnstr ( win, str, n ) : ERR );
  681. }
  682. static inline int mvwgetstr ( WINDOW *win, int y, int x, char *str ) {
  683. return ( wmove ( win, y, x ) == OK
  684. ? wgetnstr ( win, str, -1 ) : ERR );
  685. }
  686. static inline int mvwhline ( WINDOW *win, int y, int x, chtype ch, int n ) {
  687. return ( wmove ( win, y, x ) == OK
  688. ? whline ( win, ch, n ) : ERR );
  689. }
  690. #define mvwprintw( win, y, x, fmt, ... ) \
  691. ( wmove((win),(y),(x)) == OK \
  692. ? wprintw((win),(fmt), ## __VA_ARGS__) : ERR )
  693. static inline int mvwvline ( WINDOW *win, int y, int x, chtype ch, int n ) {
  694. return ( wmove ( win, y, x ) == OK
  695. ? wvline ( win, ch, n ) : ERR );
  696. }
  697. #define printw( fmt, ... ) wprintw(stdscr,(fmt), ## __VA_ARGS__ )
  698. static inline int slk_refresh ( void ) {
  699. if ( slk_clear() == OK )
  700. return slk_restore();
  701. else
  702. return ERR;
  703. }
  704. #define standend() wstandend( stdscr )
  705. #define standout() wstandout( stdscr )
  706. static inline int start_colour ( void ) {
  707. return OK;
  708. }
  709. static inline int vline ( chtype ch, int n ) {
  710. return wvline ( stdscr, ch, n );
  711. }
  712. // marked for removal
  713. static inline int vwprintw ( WINDOW *win, const char *fmt, va_list varglist ) {
  714. return vw_printw ( win, fmt, varglist );
  715. }
  716. static inline int waddchstr ( WINDOW *win, const chtype *chstr ) {
  717. return waddchnstr ( win, chstr, -1 );
  718. }
  719. static inline int waddstr ( WINDOW *win, const char *str ) {
  720. return waddnstr ( win, str, -1 );
  721. }
  722. static inline int wbkgdset ( WINDOW *win, chtype ch ) {
  723. return wattrset( win, ch );
  724. }
  725. static inline int wgetstr ( WINDOW *win, char *str ) {
  726. return wgetnstr ( win, str, -1 );
  727. }
  728. static inline int wstandend ( WINDOW *win ) {
  729. return wattrset ( win, A_DEFAULT );
  730. }
  731. static inline int wstandout ( WINDOW *win ) {
  732. return wattrset ( win, A_STANDOUT );
  733. }
  734. #endif /* CURSES_H */