From 98a21ce9edcd22bf7a9dde62f317f143e289ecf5 Mon Sep 17 00:00:00 2001 From: dam Date: Tue, 4 Apr 2023 17:45:05 +0100 Subject: WIP Making ncurses work a bit. --- curses.jai | 303 +++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 244 insertions(+), 59 deletions(-) (limited to 'curses.jai') diff --git a/curses.jai b/curses.jai index 866d99e..532054a 100644 --- a/curses.jai +++ b/curses.jai @@ -1,62 +1,62 @@ ldat :: struct { - text :*void; /* text of the line */ - firstchar :s16; /* first changed character in the line */ - lastchar :s16; /* last changed character in the line */ - oldindex :s16; /* index of the line at last update */ + text :*void; /* text of the line */ + firstchar :s16; /* first changed character in the line */ + lastchar :s16; /* last changed character in the line */ + oldindex :s16; /* index of the line at last update */ }; // TODO This also works... -WINDOW :: struct { +WINDOWx :: struct { data : [88] u8; } -WINDOWx :: struct { - _cury, _curx : s16; /* current cursor position */ - - /* window location and size */ - _maxy, _maxx : s16; /* maximums of x and y, NOT window size */ - _begy, _begx : s16; /* screen coords of upper-left-hand corner */ - - _flags :s16; /* window state flags */ - - /* attribute tracking */ - _attrs :u8; /* current attribute for non-space character */ - _bkgd :u8; /* current background char/attribute pair */ - - /* option values set by user */ - _notimeout :bool; /* no time out on function-key entry? */ - _clear :bool; /* consider all data in the window invalid? */ - _leaveok :bool; /* OK to not reset cursor on exit? */ - _scroll :bool; /* OK to scroll this window? */ - _idlok :bool; /* OK to use insert/delete line? */ - _idcok :bool; /* OK to use insert/delete char? */ - _immed :bool; /* window in immed mode? (not yet used) */ - _sync :bool; /* window in sync mode? */ - _use_keypad :bool; /* process function keys into KEY_ symbols? */ - _delay :s32; /* 0 = nodelay, <0 = blocking, >0 = delay */ - - _line :*ldat; /* the actual line data */ - - /* global screen state */ - _regtop :s16; /* top line of scrolling region */ - _regbottom :s16; /* bottom line of scrolling region */ - - /* these are used only if this is a sub-window */ - _parx :s32; /* x coordinate of this window in parent */ - _pary :s32; /* y coordinate of this window in parent */ +WINDOW :: struct { + _cury, _curx : s16; /* current cursor position */ + + /* window location and size */ + _maxy, _maxx : s16; /* maximums of x and y, NOT window size */ + _begy, _begx : s16; /* screen coords of upper-left-hand corner */ + + _flags :s16; /* window state flags */ + + /* attribute tracking */ + _attrs :u8; /* current attribute for non-space character */ + _bkgd :u8; /* current background char/attribute pair */ + + /* option values set by user */ + _notimeout :bool; /* no time out on function-key entry? */ + _clear :bool; /* consider all data in the window invalid? */ + _leaveok :bool; /* OK to not reset cursor on exit? */ + _scroll :bool; /* OK to scroll this window? */ + _idlok :bool; /* OK to use insert/delete line? */ + _idcok :bool; /* OK to use insert/delete char? */ + _immed :bool; /* window in immed mode? (not yet used) */ + _sync :bool; /* window in sync mode? */ + _use_keypad :bool; /* process function keys into KEY_ symbols? */ + _delay :s32; /* 0 = nodelay, <0 = blocking, >0 = delay */ + + _line :*ldat; /* the actual line data */ + + /* global screen state */ + _regtop :s16; /* top line of scrolling region */ + _regbottom :s16; /* bottom line of scrolling region */ + + /* these are used only if this is a sub-window */ + _parx :s32; /* x coordinate of this window in parent */ + _pary :s32; /* y coordinate of this window in parent */ _parent :*WINDOW; /* pointer to parent if a sub-window */ - /* these are used only if this is a pad */ - pdat :: struct - { - _pad_y, _pad_x :s16 ; - _pad_top, _pad_left :s16; - _pad_bottom, _pad_right :s16; - }; + /* these are used only if this is a pad */ + pdat :: struct + { + _pad_y, _pad_x :s16 ; + _pad_top, _pad_left :s16; + _pad_bottom, _pad_right :s16; + }; _pad :pdat; - - _yoffset :s16; /* real begy is _begy + _yoffset */ + + _yoffset :s16; /* real begy is _begy + _yoffset */ /* #if NCURSES_WIDECHAR @@ -79,29 +79,214 @@ tinfo :: #system_library "libtinfo"; // Required by some of ncurses functions. // ncurses :: #system_library "libncurses"; ncurses :: #library "libncurses"; -COLOR_BLACK :: 0; -COLOR_RED :: 1; -COLOR_GREEN :: 2; -COLOR_YELLOW :: 3; -COLOR_BLUE :: 4; -COLOR_MAGENTA :: 5; -COLOR_CYAN :: 6; -COLOR_WHITE :: 7; - stdscr : *WINDOW; initscr :: () -> *WINDOW #foreign ncurses; -getch :: () -> s8 #foreign ncurses; +getch :: () -> s32 #foreign ncurses; endwin :: () -> void #foreign ncurses; cbreak :: () -> void #foreign ncurses; start_color :: () -> void #foreign ncurses; use_default_colors :: () -> void #foreign ncurses; - +flushinp :: () -> s32 #foreign ncurses; keypad :: (win: *WINDOW, bf: bool) -> s32 #foreign ncurses; +ungetch :: (ch: s32) -> s32 #foreign ncurses; +attrset :: (attrs: s32) -> s32 #foreign ncurses; +erase :: () -> s32 #foreign ncurses; curs_set :: (visibility: s32) -> s32 #foreign ncurses; mvaddstr :: (y: s32, x: s32, str: *u8) -> s32 #foreign ncurses; noecho :: () -> s32 #foreign ncurses; box :: (win: *WINDOW, verch: u8, horch: u8) -> s32 #foreign ncurses; init_pair :: (pair: s16, f: s16, b: s16) -> s32 #foreign ncurses; +timeout :: (delay: s32) -> void #foreign ncurses; +mvaddch :: (y: s32, x: s32, ch: u32) -> s32 #foreign ncurses; +clear :: () -> s32 #foreign ncurses; +refresh :: () -> s32 #foreign ncurses; + +getmaxyx :: inline (win: *WINDOW, y: *s32, x: *s32) { < s32 { return ifx win == null then ERR else win._maxx + 1; } +getmaxy :: inline (win: *WINDOW) -> s32 { return ifx win == null then ERR else win._maxy + 1; } +getcurx :: inline (win: *WINDOW) -> s32 { return ifx win == null then ERR else win._curx; } +getcury :: inline (win: *WINDOW) -> s32 { return ifx win == null then ERR else win._cury; } + +//#if CPU == .X64 { +//typedef unsigned chtype; // Used for mask and shift vars. +//typedef unsigned mmask_t; +//} else { +//typedef uint32_t chtype; +//typedef uint32_t mmask_t; +//} +NCURSES_ATTR_SHIFT :: 8; +NCURSES_BITS :: inline (mask: u32, shift: u32) -> u32 { return mask << (shift + NCURSES_ATTR_SHIFT); } + +A_NORMAL :: 0; +A_ATTRIBUTES :: #run NCURSES_BITS(~(cast(u32)(1 - 1)),0); +A_CHARTEXT :: #run (NCURSES_BITS(1,0) - 1); +A_COLOR :: #run NCURSES_BITS(((1) << 8) - 1,0); +A_STANDOUT :: #run NCURSES_BITS(1,8); +A_UNDERLINE :: #run NCURSES_BITS(1,9); +A_REVERSE :: #run NCURSES_BITS(1,10); +A_BLINK :: #run NCURSES_BITS(1,11); +A_DIM :: #run NCURSES_BITS(1,12); +A_BOLD :: #run NCURSES_BITS(1,13); +A_ALTCHARSET :: #run NCURSES_BITS(1,14); +A_INVIS :: #run NCURSES_BITS(1,15); +A_PROTECT :: #run NCURSES_BITS(1,16); +A_HORIZONTAL :: #run NCURSES_BITS(1,17); +A_LEFT :: #run NCURSES_BITS(1,18); +A_LOW :: #run NCURSES_BITS(1,19); +A_RIGHT :: #run NCURSES_BITS(1,20); +A_TOP :: #run NCURSES_BITS(1,21); +A_VERTICAL :: #run NCURSES_BITS(1,22); +A_ITALIC :: #run NCURSES_BITS(1,23); // ncurses extension + +// VT100 symbols begin here. +ACS_ULCORNER :: #run A_ALTCHARSET | #char "l"; /* upper left corner */ +ACS_LLCORNER :: #run A_ALTCHARSET | #char "m"; /* lower left corner */ +ACS_URCORNER :: #run A_ALTCHARSET | #char "k"; /* upper right corner */ +ACS_LRCORNER :: #run A_ALTCHARSET | #char "j"; /* lower right corner */ +ACS_LTEE :: #run A_ALTCHARSET | #char "t"; /* tee pointing right */ +ACS_RTEE :: #run A_ALTCHARSET | #char "u"; /* tee pointing left */ +ACS_BTEE :: #run A_ALTCHARSET | #char "v"; /* tee pointing up */ +ACS_TTEE :: #run A_ALTCHARSET | #char "w"; /* tee pointing down */ +ACS_HLINE :: #run A_ALTCHARSET | #char "q"; /* horizontal line */ +ACS_VLINE :: #run A_ALTCHARSET | #char "x"; /* vertical line */ +ACS_PLUS :: #run A_ALTCHARSET | #char "n"; /* large plus or crossover */ +ACS_S1 :: #run A_ALTCHARSET | #char "o"; /* scan line 1 */ +ACS_S9 :: #run A_ALTCHARSET | #char "s"; /* scan line 9 */ +ACS_DIAMOND :: #run A_ALTCHARSET | #char "`"; /* diamond */ +ACS_CKBOARD :: #run A_ALTCHARSET | #char "a"; /* checker board (stipple) */ +ACS_DEGREE :: #run A_ALTCHARSET | #char "f"; /* degree symbol */ +ACS_PLMINUS :: #run A_ALTCHARSET | #char "g"; /* plus/minus */ +ACS_BULLET :: #run A_ALTCHARSET | #char "~"; /* bullet */ +// Teletype 5410v1 symbols begin here. +ACS_LARROW :: #run A_ALTCHARSET | #char ","; /* arrow pointing left */ +ACS_RARROW :: #run A_ALTCHARSET | #char "+"; /* arrow pointing right */ +ACS_DARROW :: #run A_ALTCHARSET | #char "."; /* arrow pointing down */ +ACS_UARROW :: #run A_ALTCHARSET | #char "-"; /* arrow pointing up */ +ACS_BOARD :: #run A_ALTCHARSET | #char "h"; /* board of squares */ +ACS_LANTERN :: #run A_ALTCHARSET | #char "i"; /* lantern symbol */ +ACS_BLOCK :: #run A_ALTCHARSET | #char "0"; /* solid square block */ +// These aren't documented, but a lot of System Vs have them anyway +// (you can spot pprryyzz{{||}} in a lot of AT&T terminfo strings). +// The ACS_names may not match AT&T's, our source didn't know them. +ACS_S3 :: #run A_ALTCHARSET | #char "p"; /* scan line 3 */ +ACS_S7 :: #run A_ALTCHARSET | #char "r"; /* scan line 7 */ +ACS_LEQUAL :: #run A_ALTCHARSET | #char "y"; /* less/equal */ +ACS_GEQUAL :: #run A_ALTCHARSET | #char "z"; /* greater/equal */ +ACS_PI :: #run A_ALTCHARSET | #char "{"; /* Pi */ +ACS_NEQUAL :: #run A_ALTCHARSET | #char "|"; /* not equal */ +ACS_STERLING :: #run A_ALTCHARSET | #char "}"; /* UK pound sign */ + + +COLOR_PAIR :: (n: s32) -> s32 #foreign ncurses; + +COLOR_BLACK :: 0; +COLOR_RED :: 1; +COLOR_GREEN :: 2; +COLOR_YELLOW :: 3; +COLOR_BLUE :: 4; +COLOR_MAGENTA :: 5; +COLOR_CYAN :: 6; +COLOR_WHITE :: 7; + +ERR :: -1; +OK :: 0; + + +KEY_CODE_YES :: 0400; +KEY_MIN :: 0401; +KEY_BREAK :: 0401; +KEY_SRESET :: 0530; +KEY_RESET :: 0531; +KEY_DOWN :: 0402; +KEY_UP :: 0403; +KEY_LEFT :: 0404; +KEY_RIGHT :: 0405; +KEY_HOME :: 0406; +KEY_BACKSPACE :: 0407; +KEY_F0 :: 0410; +KEY_F :: inline (n: s32) -> s32 { return KEY_F0+n; }; +KEY_DL :: 0510; +KEY_IL :: 0511; +KEY_DC :: 0512; +KEY_IC :: 0513; +KEY_EIC :: 0514; +KEY_CLEAR :: 0515; +KEY_EOS :: 0516; +KEY_EOL :: 0517; +KEY_SF :: 0520; +KEY_SR :: 0521; +KEY_NPAGE :: 0522; +KEY_PPAGE :: 0523; +KEY_STAB :: 0524; +KEY_CTAB :: 0525; +KEY_CATAB :: 0526; +KEY_ENTER :: 0527; +KEY_PRINT :: 0532; +KEY_LL :: 0533; +KEY_A1 :: 0534; +KEY_A3 :: 0535; +KEY_B2 :: 0536; +KEY_C1 :: 0537; +KEY_C3 :: 0540; +KEY_BTAB :: 0541; +KEY_BEG :: 0542; +KEY_CANCEL :: 0543; +KEY_CLOSE :: 0544; +KEY_COMMAND :: 0545; +KEY_COPY :: 0546; +KEY_CREATE :: 0547; +KEY_END :: 0550; +KEY_EXIT :: 0551; +KEY_FIND :: 0552; +KEY_HELP :: 0553; +KEY_MARK :: 0554; +KEY_MESSAGE :: 0555; +KEY_MOVE :: 0556; +KEY_NEXT :: 0557; +KEY_OPEN :: 0560; +KEY_OPTIONS :: 0561; +KEY_PREVIOUS :: 0562; +KEY_REDO :: 0563; +KEY_REFERENCE :: 0564; +KEY_REFRESH :: 0565; +KEY_REPLACE :: 0566; +KEY_RESTART :: 0567; +KEY_RESUME :: 0570; +KEY_SAVE :: 0571; +KEY_SBEG :: 0572; +KEY_SCANCEL :: 0573; +KEY_SCOMMAND :: 0574; +KEY_SCOPY :: 0575; +KEY_SCREATE :: 0576; +KEY_SDC :: 0577; +KEY_SDL :: 0600; +KEY_SELECT :: 0601; +KEY_SEND :: 0602; +KEY_SEOL :: 0603; +KEY_SEXIT :: 0604; +KEY_SFIND :: 0605; +KEY_SHELP :: 0606; +KEY_SHOME :: 0607; +KEY_SIC :: 0610; +KEY_SLEFT :: 0611; +KEY_SMESSAGE :: 0612; +KEY_SMOVE :: 0613; +KEY_SNEXT :: 0614; +KEY_SOPTIONS :: 0615; +KEY_SPREVIOUS :: 0616; +KEY_SPRINT :: 0617; +KEY_SREDO :: 0620; +KEY_SREPLACE :: 0621; +KEY_SRIGHT :: 0622; +KEY_SRSUME :: 0623; +KEY_SSAVE :: 0624; +KEY_SSUSPEND :: 0625; +KEY_SUNDO :: 0626; +KEY_SUSPEND :: 0627; +KEY_UNDO :: 0630; +KEY_MOUSE :: 0631; +KEY_RESIZE :: 0632; +KEY_MAX :: 0777; -- cgit v1.2.3