ncurses.nim 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  1. {.deadCodeElim: on.}
  2. when defined(windows):
  3. const libncurses* = "libncurses(w|w6).dll"
  4. elif defined(macosx):
  5. const libncurses* = "libncurses.dylib"
  6. else:
  7. const libncurses* = "libncursesw.so(.5|.6|)"
  8. type
  9. chtype* = cuint ## Holds a character and possibly an attribute
  10. attr_t* = chtype ## Attribute type
  11. cchar_t* = object ## Complex char
  12. attr: attr_t
  13. chars: WideCString #5
  14. ext_color: cint
  15. ldat = object ## Holds line data
  16. Screen* = object
  17. Terminal* = object
  18. Window* = object ## Holds window data
  19. cury, curx: cshort # current cursor position
  20. # window location and size
  21. maxy, maxx: cshort # maximums of x and y, NOT window size
  22. begy, begx: cshort # screen coords of upper-left-hand corner
  23. flags: cshort # window state flags
  24. # attribute tracking
  25. attrs: attr_t # current attribute for non-space character
  26. bkgd: chtype # current background char/attribute pair
  27. # option values set by user
  28. notimeout: bool # no time out on function-key entry?
  29. clear: bool # consider all data in the window invalid?
  30. leaveok: bool # OK to not reset cursor on exit?
  31. scroll: bool # OK to scroll this window?
  32. idlok: bool # OK to use insert/delete line?
  33. idcok: bool # OK to use insert/delete char?
  34. immed: bool # window in immed mode? (not yet used)
  35. sync: bool # window in sync mode?
  36. use_keypad: bool # process function keys into KEY_ symbols?
  37. delay: cint # 0 = nodelay, <0 = blocking, >0 = delay
  38. line: ptr ldat # the actual line data
  39. # global screen state
  40. regtop: cshort # top line of scrolling region
  41. regbottom: cshort # bottom line of scrolling region
  42. # these are used only if this is a sub-window
  43. pary, parx: cint # y, x coordinates of this window in parent
  44. parent: PWindow # pointer to parent if a sub-window
  45. # these are used only if this is a pad
  46. pad: pdat
  47. yoffset: cshort # real begy is _begy + _yoffset
  48. bkgrnd: cchar_t # current background char/attribute pair
  49. color: cint # current color-pair for non-space character
  50. window* {.deprecated: "Use PWindow instead".} = Window
  51. pdat = object ## pad data
  52. pad_y*, pad_x*: cshort
  53. pad_top*, pad_left*: cshort
  54. pad_bottom*, pad_right*: cshort
  55. mmask_t* = uint32
  56. Mevent* = object ## mouse event
  57. id*: cshort # ID to distinguish multiple devices
  58. x*, y*, z*: cint # event coordinates (character-cell)
  59. bstate*: mmask_t # button state bits
  60. #not ncurses but used to make things easier
  61. ErrCode* = cint ## Error Code. Returns ERR (-1) upon failure or OK (0) on success.
  62. PWindow* = ptr Window
  63. PScreen* = ptr Screen
  64. const
  65. ERR*: ErrCode = (-1)
  66. OK*: ErrCode = (0)
  67. NCURSES_ATTR_SHIFT = 8
  68. template NCURSES_CAST(`type`, value: untyped): untyped = (`type`)(value)
  69. template NCURSES_BITS(mask, shift: untyped): untyped =
  70. (NCURSES_CAST(chtype, (mask)) shl ((shift) + NCURSES_ATTR_SHIFT))
  71. #color: color manipulation routines
  72. const
  73. COLOR_BLACK* = 0
  74. COLOR_RED* = 1
  75. COLOR_GREEN* = 2
  76. COLOR_YELLOW* = 3
  77. COLOR_BLUE* = 4
  78. COLOR_MAGENTA* = 5
  79. COLOR_CYAN* = 6
  80. COLOR_WHITE* = 7
  81. var
  82. COLORS* {.importc: "COLORS", dynlib: libncurses.}: cint
  83. ## Initialized by start_color to the maximum number of colors thfe
  84. ## terminal can support.
  85. COLOR_PAIRS* {.importc: "COLOR_PAIRS", dynlib: libncurses.}: cint
  86. ## Initialized by start_color to the maximum number of color pairs the
  87. ## terminal can support.
  88. template COLOR_PAIR*(n: untyped): untyped = NCURSES_BITS((n), 0'i64)
  89. template PAIR_NUMBER*(a: untyped): untyped =
  90. (NCURSES_CAST(cint, ((NCURSES_CAST(cuint, (a)) and A_COLOR) shr
  91. NCURSES_ATTR_SHIFT)))
  92. proc start_color*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  93. ## Initialises the the eight basic colours and the two global varables COLORS and COLOR_PAIRS.
  94. ## It also restores the colours on the terminal to the values that they had when the
  95. ## terminal was just turned on.
  96. ## @Note: It is good practice to call this routine right after initscr. It must be
  97. ## called before any other colour manipulating routines.
  98. proc has_colors*(): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  99. ## Used to determine if the terminal can manipulate colours.
  100. ## @Returns: true if the terminal can manipulate colours or false if it cannot.
  101. proc can_change_color*(): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  102. ## Used to determine if the terminal supports colours and can change their definitions.
  103. ## @Returns: true if the terminal supports colours and can change their definitions or
  104. ## false otherwise.
  105. proc init_pair*(pair, f,b: cshort): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  106. ## Changes the definition of a colour pair.
  107. ## @Param: 'pair' the number of the colour pair to change.
  108. ## @Param: 'foreground': the foreground colour number.
  109. ## @Param: 'background': the background colour number.
  110. ## @Returns: ERR on failure and OK upon successful completion.
  111. proc init_color*(color: cshort, r, g, b: cshort): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  112. proc init_extended_pair*(pair, f,b: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  113. proc init_extended_color*(color: cint, r, g, b: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  114. proc color_content*(color: cshort, r, g, b: ptr cshort): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  115. proc pair_content*(pair: cshort, f,b: ptr cshort): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  116. proc extended_color_content*(color: cint, r, g, b: ptr cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  117. proc pair_content*(pair: cint, f,b: ptr cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  118. proc reset_color_pairs*(): void {.cdecl, importc, discardable, dynlib: libncurses.}
  119. #threads: thread support
  120. proc get_escdelay*(): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  121. proc set_escdelay*(size: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  122. proc set_tabsize*(size: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  123. proc use_screen*(scr: PScreen, scr_cb: proc(scr: PScreen, pt: pointer): cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  124. proc use_window*(win: PWindow, win_cb: proc(win: PWindow, pt: pointer): cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  125. #add_wch: Adding complex characters to a window
  126. proc add_wch*(wch: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  127. proc wadd_wch*(win: PWindow, wch: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  128. proc mvadd_wch*(y, x: cint, wch: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  129. proc mvwadd_wch*(win: PWindow, y, x: cint, wch: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  130. proc echo_wchar*(wch: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  131. proc wecho_wchar*(win: PWindow, wch: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  132. #add_wchstr: Adding an array of complex characters to a window
  133. proc add_wchstr*(wchstr: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  134. proc add_wchnstr*(wchstr: ptr cchar_t, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  135. proc wadd_wchstr*(win: PWindow, wchstr: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  136. proc wadd_wchnstr*(win: PWindow, wchstr: ptr cchar_t, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  137. proc mvadd_wchstr*(y, x: cint, wchstr: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  138. proc mvadd_wchnstr*(y, x: cint, wchstr: ptr cchar_t, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  139. proc mvwadd_wchstr*(win: PWindow, y, x: cint, wchstr: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  140. proc mvwadd_wchnstr*(win: PWindow, y, x: cint, wchstr: ptr cchar_t, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  141. #addch: Adding a character (with attributes) to a window
  142. proc addch*(character: chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  143. ## Puts a character into the stdscr at its current window position and then advances
  144. ## the current window position to the next position.
  145. ## @Param: 'character' the character to put into the current window.
  146. ## @Returns: ERR on failure and OK upon successful completion.
  147. proc waddch*(win: PWindow, ch: chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  148. proc mvaddch*(y,x: cint; character: chtype): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  149. ## Moves the cursor to the specified position and outputs the provided character.
  150. ## The cursor is then advanced to the next position.
  151. ## @Param: 'y' the line to move the cursor to.
  152. ## @Param: 'x' the column to move the cursor to.
  153. ## @Param: 'character' the character to put into the current window.
  154. ## @Returns: ERR on failure and OK upon successful completion.
  155. proc mvwaddch*(win: PWindow, y, x: cint, ch: chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  156. proc echochar*(ch: chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  157. proc wechochar*(win: PWindow, ch: chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  158. #addchstr: Adding a string of characters (and attributes) to a window
  159. proc addchstr*(chstr: ptr chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  160. proc addchnstr*(chstr: ptr chtype, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  161. proc waddchstr*(win: PWindow, chstr: ptr chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  162. proc waddchnstr*(win: PWindow, chstr: ptr chtype, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  163. proc mvaddchstr*(y, x: cint, chstr: ptr chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  164. proc mvaddchnstr*(y, x: cint, chstr: ptr chtype, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  165. proc mvwaddchstr*(win: PWindow, y, x: cint, chstr: ptr chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  166. proc mvwaddchnstr*(win: PWindow, y, x: cint, chstr: ptr chtype, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  167. #addstr: Adding a string of characters to a window (cstring)
  168. proc addstr*(str: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  169. ## Adds a string of characters the the stdscr and advances the cursor.
  170. ## @Param: The string to add the stdscr.
  171. ## @Returns: ERR on failure and OK upon successful completion.
  172. proc addnstr*(str: cstring, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  173. proc waddstr*(win: PWindow; str: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  174. ## Writes a string to the specified window.
  175. ## @Param: 'destinationWindow' the window to write the string to.
  176. ## @Param: 'stringToWrite'
  177. ## @Returns: ERR on failure and OK upon successful completion.
  178. proc waddnstr*(win: PWindow, str: cstring, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  179. proc mvaddstr*(y, x: cint; str: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  180. ## Moves the cursor to the specified position and outputs the provided string.
  181. ## The cursor is then advanced to the next position.
  182. ## @Param: 'y' the line to move the cursor to.
  183. ## @Param: 'x' the column to move the cursor to.
  184. ## @Param: 'stringToOutput' the string to put into the current window.
  185. ## @Returns: ERR on failure and OK upon successful completion.
  186. proc mvaddnstr*(y, x: cint, str: cstring, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  187. proc mvwaddstr*(win: PWindow, y, x: cint, str: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  188. proc mvwaddnstr*(win: PWindow, y, x: cint, str: cstring, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  189. #addwstr: Adding a string of wide characters to a window (WideCString) ## Not used?
  190. #[
  191. proc addwstr(wstr: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  192. proc addnwstr(wstr: WideCString, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  193. proc waddwstr(win: PWindow, wstr: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  194. proc waddnwstr(win: PWindow, wstr: WideCString, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  195. proc mvaddwstr(y, x: cint, win: PWindow, wstr: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  196. proc mvaddnwstr(y, x: cint, win: PWindow, wstr: WideCString, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  197. proc mvwaddwstr(win: PWindow, y, x: cint, wstr: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  198. proc mvwaddnwstr(win: PWindow, y, x: cint, wstr: WideCString, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  199. ]#
  200. #new_pair: Color-pair functions
  201. proc alloc_pair*(fg, bg: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  202. proc find_pair*(fg, bg: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  203. proc free_pair*(pair: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  204. #default_colors: Use terminal's default colors
  205. proc use_default_colors*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  206. proc assume_default_colors*(fg, bg: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  207. #attr: Character and attribute control routines
  208. const
  209. u1: cuint = 1
  210. A_NORMAL* = (u1 - u1)
  211. A_ATTRIBUTES* = NCURSES_BITS(not (u1 - u1), 0)
  212. A_CHAR_TEXT* = (NCURSES_BITS(u1, 0) - u1.chtype)
  213. A_COLOR* = NCURSES_BITS((u1 shl 8) - u1, 0)
  214. A_STANDOUT* = NCURSES_BITS(u1, 8)
  215. A_UNDERLINE* = NCURSES_BITS(u1, 9)
  216. A_REVERSE* = NCURSES_BITS(u1, 10)
  217. A_BLINK* = NCURSES_BITS(u1, 11)
  218. A_DIM* = NCURSES_BITS(u1, 12)
  219. A_BOLD* = NCURSES_BITS(u1, 13)
  220. A_ALT_CHARSET* = NCURSES_BITS(u1, 14)
  221. A_INVIS* = NCURSES_BITS(u1, 15)
  222. A_PROTECT* = NCURSES_BITS(u1, 16)
  223. A_HORIZONTAL* = NCURSES_BITS(u1, 17)
  224. A_LEFT* = NCURSES_BITS(u1, 18)
  225. A_LOW* = NCURSES_BITS(u1, 19)
  226. A_RIGHT* = NCURSES_BITS(u1, 20)
  227. A_TOP* = NCURSES_BITS(u1, 21)
  228. A_VERTICAL* = NCURSES_BITS(u1, 22)
  229. A_ITALIC* = NCURSES_BITS(u1, 23)
  230. proc attr_get*(attrs: ptr attr_t, pair: ptr cshort, opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  231. proc wattr_get*(win: PWindow, attrs: ptr attr_t, pair: ptr cshort, opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  232. proc attr_set*(attrs: attr_t, pair: cshort, opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  233. proc wattr_set*(win: PWindow, attrs: attr_t, pair: cshort, opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  234. proc attr_off*(attrs: attr_t, opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  235. proc wattr_off*(win: PWindow, attrs: attr_t, opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  236. proc attr_on*(attrs: attr_t, opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  237. proc wattr_on*(win: PWindow, attrs: attr_t, opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  238. proc attroff*(attrs: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  239. ## Turns off the named attributes without affecting any other attributes.
  240. ## @Param: 'attributes' the attributes to turn off for the current window.
  241. ## @Returns: An integer value, but the returned value does not have any meaning and can
  242. ## thus be ignored.
  243. proc wattroff*(win: PWindow, attrs: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  244. proc attron*(attrs: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  245. ## Turns on the named attributes without affecting any other attributes.
  246. ## @Param: 'attributes' the attributes to turn on for the current window.
  247. ## @Returns: An integer value, but the returned value does not have any meaning and can
  248. ## thus be ignored.
  249. proc wattron*(win: PWindow, attrs: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  250. proc attrset*(attrs: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  251. ## Sets the current attributes of the given window to the provided attributes.
  252. ## @Param: 'attributes', the attributes to apply to the current window.
  253. ## @Returns: An integer value, but the returned value does not have any meaning and can
  254. ## thus be ignored.
  255. proc wattrset*(win: PWindow, attrs: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  256. proc chgat*(n: cint, attr: attr_t, pair: cshort, opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  257. proc wchgat*(win: PWindow, n: cint, attr: attr_t, pair: cshort, opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  258. proc mvchgat*(y, x: cint, n: cint, attr: attr_t, pair: cshort, opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  259. proc mvwchgat*(win: PWindow, y, x: cint, n: cint, attr: attr_t, pair: cshort, opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  260. proc color_set*(pair: cshort, opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  261. proc wcolor_set*(win: PWindow, pair: cshort, opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  262. #proc standend(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.} ## Not used?
  263. proc wstandend*(win: PWindow): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  264. proc standout*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  265. proc wstandout*(win: PWindow): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  266. #termattrs: Enviroment query routines
  267. proc baudrate*(): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  268. proc erasechar*() {.cdecl, importc, discardable, dynlib: libncurses.}
  269. proc erasewchar*(ch: WideCString) {.cdecl, importc, discardable, dynlib: libncurses.}
  270. proc has_ic*(): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  271. proc has_il*(): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  272. proc killchar*(): cchar {.cdecl, importc, discardable, dynlib: libncurses.}
  273. proc killwchar*(ch: WideCString): cchar {.cdecl, importc, discardable, dynlib: libncurses.}
  274. proc longname*(): cstring {.cdecl, importc, discardable, dynlib: libncurses.}
  275. proc term_attrs*(): attr_t {.cdecl, importc, discardable, dynlib: libncurses.}
  276. proc term_attrs_ch*(): chtype {.cdecl, importc: "termattrs", discardable, dynlib: libncurses.} ## Previously termattrs
  277. proc termname*(): cstring {.cdecl, importc, discardable, dynlib: libncurses.}
  278. #beep: Bell and screen flash routines
  279. proc beep*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  280. proc flash*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  281. ## Flashes the screen and if that is not possible it sounds the alert. If this is not possible
  282. ## nothing happens.
  283. ## @Returns: ERR on failure and OK upon successfully flashing.
  284. #bkgd: Window background manipulation routines
  285. proc bkgdset*(ch: chtype): void {.cdecl, importc, discardable, dynlib: libncurses.}
  286. proc wbkgdset*(win: PWindow, ch: chtype): void {.cdecl, importc, discardable, dynlib: libncurses.}
  287. proc bkgd*(ch: chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  288. ## Sets the background property of the current window and apply this setting to every
  289. ## character position in the window.
  290. ## @Param: 'background' the background property to apply.
  291. proc wbkgd*(win: PWindow, ch: chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  292. proc getbkgd*(win: PWindow): chtype {.cdecl, importc, discardable, dynlib: libncurses.}
  293. #bkgrnd: Window complex background manipulation routines
  294. proc bkgrnd*(wch: cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  295. proc wbkgrnd*(win: PWindow, wch: cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  296. proc bkgrndset*(wch: cchar_t): void {.cdecl, importc, discardable, dynlib: libncurses.}
  297. proc wbkgrndset*(win: PWindow, wch: cchar_t): void {.cdecl, importc, discardable, dynlib: libncurses.}
  298. proc getbkgrnd*(wch: cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  299. proc wgetbkgrnd*(win: PWindow, wch: cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  300. #border: Create borders, horizontal and vertical lines
  301. proc border*(ls, rs, ts, bs, tl, tr, bl, br: chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  302. proc wborder*(win: PWindow, ls, rs, ts, bs, tl, tr, bl, br: chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  303. proc box*(win: PWindow, verch, horch: chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  304. proc hline*(ch: chtype, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  305. proc whline*(win: PWindow, ch: chtype, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  306. proc vline*(ch: chtype, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  307. proc wvline*(win: PWindow, ch: chtype, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  308. proc mvhline*(y, x: cint, ch: chtype, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  309. proc mvwhline*(win: PWindow, y, x: cint, ch: chtype, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  310. proc mvvline*(y, x: cint, ch: chtype, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  311. proc mvwvline*(win: PWindow, y, x: cint, ch: chtype, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  312. #borderset: Create borders or lines using complex characters and renditions
  313. proc border_set*(ls, rs, ts, bs, tl, tr, bl, br: cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  314. proc wborder_set*(win: PWindow, ls, rs, ts, bs, tl, tr, bl, br: cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  315. proc box_set*(win: PWindow, verch, horch: cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  316. proc hline_set*(wch: cchar_t, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  317. proc whline_set*(win: PWindow, wch: cchar_t, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  318. proc mvhline_set*(y,x: cint, wch: cchar_t, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  319. proc mvwhline_set*(win: PWindow, y,x: cint, wch: cchar_t, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  320. proc vline_set*(wch: cchar_t, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  321. proc wvline_set*(win: PWindow, wch: cchar_t, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  322. proc mvvline_set*(y,x: cint, wch: cchar_t, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  323. proc mvwvline_set*(win: PWindow, y,x: cint, wch: cchar_t, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  324. #inopts: Input options
  325. proc cbreak*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  326. ## The cbreak routine disables line buffering and erase/kill character-processing
  327. ## (interrupt and flow control characters are unaffected), making characters typed by
  328. ## the user immediately available to the program.
  329. ## @Returns: ERR on failure and OK upon successful completion.
  330. proc nocbreak*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  331. ## Returns the terminal to normal (cooked mode).
  332. ## @Returns: ERR on failure and OK upon successful completion.
  333. proc noecho*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  334. proc onecho*(): ErrCode {.cdecl, discardable, dynlib: libncurses, importc: "echo".} ## Previously echo
  335. proc halfdelay*(tenths: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  336. proc keypad*(win: PWindow, bf: bool): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  337. proc meta*(win: PWindow, bf: bool): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  338. proc nodelay*(win: PWindow, bf: bool): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  339. proc raw*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  340. proc noraw*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  341. proc noqiflush*(): void {.cdecl, importc, discardable, dynlib: libncurses.}
  342. proc qiflush*(): void {.cdecl, importc, discardable, dynlib: libncurses.}
  343. proc notimeout*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  344. proc timeout*(delay: cint): void {.cdecl, importc, discardable, dynlib: libncurses.}
  345. proc wtimeout*(win: PWindow, delay: cint): void {.cdecl, importc, discardable, dynlib: libncurses.}
  346. proc typeahead*(fd: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  347. #clear: Clear all or part of a window
  348. proc erase*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  349. proc werase*(win: PWindow): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  350. proc clear*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  351. proc wclear*(win: PWindow): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  352. proc clrtobot*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  353. proc wclrtobot*(win: PWindow): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  354. proc clrtoeol*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  355. proc wclrtoeol*(win: PWindow): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  356. #outopts: Output options
  357. proc clearok*(win: PWindow, bf: bool): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  358. proc idlok*(win: PWindow, bf: bool): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  359. proc idcok*(win: PWindow, bf: bool): void {.cdecl, importc, discardable, dynlib: libncurses.}
  360. proc immedok*(win: PWindow, bf: bool): void {.cdecl, importc, discardable, dynlib: libncurses.}
  361. proc leaveok*(win: PWindow, bf: bool): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  362. proc setscrreg*(top, bot: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  363. proc wsetscrreg*(win: PWindow, top, bot: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  364. proc scrollok*(win: PWindow, bf: bool): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  365. proc nl*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  366. proc nonl*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  367. #overlay: overlay and manipulate overlapped windows
  368. proc overlay*(srcwin, dstwin: PWindow): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  369. proc overwrite*(srcwin, dstwin: PWindow): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  370. proc copywin*(srcwin, dstwin: PWindow,
  371. sminrow, smincol,
  372. dminrow, dmincol,
  373. dmaxrow, dmaxcol: cint
  374. ): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  375. #kernel: low-level routines (all except cur_set will always return OK)
  376. proc def_prog_mode*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  377. proc def_shell_mode*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  378. proc reset_prog_mode*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  379. proc reset_shell_mode*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  380. proc resetty*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  381. proc savetty*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  382. proc getsyx*(y,x: cint): void {.cdecl, importc, discardable, dynlib: libncurses.}
  383. proc setsyx*(y,x: cint): void {.cdecl, importc, discardable, dynlib: libncurses.}
  384. proc ripoffline*(line: cint, init: proc(win: PWindow, cols: cint): cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  385. proc curs_set*(visibility: cint): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  386. proc napms*(ms: cint): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  387. ## Used to sleep for the specified milliseconds.
  388. ## @Params: 'milliseconds' the number of milliseconds to sleep for.
  389. ## @Returns: ERR on failure and OK upon successful completion.
  390. #extend: misc extensions
  391. proc curses_version*(): cstring {.cdecl, importc, discardable, dynlib: libncurses.}
  392. proc use_extended_names*(enable: bool): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  393. #define_key: define a keycode
  394. proc define_key*(definition: cstring, keycode: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  395. #terminfo: interfaces to terminfo database
  396. var
  397. cur_term*: ptr Terminal
  398. boolnames*, boolcodes*, boolfnames*: cstringArray
  399. numnames*, numcodes*, numfnames*: cstringArray
  400. strnames*, strcodes*, strfnames*: cstringArray
  401. proc setupterm*(term: cstring; filedes: cint; errret: ptr cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  402. proc setterm*(term: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  403. proc set_curterm*(nterm: ptr Terminal): ptr Terminal {.cdecl, importc, discardable, dynlib: libncurses.}
  404. proc del_curterm*(oterm: ptr Terminal): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  405. proc restartterm*(term: cstring; filedes: cint; errret: ptr cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  406. proc tparm*(str: cstring): cstring {.varargs, cdecl, importc, discardable, dynlib: libncurses.}
  407. proc putp*(str: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  408. proc vid_puts_ch*(attrs: chtype; putc: proc(ch: cint): cint): ErrCode {.cdecl, importc: "vidputs", discardable, dynlib: libncurses.}
  409. proc vid_attr_ch*(attrs: chtype): ErrCode {.cdecl, importc: "vidattr", discardable, dynlib: libncurses.}
  410. proc vid_puts*(attrs: attr_t; pair: cshort; opts: pointer; putc: proc(ch: cint): cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  411. proc vid_attr*(attrs: attr_t; pair: cshort; opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  412. proc mvcur*(oldrow, oldcol, newrow, newcol: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  413. proc tigetflag*(capname: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  414. proc tigetnum*(capname: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  415. proc tigetstr*(capname: cstring): cstring {.cdecl, importc, discardable, dynlib: libncurses.}
  416. proc tiparm*(str: cstring): cstring {.varargs, cdecl, importc, discardable, dynlib: libncurses.}
  417. #util: misc utility routines
  418. proc unctrl*(c: chtype): cstring {.cdecl, importc, discardable, dynlib: libncurses.}
  419. proc wunctrl*(c: ptr cchar_t): WideCString {.cdecl, importc, discardable, dynlib: libncurses.}
  420. proc keyname*(c: cint): cstring {.cdecl, importc, discardable, dynlib: libncurses.}
  421. proc keyname_wch*(w: WideCString): cstring {.cdecl, discardable, dynlib: libncurses, importc: "key_name".} ## previously key_name, had to be renamed.
  422. proc filter*(): void {.cdecl, importc, discardable, dynlib: libncurses.}
  423. proc nofilter*(): void {.cdecl, importc, discardable, dynlib: libncurses.}
  424. proc use_env*(f: bool): void {.cdecl, importc, discardable, dynlib: libncurses.}
  425. proc use_tioctl*(f: bool): void {.cdecl, importc, discardable, dynlib: libncurses.}
  426. proc putwin*(win: PWindow, filep: File): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  427. proc getwin*(filep: File): PWindow {.cdecl, importc, discardable, dynlib: libncurses.}
  428. proc delay_output*(ms: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  429. proc flushinp*(): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  430. #delch: delete character under the cursor in a window
  431. proc delch*(): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  432. ## Delete the character under the cursor in the stdscr.
  433. ## @Returns: ERR on failure and OK upon successfully flashing.
  434. proc wdelch*(win: PWindow): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  435. proc mvdelch*(y,x: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  436. proc mvwdelch*(win: PWindow, y,x: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  437. #deleteln: delete and insert lines in a window
  438. proc deleteln*(): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  439. ## Deletes the line under the cursor in the stdscr. All lines below the current line are moved up one line.
  440. ## The bottom line of the window is cleared and the cursor position does not change.
  441. ## @Returns: ERR on failure and OK upon successful completion.
  442. proc wdeleteln*(win: PWindow): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  443. proc insdeln*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  444. proc winsdeln*(win: PWindow, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  445. proc insertln*(): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  446. ## Inserts a blank line above the current line in stdscr and the bottom line is lost.
  447. ## @Returns: ERR on failure and OK upon successful completion.
  448. proc winsertln*(win: PWindow): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  449. #initscr: screen initialization and manipulation routines
  450. proc initscr*(): PWindow {.cdecl, importc, discardable, dynlib: libncurses.}
  451. ## Usually the first curses routine to be called when initialising a program
  452. ## The initscr code determines the terminal type and initialises all curses data structures. initscr also causes the
  453. ## first call to refresh to clear the screen.
  454. ## @Returns: A pointer to stdscr is returned if the operation is successful.
  455. ## @Note: If errors occur, initscr writes an appropriate error message to
  456. ## standard error and exits.
  457. proc endwin*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  458. ## A program should always call endwin before exiting or escaping from curses mode temporarily. This routine
  459. ## restores tty modes, moves the cursor to the lower left-hand corner of the screen and resets the terminal into the
  460. ## proper non-visual mode. Calling refresh or doupdate after a temporary escape causes the program to resume visual mode.
  461. ## @Returns: ERR on failure and OK upon successful completion.
  462. proc isendwin*(): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  463. proc newterm*(`type`: cstring, outfd, infd: File): PScreen {.cdecl, importc, discardable, dynlib: libncurses.}
  464. proc set_term*(`new`: PScreen): PScreen {.cdecl, importc, discardable, dynlib: libncurses.}
  465. proc delscreen*(sp: PScreen): void {.cdecl, importc, discardable, dynlib: libncurses.}
  466. #window: create a window
  467. proc newwin*(nlines, ncols, begin_y, begin_x: cint): PWindow {.cdecl, importc, discardable, dynlib: libncurses.}
  468. proc delwin*(win: PWindow): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  469. proc mvwin*(win: PWindow, y,x: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  470. proc subwin*(orig: PWindow, nlines, ncols, begin_y, begin_x: cint): PWindow {.cdecl, importc, discardable, dynlib: libncurses.}
  471. proc derwin*(orig: PWindow, nlines, ncols, begin_y, begin_x: cint): PWindow {.cdecl, importc, discardable, dynlib: libncurses.}
  472. proc mvderwin*(win: PWindow, par_y, par_x: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  473. proc dupwin*(win: PWindow): PWindow {.cdecl, importc, discardable, dynlib: libncurses.}
  474. proc wsyncup*(win: PWindow): void {.cdecl, importc, discardable, dynlib: libncurses.}
  475. proc syncok*(win: PWindow, bf: bool): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  476. proc wcursyncup*(win: PWindow): void {.cdecl, importc, discardable, dynlib: libncurses.}
  477. proc wsyncdown*(win: PWindow): void {.cdecl, importc, discardable, dynlib: libncurses.}
  478. #refresh: refresh windows and lines
  479. proc refresh*(): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  480. ## Must be called to get actual output to the terminal. refresh uses stdscr has the default window.
  481. ## @Returns: ERR on failure and OK upon successful completion.
  482. proc wrefresh*(win: PWindow): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  483. proc wnoutrefresh*(win: PWindow): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  484. proc doupdate*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  485. proc redrawwin*(win: PWindow): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  486. proc wredrawln*(win: PWindow, beg_lines, num_lines: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  487. #slk: soft label routines
  488. proc slk_init*(fmt: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  489. proc slk_set*(labnum: cint, label: WideCString, fmt: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  490. proc slk_wset*(labnum: cint, label: WideCString, fmt: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  491. proc slk_label*(labnum: cint): cstring {.cdecl, importc, discardable, dynlib: libncurses.}
  492. proc slk_refresh*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  493. proc slk_noutrefresh*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  494. proc slk_clear*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  495. proc slk_restore*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  496. proc slk_touch*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  497. proc slk_attron_ch*(attrs: chtype): ErrCode {.cdecl, importc: "slk_attron", discardable, dynlib: libncurses.} ## Previously slk_attron
  498. proc slk_attroff_ch*(attrs: chtype): ErrCode {.cdecl, importc: "slk_attroff", discardable, dynlib: libncurses.} ## Previously slk_attroff
  499. proc slk_attrset_ch*(attrs: chtype): ErrCode {.cdecl, importc: "slk_attrset", discardable, dynlib: libncurses.} ## Previously slk_attrset
  500. proc slk_attr_on*(attrs: attr_t, opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  501. proc slk_attr_off*(attrs: attr_t, opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  502. proc slk_attr_set*(attrs: attr_t, pair: cshort, opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  503. proc slk_attr*(): attr_t {.cdecl, importc, discardable, dynlib: libncurses.}
  504. proc slk_color*(pair: cshort): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  505. proc extended_slk_color*(pair: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  506. #get_wch: get (or push back) a wide character from a terminal keyboard
  507. proc get_wch*(wch: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  508. proc wget_wch*(win: PWindow, wch: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  509. proc mvget_wch*(y,x: cint, wch: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  510. proc mvwget_wch*(win: PWindow, y,x: cint, wch: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  511. proc unget_wch*(wch: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  512. #get_wstr: get an array of wide characters from a terminal keyboard
  513. proc get_wstr*(wstr: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  514. proc getn_wstr*(wstr: WideCString, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  515. proc wget_wstr*(win: PWindow, wstr: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  516. proc wgetn_wstr*(win: PWindow, wstr: WideCString, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  517. proc mvget_wstr*(y,x: cint, wstr: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  518. proc mvgetn_wstr*(y,x: cint, wstr: WideCString, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  519. proc mvwget_wstr*(win: PWindow, y,x: cint, wstr: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  520. proc mvwgetn_wstr*(win: PWindow, y,x: cint, wstr: WideCString, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  521. #legacy: get cursor and window coordinates, attributes
  522. proc getattrs*(win: PWindow): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  523. proc getbegx*(win: PWindow): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  524. proc getbegy*(win: PWindow): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  525. proc getcurx*(win: PWindow): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  526. proc getcury*(win: PWindow): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  527. proc getmaxx*(win: PWindow): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  528. proc getmaxy*(win: PWindow): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  529. proc getparx*(win: PWindow): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  530. proc getpary*(win: PWindow): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  531. #getyx: get curses cursor and window coordinates (these are implemented as macros in ncurses.h)
  532. template getyx*(win: PWindow, y, x: cint): untyped=
  533. ## Reads the logical cursor location from the specified window.
  534. ## @Param: 'win' the window to get the cursor location from.
  535. ## @Param: 'y' stores the height of the window.
  536. ## @Param: 'x' stores the width of the window.
  537. (y = getcury(win); x = getcurx(win)) ## testing
  538. template getbegyx*(win: PWindow, y, x: cint): untyped=
  539. (y = getbegy(win); x = getbegx(win))
  540. template getmaxyx*(win: PWindow, y, x: cint): untyped=
  541. ## retrieves the size of the specified window in the provided y and x parameters.
  542. ## @Param: 'win' the window to measure.
  543. ## @Param: 'y' stores the height of the window.
  544. ## @Param: 'x' stores the width of the window.
  545. (y = getmaxy(win); x = getmaxx(win))
  546. template getparyx*(win: PWindow, y, x: cint): untyped=
  547. (y = getpary(win); x = getparx(win))
  548. #getcchar: Get a wide character string and rendition from cchar_t or set a cchar_t from a wide-character string
  549. proc getcchar*(wcval: ptr cchar_t, wch: WideCString, attrs: ptr attr_t, color_pair: ptr cshort, opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  550. proc setcchar*(wcval: ptr cchar_t, wch: WideCString, attrs: attr_t, color_pair: cshort, opts: pointer): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  551. #getch: get (or push back) characters from the terminal keyboard
  552. proc getch*(): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  553. ## Read a character from the stdscr window.
  554. ## @Returns: ERR on failure and OK upon successful completion.
  555. proc wgetch*(win: PWindow): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  556. ## Read a character from the specified window.
  557. ## @Param: 'sourceWindow' the window to read a character from.
  558. ## @Returns: ERR on failure and OK upon successful completion.
  559. proc mvgetch*(y,x: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  560. proc mvwgetch*(win: PWindow, y,x: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  561. proc ungetch*(ch: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  562. proc has_key*(ch: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  563. #mouse: mouse interface
  564. proc has_mouse*(): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  565. proc getmouse*(event: ptr Mevent): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  566. proc ungetmouse*(event: ptr Mevent): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  567. proc mousemask*(newmask: mmask_t, oldmask: ptr mmask_t): mmask_t {.cdecl, importc, discardable, dynlib: libncurses.}
  568. proc wenclose*(win: PWindow, y, x: cint): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  569. proc mouse_trafo*(y,x: ptr cint, to_screen: bool): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  570. proc wmouse_trafo*(win: PWindow, y,x: ptr cint, to_screen: bool): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  571. proc mouseinterval*(erval: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  572. #getstr: accept character strings from terminal keyboard
  573. proc getstr*(str: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  574. ## Reads the inputted characters into the provided string.
  575. ## @Param: 'inputString' the variable to read the input into.
  576. ## @Returns: ERR on failure and OK upon successful completion.
  577. proc getnstr*(str: cstring; n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  578. ## Reads at most the specified number of characters into the provided string.
  579. ## @Param: 'inputString' the variable to read the input into.
  580. ## @Param: 'numberOfCharacters' the maximum number of characters to read.
  581. ## @Returns: ERR on failure and OK upon successful completion.
  582. proc wgetstr*(win: PWindow, str: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  583. proc wgetnstr*(win: PWindow, str: cstring, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  584. proc mvgetstr*(y,x: cint, str: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  585. proc mvgetnstr*(y,x: cint, str: cstring, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  586. proc mvwgetstr*(win: PWindow, y,x: cint, str: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  587. proc mvwgetnstr*(win: PWindow, y,x: cint, str: cstring, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  588. #in_wch: extract a complex character and rendition from a window
  589. proc in_wch*(wcval: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  590. proc mvinwch*(y,x: cint, wcval: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  591. proc mvwin_wch*(win: PWindow, y,x: cint, wcval: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  592. proc win_wch*(win: PWindow, wcval: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  593. #in_wchstr: get an array of complex characters and renditions from a window
  594. proc in_wchstr*(wchstr: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  595. proc in_wchnstr*(wchstr: ptr cchar_t, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  596. proc win_wchstr*(win: PWindow, wchstr: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  597. proc win_wchnstr*(win: PWindow, wchstr: ptr cchar_t, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  598. proc mvin_wchstr*(y,x: cint, wchstr: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  599. proc mvin_wchnstr*(y,x: cint, wchstr: ptr cchar_t, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  600. proc mvwin_wchstr*(win: PWindow, y,x: cint, wchstr: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  601. proc mvwin_wchnstr*(win: PWindow; y,x: cint, wchstr: ptr cchar_t, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  602. #inch: get a character and attributes from a window
  603. proc inch*(): chtype {.cdecl, importc, discardable, dynlib: libncurses.}
  604. proc winch*(win: PWindow): chtype {.cdecl, importc, discardable, dynlib: libncurses.}
  605. proc mvinch*(y,x: cint): chtype {.cdecl, importc, discardable, dynlib: libncurses.}
  606. proc mvwinch*(win: PWindow; y,x: cint): chtype {.cdecl, importc, discardable, dynlib: libncurses.}
  607. #inchstr: get a string of characters (and attributes) from a window
  608. proc inchstr*(chstr: ptr chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  609. proc inchnstr*(chstr: ptr chtype; n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  610. proc winchstr*(win: PWindow; chstr: ptr chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  611. proc winchnstr*(win: PWindow; chstr: ptr chtype; n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  612. proc mvinchstr*(y,x: cint; chstr: ptr chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  613. proc mvinchnstr*(y,x: cint; chstr: ptr chtype; n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  614. proc mvwinchstr*(win: PWindow, y,x: cint; chstr: ptr chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  615. proc mvwinchnstr*(win: PWindow, y,x: cint; chstr: ptr chtype; n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  616. #instr: get a string of characters from a window
  617. proc instr*(str: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  618. proc innstr*(str: cstring, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  619. proc winstr*(win: PWindow, str: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  620. proc winnstr*(win: PWindow, str: cstring, n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  621. proc mvinstr*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  622. proc mvinnstr*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  623. proc mvwinstr*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  624. proc mvwinnstr*(): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  625. #inwstr: get a string of wchar_t characters from a window
  626. proc inwstr*(wstr: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  627. proc innwstr*(wstr: WideCString; n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  628. proc winwstr*(win: PWindow; wstr: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  629. proc winnwstr*(win: PWindow; wstr: WideCString; n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  630. proc mvinwstr*(y,x: cint; wstr: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  631. proc mvinnwstr*(y,x: cint; wstr: WideCString; n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  632. proc mvwinwstr*(win: PWindow; y,x: cint; wstr: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  633. proc mvwinnwstr*(win: PWindow; y,x: cint; wstr: WideCString; n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  634. #ins_wstr: insert a wide-character string into a window
  635. proc ins_wstr*(wstr: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  636. proc ins_nwstr*(wstr: WideCString; n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  637. proc wins_wstr*(win: PWindow; wstr: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  638. proc wins_nwstr*(win: PWindow; wstr: WideCString; n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  639. proc mvins_wstr*(y,x: cint; wstr: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  640. proc mvins_nwstr*(y,x: cint; wstr: WideCString; n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  641. proc mvwins_wstr*(win: PWindow; y,x: cint; wstr: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  642. proc mvwins_nwstr*(win: PWindow; y,x: cint; wstr: WideCString; n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  643. #ins_wch: insert a complex character and rendition into a window
  644. proc ins_wch*(wch: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  645. proc wins_wch*(win: PWindow; wch: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  646. proc mvins_wch*(y,x: cint; wch: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  647. proc mvwins_wch*(win: PWindow; y,x: cint; wch: ptr cchar_t): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  648. #insch: insert a character before cursor in a window
  649. proc insch*(ch: chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  650. ## Inserts a character before the cursor in the stdscr.
  651. ## @Param: 'character' the character to insert.
  652. ## @Returns: ERR on failure and OK upon successful completion.
  653. proc winsch*(win: PWindow; ch: chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  654. proc mvinsch*(y,x: cint; ch: chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  655. proc mvwinsch*(win: PWindow; y,x: cint; ch: chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  656. #insstr: insert string before cursor in a window
  657. proc insstr*(str: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  658. proc insnstr*(str: cstring; n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  659. proc winsstr*(win: PWindow; str: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  660. proc winsnstr*(win: PWindow; str: cstring; n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  661. proc mvinsstr*(y,x: cint; str: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  662. proc mvinsnstr*(y,x: cint; str: cstring; n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  663. proc mvwinsstr*(win: Pwindow; y,x: cint; str: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  664. proc mvwinsnstr*(win: Pwindow; y,x: cint; str: cstring; n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  665. #opaque: window properties
  666. proc is_cleared*(win: PWindow): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  667. ## returns the value set in clearok
  668. proc is_idcok*(win: PWindow): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  669. ## returns the value set in is_idcok
  670. proc is_idlok*(win: PWindow): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  671. ## returns the value set in is_idlok
  672. proc is_immedok*(win: PWindow): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  673. ## returns the value set in is_immedok
  674. proc is_keypad*(win: PWindow): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  675. ## returns the value set in is_keypad
  676. proc is_leaveok*(win: PWindow): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  677. ## returns the value set in is_leaveok
  678. proc is_nodelay*(win: PWindow): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  679. ## returns the value set in is_nodelay
  680. proc is_notimeout*(win: PWindow): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  681. ## returns the value set in is_notimeout
  682. proc is_pad*(win: PWindow): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  683. ## returns TRUE if the window is a pad i.e., created by newpad
  684. proc is_scrollok*(win: PWindow): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  685. ## returns the value set in is_scrollok
  686. proc is_subwin*(win: PWindow): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  687. ## returns TRUE if the window is a subwindow, i.e., created by subwin
  688. ## or derwin
  689. proc is_syncok*(win: PWindow): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  690. ## returns the value set in is_syncok
  691. proc wgetparent*(win: PWindow): PWindow {.cdecl, importc, discardable, dynlib: libncurses.}
  692. ## returns the parent WINDOW pointer for subwindows, or NULL for
  693. ## windows with no parent
  694. proc wgetdelay*(win: PWindow): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  695. ## returns the delay timeout as set in wtimeout
  696. proc wgetscrreg*(win: PWindow; top, bottom: cint): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  697. ## returns the top and bottom rows for the scrolling margin as set in
  698. ## wsetscrreg
  699. #touch: refresh control routines
  700. proc touchwin*(win: PWindow): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  701. ## Throws away all optimization information about which parts of the window
  702. ## have been touched, by pretending that the entire window has been drawn on.
  703. ## This is sometimes necessary when using overlapping windows, since a change
  704. ## to one window affects the other window, but the records of which lines
  705. ## have been changed in the other window do not reflect the change.
  706. proc touchline*(win: PWindow; start, count: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  707. ## The same as touchwin, except it only pretends that count lines have been
  708. ## changed, beginning with line start.
  709. proc untouchwin*(win: PWindow): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  710. ## Marks all lines in the window as unchanged since the last call to wrefresh.
  711. proc wtouchln*(win: PWindow; y, n, changed: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  712. ## Makes n lines in the window, starting at line y, look as if they have
  713. ## (changed=1) or have not (changed=0) been changed since the last call to
  714. ## wrefresh.
  715. proc is_wintouched*(win: PWindow): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  716. ## Returns TRUE if the specified window was modified since the last call to
  717. ## wrefresh
  718. proc is_linetouched*(win: PWindow; line: cint): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  719. ## The same as is_wintouched, In addition, returns ERR if line is not valid
  720. ## for the given window.
  721. #resizeterm: change the curses terminal size
  722. proc is_term_resized*(lines, columns: cint): bool {.cdecl, importc, discardable, dynlib: libncurses.}
  723. ## Checks if the resize_term function would modify the window structures.
  724. ## returns TRUE if the windows would be modified, and FALSE otherwise.
  725. proc resize_term*(lines, columns: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  726. ## Resizes the standard and current windows to the specified dimensions,
  727. ## and adjusts other bookkeeping data used by the ncurses library that
  728. ## record the window dimensions such as the LINES and COLS variables.
  729. proc resize_term_ext*(lines, columns: cint): ErrCode {.cdecl, discardable, dynlib: libncurses, importc: "resize_term".}
  730. ## Blank-fills the areas that are extended. The calling application should
  731. ## fill in these areas with appropriate data. The resize_term function
  732. ## attempts to resize all windows. However, due to the calling convention of
  733. ## pads, it is not possible to resize these without additional interaction
  734. ## with the application.
  735. #key_defined: check if a keycode is defined
  736. proc key_defined*(definition: cstring): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  737. ## If the string is bound to a keycode, its value (greater than zero) is
  738. ## returned. If no keycode is bound, zero is returned. If the string
  739. ## conflicts with longer strings which are bound to keys, -1 is returned.
  740. #keybound: return definition of keycode
  741. proc keybound*(keycode, count: cint): cstring {.cdecl, importc, discardable, dynlib: libncurses.}
  742. ## The keycode parameter must be greater than zero, else NULL is returned.
  743. ## If it does not correspond to a defined key, then NULL is returned. The
  744. ## count parameter is used to allow the application to iterate through
  745. ## multiple definitions, counting from zero. When successful, the function
  746. ## returns a string which must be freed by the caller.
  747. #keyok: enable or disable a keycode
  748. #[
  749. proc keyok(keycode: cint; enable: bool): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.} ## Not used?
  750. ## The keycode must be greater than zero, else ERR is returned. If it
  751. ## does not correspond to a defined key, then ERR is returned. If the
  752. ## enable parameter is true, then the key must have been disabled, and
  753. ## vice versa. Otherwise, the function returns OK.
  754. ]#
  755. #mcprint: ship binary data to printer
  756. proc mcprint*(data: cstring; len: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  757. #move: move window cursor
  758. proc move*(y, x: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  759. ## Moves the cursor of stdscr to the specified coordinates.
  760. ## @Param: 'y' the line to move the cursor to.
  761. ## @Param: 'x' the column to move the cursor to.
  762. ## @Returns: ERR on failure and OK upon successful completion.
  763. proc wmove*(win: PWindow; y,x: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  764. #printw: print formatted output in windows
  765. proc printw*(fmt: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses, varargs.}
  766. ## Prints out a formatted string to the stdscr.
  767. ## @Param: 'formattedString' the string with formatting to be output to stdscr.
  768. ## @Returns: ERR on failure and OK upon successful completion.
  769. proc wprintw*(win: PWindow, fmt: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  770. proc mvprintw*(y, x: cint; fmt: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses, varargs.}
  771. ## Prints out a formatted string to the stdscr at the specified row and column.
  772. ## @Param: 'y' the line to move the cursor to.
  773. ## @Param: 'x' the column to move the cursor to.
  774. ## @Param: 'formattedString' the string with formatting to be output to stdscr.
  775. ## @Returns: ERR on failure and OK upon successful completion.
  776. proc mvwprintw*(win: PWindow; y,x: cint; fmt: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses, varargs.}
  777. ## Prints out a formatted string to the specified window at the specified row and column.
  778. ## @Param: 'destinationWindow' the window to write the string to.
  779. ## @Param: 'y' the line to move the cursor to.
  780. ## @Param: 'x' the column to move the cursor to.
  781. ## @Param: 'formattedString' the string with formatting to be output to stdscr.
  782. ## @Returns: ERR on failure and OK upon successful completion.
  783. proc vw_printw*(win: PWindow; fmt: cstring; varglist: varargs[cstring]): ErrCode {.cdecl, importc, discardable, dynlib: libncurses}
  784. #scanw: convert formatted input from a window
  785. proc scanw*(fmt: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses, varargs.}
  786. ## Converts formatted input from the stdscr.
  787. ## @Param: 'formattedInput' Contains the fields for the input to be mapped to.
  788. ## @Returns: The number of fields that were mapped in the call.
  789. proc wscanw*(win: PWindow; fmt: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses, varargs.}
  790. proc mvscanw*(y,x: cint; fmt: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses, varargs.}
  791. proc mvwscanw*(win: PWindow; y,x: cint; fmt: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses, varargs.}
  792. proc vw_scanw*(win: PWindow; fmt: cstring; varglist: varargs[cstring]): ErrCode {.cdecl, importc, discardable, dynlib: libncurses, varargs,.}
  793. #pad: create and display pads
  794. proc newpad*(nlines, ncols: cint): PWindow {.cdecl, importc, discardable, dynlib: libncurses.}
  795. proc subpad*(orig: PWindow; lines, columns, begin_y, begin_x: cint): PWindow {.cdecl, importc, discardable, dynlib: libncurses.}
  796. proc prefresh*(pad: PWindow;
  797. pminrow, pmincol,
  798. sminrow, smincol,
  799. smaxrow, smaxcol: cint
  800. ): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  801. proc pnoutrefersh*(pad: PWindow;
  802. pminrow, pmincol,
  803. sminrow, smincol,
  804. smaxrow, smaxcol: cint
  805. ): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  806. proc pechochar*(pad: PWindow; ch: chtype): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  807. proc pecho_wchar*(pad: PWindow; wch: WideCString): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  808. #scr_dump: read (write) a screen from (to) a file
  809. proc scr_dump*(filename: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  810. proc scr_restore*(filename: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  811. proc scr_init*(filename: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  812. proc scr_set*(filename: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  813. #scroll: scroll a window
  814. proc scroll*(win: PWindow): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  815. proc scrl*(n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  816. proc wscrl*(win: PWindow; n: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  817. #termcap: direct interface to the terminfo capability database
  818. var
  819. PC* {.importc, dynlib: libncurses.}: cchar
  820. ## Set by tgetent to the terminfo entry's pad_char value.
  821. ## Used in the tdelay_output function.
  822. UP* {.importc, dynlib: libncurses.}: ptr cchar
  823. ## Set by tgetent to the terminfo entry's cursor_up value.
  824. ## Not used by ncurses.
  825. BC* {.importc, dynlib: libncurses.}: ptr cchar
  826. ## Set by tgetent to the terminfo entry's backspace_if_not_bs value.
  827. ## Used in the tgoto() emulation.
  828. ospeed* {.importc, dynlib: libncurses.}: cshort
  829. ## Set by ncurses in a system-specific coding to reflect the terminal speed.
  830. proc tgetent*(np, name: cstring): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  831. proc tgetflag*(id: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  832. proc tgetnum*(id: cstring): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  833. proc tgetstr*(id: cstring; area: cstringArray ): cstring {.cdecl, importc, discardable, dynlib: libncurses.}
  834. proc tgoto*(cap: cstring; col, row: cint): cstring {.cdecl, importc, discardable, dynlib: libncurses.}
  835. proc tputs*(str: cstring; affcnt: cint; putc: ptr proc(ch: cint): cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  836. #legacy_coding: override locale-encoding checks
  837. proc use_legacy_coding*(level: cint): cint {.cdecl, importc, discardable, dynlib: libncurses.}
  838. ## If the screen has not been initialized, or the level parameter is out
  839. ## of range, the function returns ERR. Otherwise, it returns the previous
  840. ## level: 0, 1 or 2.
  841. #wresize: resize a curses window
  842. proc wresize*(win: PWindow; line, column: cint): ErrCode {.cdecl, importc, discardable, dynlib: libncurses.}
  843. # mouse interface
  844. template NCURSES_MOUSE_MASK(b, m: untyped): untyped = ((m) shl (((b) - 1) * 5))
  845. template BUTTON_RELEASE*(e, x: untyped): untyped =
  846. ((e) and NCURSES_MOUSE_MASK(x, NCURSES_BUTTON_RELEASED))
  847. template BUTTON_PRESS*(e, x: untyped): untyped =
  848. ((e) and NCURSES_MOUSE_MASK(x, NCURSES_BUTTON_PRESSED))
  849. template BUTTON_CLICK*(e, x: untyped): untyped =
  850. ((e) and NCURSES_MOUSE_MASK(x, NCURSES_BUTTON_CLICKED))
  851. template BUTTON_DOUBLE_CLICK*(e, x: untyped): untyped =
  852. ((e) and NCURSES_MOUSE_MASK(x, NCURSES_DOUBLE_CLICKED))
  853. template BUTTON_TRIPLE_CLICK*(e, x: untyped): untyped =
  854. ((e) and NCURSES_MOUSE_MASK(x, NCURSES_TRIPLE_CLICKED))
  855. template BUTTON_RESERVED_EVENT*(e, x: untyped): untyped =
  856. ((e) and NCURSES_MOUSE_MASK(x, NCURSES_RESERVED_EVENT))
  857. const
  858. NCURSES_BUTTON_RELEASED* = 0o01'i32
  859. NCURSES_BUTTON_PRESSED* = 0o02'i32
  860. NCURSES_BUTTON_CLICKED* = 0o04'i32
  861. NCURSES_DOUBLE_CLICKED* = 0o10'i32
  862. NCURSES_TRIPLE_CLICKED* = 0o20'i32
  863. NCURSES_RESERVED_EVENT* = 0o40'i32
  864. # event masks
  865. BUTTON1_RELEASED* = NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_RELEASED)
  866. BUTTON1_PRESSED* = NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_PRESSED)
  867. BUTTON1_CLICKED* = NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_CLICKED)
  868. BUTTON1_DOUBLE_CLICKED* = NCURSES_MOUSE_MASK(1, NCURSES_DOUBLE_CLICKED)
  869. BUTTON1_TRIPLE_CLICKED* = NCURSES_MOUSE_MASK(1, NCURSES_TRIPLE_CLICKED)
  870. BUTTON2_RELEASED* = NCURSES_MOUSE_MASK(2, NCURSES_BUTTON_RELEASED)
  871. BUTTON2_PRESSED* = NCURSES_MOUSE_MASK(2, NCURSES_BUTTON_PRESSED)
  872. BUTTON2_CLICKED* = NCURSES_MOUSE_MASK(2, NCURSES_BUTTON_CLICKED)
  873. BUTTON2_DOUBLE_CLICKED* = NCURSES_MOUSE_MASK(2, NCURSES_DOUBLE_CLICKED)
  874. BUTTON2_TRIPLE_CLICKED* = NCURSES_MOUSE_MASK(2, NCURSES_TRIPLE_CLICKED)
  875. BUTTON3_RELEASED* = NCURSES_MOUSE_MASK(3, NCURSES_BUTTON_RELEASED)
  876. BUTTON3_PRESSED* = NCURSES_MOUSE_MASK(3, NCURSES_BUTTON_PRESSED)
  877. BUTTON3_CLICKED* = NCURSES_MOUSE_MASK(3, NCURSES_BUTTON_CLICKED)
  878. BUTTON3_DOUBLE_CLICKED* = NCURSES_MOUSE_MASK(3, NCURSES_DOUBLE_CLICKED)
  879. BUTTON3_TRIPLE_CLICKED* = NCURSES_MOUSE_MASK(3, NCURSES_TRIPLE_CLICKED)
  880. BUTTON4_RELEASED* = NCURSES_MOUSE_MASK(4, NCURSES_BUTTON_RELEASED)
  881. BUTTON4_PRESSED* = NCURSES_MOUSE_MASK(4, NCURSES_BUTTON_PRESSED)
  882. BUTTON4_CLICKED* = NCURSES_MOUSE_MASK(4, NCURSES_BUTTON_CLICKED)
  883. BUTTON4_DOUBLE_CLICKED* = NCURSES_MOUSE_MASK(4, NCURSES_DOUBLE_CLICKED)
  884. BUTTON4_TRIPLE_CLICKED* = NCURSES_MOUSE_MASK(4, NCURSES_TRIPLE_CLICKED)
  885. BUTTON5_RELEASED* = NCURSES_MOUSE_MASK(5, NCURSES_BUTTON_RELEASED)
  886. BUTTON5_PRESSED* = NCURSES_MOUSE_MASK(5, NCURSES_BUTTON_PRESSED)
  887. BUTTON5_CLICKED* = NCURSES_MOUSE_MASK(5, NCURSES_BUTTON_CLICKED)
  888. BUTTON5_DOUBLE_CLICKED* = NCURSES_MOUSE_MASK(5, NCURSES_DOUBLE_CLICKED)
  889. BUTTON5_TRIPLE_CLICKED* = NCURSES_MOUSE_MASK(5, NCURSES_TRIPLE_CLICKED)
  890. BUTTON_CTRL* = NCURSES_MOUSE_MASK(6, 1)
  891. BUTTON_SHIFT* = NCURSES_MOUSE_MASK(6, 2)
  892. BUTTON_ALT* = NCURSES_MOUSE_MASK(6, 4)
  893. # keys
  894. KEY_CODE_YES* = 0o400 ## A wchar_t contains a key code
  895. KEY_MIN* = 0o401 ## Minimum curses key
  896. KEY_BREAK* = 0o401 ## Break key (unreliable)
  897. KEY_SRESET* = 0o530 ## Soft (partial) reset (unreliable)
  898. KEY_RESET* = 0o531 ## Reset or hard reset (unreliable)
  899. KEY_DOWN* = 0o402 ## down-arrow key
  900. KEY_UP* = 0o403 ## up-arrow key
  901. KEY_LEFT* = 0o404 ## left-arrow key
  902. KEY_RIGHT* = 0o405 ## right-arrow key
  903. KEY_HOME* = 0o406 ## home key
  904. KEY_BACKSPACE* = 0o407 ## backspace key
  905. KEY_F0* = 0o410 ## Function keys. Space for 64
  906. KEY_DL* = 0o510 ## delete-line key
  907. KEY_IL* = 0o511 ## insert-line key
  908. KEY_DC* = 0o512 ## delete-character key
  909. KEY_IC* = 0o513 ## insert-character key
  910. KEY_EIC* = 0o514 ## sent by rmir or smir in insert mode
  911. KEY_CLEAR* = 0o515 ## clear-screen or erase key
  912. KEY_EOS* = 0o516 ## clear-to-end-of-screen key
  913. KEY_EOL* = 0o517 ## clear-to-end-of-line key
  914. KEY_SF* = 0o520 ## scroll-forward key
  915. KEY_SR* = 0o521 ## scroll-backward key
  916. KEY_NPAGE* = 0o522 ## next-page key
  917. KEY_PPAGE* = 0o523 ## previous-page key
  918. KEY_STAB* = 0o524 ## set-tab key
  919. KEY_CTAB* = 0o525 ## clear-tab key
  920. KEY_CATAB* = 0o526 ## clear-all-tabs key
  921. KEY_ENTER* = 0o527 ## enter/send key
  922. KEY_PRINT* = 0o532 ## print key
  923. KEY_LL* = 0o533 ## lower-left key (home down)
  924. KEY_A1* = 0o534 ## upper left of keypad
  925. KEY_A3* = 0o535 ## upper right of keypad
  926. KEY_B2* = 0o536 ## center of keypad
  927. KEY_C1* = 0o537 ## lower left of keypad
  928. KEY_C3* = 0o540 ## lower right of keypad
  929. KEY_BTAB* = 0o541 ## back-tab key
  930. KEY_BEG* = 0o542 ## begin key
  931. KEY_CANCEL* = 0o543 ## cancel key
  932. KEY_CLOSE* = 0o544 ## close key
  933. KEY_COMMAND* = 0o545 ## command key
  934. KEY_COPY* = 0o546 ## copy key
  935. KEY_CREATE* = 0o547 ## create key
  936. KEY_END* = 0o550 ## end key
  937. KEY_EXIT* = 0o551 ## exit key
  938. KEY_FIND* = 0o552 ## find key
  939. KEY_HELP* = 0o553 ## help key
  940. KEY_MARK* = 0o554 ## mark key
  941. KEY_MESSAGE* = 0o555 ## message key
  942. KEY_MOVE* = 0o556 ## move key
  943. KEY_NEXT* = 0o557 ## next key
  944. KEY_OPEN* = 0o560 ## open key
  945. KEY_OPTIONS* = 0o561 ## options key
  946. KEY_PREVIOUS* = 0o562 ## previous key
  947. KEY_REDO* = 0o563 ## redo key
  948. KEY_REFERENCE* = 0o564 ## reference key
  949. KEY_REFRESH* = 0o565 ## refresh key
  950. KEY_REPLACE* = 0o566 ## replace key
  951. KEY_RESTART* = 0o567 ## restart key
  952. KEY_RESUME* = 0o570 ## resume key
  953. KEY_SAVE* = 0o571 ## save key
  954. KEY_SBEG* = 0o572 ## shifted begin key
  955. KEY_SCANCEL* = 0o573 ## shifted cancel key
  956. KEY_SCOMMAND* = 0o574 ## shifted command key
  957. KEY_SCOPY* = 0o575 ## shifted copy key
  958. KEY_SCREATE* = 0o576 ## shifted create key
  959. KEY_SDC* = 0o577 ## shifted delete-character key
  960. KEY_SDL* = 0o600 ## shifted delete-line key
  961. KEY_SELECT* = 0o601 ## select key
  962. KEY_SEND* = 0o602 ## shifted end key
  963. KEY_SEOL* = 0o603 ## shifted clear-to-end-of-line key
  964. KEY_SEXIT* = 0o604 ## shifted exit key
  965. KEY_SFIND* = 0o605 ## shifted find key
  966. KEY_SHELP* = 0o606 ## shifted help key
  967. KEY_SHOME* = 0o607 ## shifted home key
  968. KEY_SIC* = 0o610 ## shifted insert-character key
  969. KEY_SLEFT* = 0o611 ## shifted left-arrow key
  970. KEY_SMESSAGE* = 0o612 ## shifted message key
  971. KEY_SMOVE* = 0o613 ## shifted move key
  972. KEY_SNEXT* = 0o614 ## shifted next key
  973. KEY_SOPTIONS* = 0o615 ## shifted options key
  974. KEY_SPREVIOUS* = 0o616 ## shifted previous key
  975. KEY_SPRINT* = 0o617 ## shifted print key
  976. KEY_SREDO* = 0o620 ## shifted redo key
  977. KEY_SREPLACE* = 0o621 ## shifted replace key
  978. KEY_SRIGHT* = 0o622 ## shifted right-arrow key
  979. KEY_SRSUME* = 0o623 ## shifted resume key
  980. KEY_SSAVE* = 0o624 ## shifted save key
  981. KEY_SSUSPEND* = 0o625 ## shifted suspend key
  982. KEY_SUNDO* = 0o626 ## shifted undo key
  983. KEY_SUSPEND* = 0o627 ## suspend key
  984. KEY_UNDO* = 0o630 ## undo key
  985. KEY_MOUSE* = 0o631 ## Mouse event has occurred
  986. KEY_RESIZE* = 0o632 ## Terminal resize event
  987. KEY_EVENT* = 0o633 ## We were interrupted by an event
  988. template KEY_F*(n: untyped): untyped= (KEY_F0+(n)) ## Value of function key n