binding.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. //
  2. // binding.cs.in: Core binding for curses.
  3. //
  4. // This file attempts to call into ncurses without relying on Mono's
  5. // dllmap, so it will work with .NET Core. This means that it needs
  6. // two sets of bindings, one for "ncurses" which works on OSX, and one
  7. // that works against "libncursesw.so.5" which is what you find on
  8. // assorted Linux systems.
  9. //
  10. // Additionally, I do not want to rely on an external native library
  11. // which is why all this pain to bind two separate ncurses is here.
  12. //
  13. // Authors:
  14. // Miguel de Icaza ([email protected])
  15. //
  16. // Copyright (C) 2007 Novell (http://www.novell.com)
  17. //
  18. // Permission is hereby granted, free of charge, to any person obtaining
  19. // a copy of this software and associated documentation files (the
  20. // "Software"), to deal in the Software without restriction, including
  21. // without limitation the rights to use, copy, modify, merge, publish,
  22. // distribute, sublicense, and/or sell copies of the Software, and to
  23. // permit persons to whom the Software is furnished to do so, subject to
  24. // the following conditions:
  25. //
  26. // The above copyright notice and this permission notice shall be
  27. // included in all copies or substantial portions of the Software.
  28. //
  29. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  30. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  31. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  32. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  33. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  34. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  35. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  36. //
  37. using System;
  38. using System.IO;
  39. using System.Runtime.InteropServices;
  40. namespace Unix.Terminal {
  41. internal partial class Curses {
  42. [StructLayout (LayoutKind.Sequential)]
  43. internal struct MouseEvent {
  44. public short ID;
  45. public int X, Y, Z;
  46. public Event ButtonState;
  47. }
  48. static int lines, cols;
  49. static Window main_window;
  50. static IntPtr curses_handle, curscr_ptr, lines_ptr, cols_ptr;
  51. // If true, uses the DllImport into "ncurses", otherwise "libncursesw.so.5"
  52. static bool use_naked_driver;
  53. //
  54. // Ugly hack to P/Invoke into either libc, or libdl, again, because
  55. // we can not have nice things - .NET Core in this day and age still
  56. // does not have <dllmap>
  57. //
  58. static IntPtr DlOpen (string path)
  59. {
  60. if (!uselibc){
  61. try {
  62. var handle = dlopen (path, 1);
  63. return handle;
  64. } catch (DllNotFoundException){
  65. uselibc = true;
  66. return DlOpen (path);
  67. }
  68. } else {
  69. return libc_dlopen (path, 1);
  70. }
  71. }
  72. static void FindNCurses ()
  73. {
  74. if (File.Exists ("/usr/lib/libncurses.dylib")){
  75. curses_handle = DlOpen ("libncurses.dylib");
  76. use_naked_driver = true;
  77. } else
  78. curses_handle = DlOpen ("libncursesw.so.5");
  79. if (curses_handle == IntPtr.Zero) {
  80. Console.WriteLine ("It is not possible to open the dynamic library ncurses, tried looking for libncurses.dylib on Mac, and libncursesw.so.5 on Linux");
  81. Environment.Exit (1);
  82. }
  83. stdscr = read_static_ptr ("stdscr");
  84. curscr_ptr = get_ptr ("curscr");
  85. lines_ptr = get_ptr ("LINES");
  86. cols_ptr = get_ptr ("COLS");
  87. }
  88. static public Window initscr ()
  89. {
  90. FindNCurses ();
  91. main_window = new Window (real_initscr ());
  92. try {
  93. console_sharp_get_dims (out lines, out cols);
  94. } catch (DllNotFoundException){
  95. endwin ();
  96. Console.Error.WriteLine ("Unable to find the @MONO_CURSES@ native library\n" +
  97. "this is different than the managed mono-curses.dll\n\n" +
  98. "Typically you need to install to a LD_LIBRARY_PATH directory\n" +
  99. "or DYLD_LIBRARY_PATH directory or run /sbin/ldconfig");
  100. Environment.Exit (1);
  101. }
  102. return main_window;
  103. }
  104. public static int Lines {
  105. get {
  106. return lines;
  107. }
  108. }
  109. public static int Cols {
  110. get {
  111. return cols;
  112. }
  113. }
  114. //
  115. // Returns true if the window changed since the last invocation, as a
  116. // side effect, the Lines and Cols properties are updated
  117. //
  118. public static bool CheckWinChange ()
  119. {
  120. int l, c;
  121. console_sharp_get_dims (out l, out c);
  122. if (l != lines || c != cols){
  123. lines = l;
  124. cols = c;
  125. return true;
  126. }
  127. return false;
  128. }
  129. public static int addstr (string format, params object [] args)
  130. {
  131. var s = string.Format (format, args);
  132. return addstr (s);
  133. }
  134. static char [] r = new char [1];
  135. //
  136. // Have to wrap the native addch, as it can not
  137. // display unicode characters, we have to use addstr
  138. // for that. but we need addch to render special ACS
  139. // characters
  140. //
  141. public static int addch (int ch)
  142. {
  143. if (ch < 127 || ch > 0xffff )
  144. return _addch (ch);
  145. char c = (char) ch;
  146. return addstr (new String (c, 1));
  147. }
  148. [DllImport ("dl")]
  149. extern static IntPtr dlopen (string file, int mode);
  150. [DllImport ("dl")]
  151. extern static IntPtr dlsym (IntPtr handle, string symbol);
  152. [DllImport ("libc", EntryPoint="dlopen")]
  153. extern static IntPtr libc_dlopen (string file, int mode);
  154. [DllImport ("libc", EntryPoint ="dlsym")]
  155. extern static IntPtr libc_dlsym (IntPtr handle, string symbol);
  156. static bool uselibc;
  157. static IntPtr stdscr;
  158. static IntPtr get_ptr (string key)
  159. {
  160. var ptr = uselibc ? libc_dlsym (curses_handle, key) : dlsym (curses_handle, key);
  161. if (ptr == IntPtr.Zero)
  162. throw new Exception ("Could not load the key " + key);
  163. return ptr;
  164. }
  165. internal static IntPtr read_static_ptr (string key)
  166. {
  167. var ptr = get_ptr (key);
  168. return Marshal.ReadIntPtr (ptr);
  169. }
  170. internal static IntPtr console_sharp_get_stdscr () => stdscr;
  171. internal static IntPtr console_sharp_get_curscr ()
  172. {
  173. return Marshal.ReadIntPtr (curscr_ptr);
  174. }
  175. internal static void console_sharp_get_dims (out int lines, out int cols)
  176. {
  177. lines = Marshal.ReadInt32 (lines_ptr);
  178. cols = Marshal.ReadInt32 (cols_ptr);
  179. }
  180. public static Event mousemask (Event newmask, out Event oldmask)
  181. {
  182. IntPtr e;
  183. var ret = (Event) (use_naked_driver ? RegularCurses.call_mousemask ((IntPtr) newmask, out e) : CursesLinux.call_mousemask ((IntPtr) newmask, out e));
  184. oldmask = (Event) e;
  185. return ret;
  186. }
  187. // We encode ESC + char (what Alt-char generates) as 0x2000 + char
  188. public const int KeyAlt = 0x2000;
  189. static public int IsAlt (int key)
  190. {
  191. if ((key & KeyAlt) != 0)
  192. return key & ~KeyAlt;
  193. return 0;
  194. }
  195. public static int StartColor () => start_color ();
  196. public static bool HasColors => has_colors ();
  197. public static int InitColorPair (short pair, short foreground, short background) => init_pair (pair, foreground, background);
  198. public static int UseDefaultColors () => use_default_colors ();
  199. public static int ColorPairs => COLOR_PAIRS();
  200. //
  201. // The proxy methods to call into each version
  202. //
  203. static public IntPtr real_initscr () => use_naked_driver ? RegularCurses.real_initscr () : CursesLinux.real_initscr ();
  204. static public int endwin () => use_naked_driver ? RegularCurses.endwin () : CursesLinux.endwin ();
  205. static public bool isendwin () => use_naked_driver ? RegularCurses.isendwin () : CursesLinux.isendwin ();
  206. static public IntPtr internal_newterm (string type, IntPtr file_outfd, IntPtr file_infd) => use_naked_driver ? RegularCurses.internal_newterm (type, file_outfd, file_infd) : CursesLinux.internal_newterm (type, file_outfd, file_infd);
  207. static public IntPtr internal_set_term (IntPtr newscreen) => use_naked_driver ? RegularCurses.internal_set_term (newscreen) : CursesLinux.internal_set_term (newscreen);
  208. static public void internal_delscreen (IntPtr sp) { if (use_naked_driver) RegularCurses.internal_delscreen (sp); else CursesLinux.internal_delscreen (sp); }
  209. static public int cbreak () => use_naked_driver ? RegularCurses.cbreak () : CursesLinux.cbreak ();
  210. static public int nocbreak () => use_naked_driver ? RegularCurses.nocbreak () : CursesLinux.nocbreak ();
  211. static public int echo () => use_naked_driver ? RegularCurses.echo () : CursesLinux.echo ();
  212. static public int noecho () => use_naked_driver ? RegularCurses.noecho () : CursesLinux.noecho ();
  213. static public int halfdelay (int t) => use_naked_driver ? RegularCurses.halfdelay (t) : CursesLinux.halfdelay (t);
  214. static public int raw () => use_naked_driver ? RegularCurses.raw () : CursesLinux.raw ();
  215. static public int noraw () => use_naked_driver ? RegularCurses.noraw () : CursesLinux.noraw ();
  216. static public void noqiflush () { if (use_naked_driver) RegularCurses.noqiflush (); else CursesLinux.noqiflush (); }
  217. static public void qiflush () { if (use_naked_driver) RegularCurses.qiflush (); else CursesLinux.qiflush (); }
  218. static public int typeahead (IntPtr fd) => use_naked_driver ? RegularCurses.typeahead (fd) : CursesLinux.typeahead (fd);
  219. static public int timeout (int delay) => use_naked_driver ? RegularCurses.timeout (delay) : CursesLinux.timeout (delay);
  220. static public int wtimeout (IntPtr win, int delay) => use_naked_driver ? RegularCurses.wtimeout (win, delay) : CursesLinux.wtimeout (win, delay);
  221. static public int notimeout (IntPtr win, bool bf) => use_naked_driver ? RegularCurses.notimeout (win, bf) : CursesLinux.notimeout (win, bf);
  222. static public int keypad (IntPtr win, bool bf) => use_naked_driver ? RegularCurses.keypad (win, bf) : CursesLinux.keypad (win, bf);
  223. static public int meta (IntPtr win, bool bf) => use_naked_driver ? RegularCurses.meta (win, bf) : CursesLinux.meta (win, bf);
  224. static public int intrflush (IntPtr win, bool bf) => use_naked_driver ? RegularCurses.intrflush (win, bf) : CursesLinux.intrflush (win, bf);
  225. static public int clearok (IntPtr win, bool bf) => use_naked_driver ? RegularCurses.clearok (win, bf) : CursesLinux.clearok (win, bf);
  226. static public int idlok (IntPtr win, bool bf) => use_naked_driver ? RegularCurses.idlok (win, bf) : CursesLinux.idlok (win, bf);
  227. static public void idcok (IntPtr win, bool bf) { if (use_naked_driver) RegularCurses.idcok (win, bf); else CursesLinux.idcok (win, bf);}
  228. static public void immedok (IntPtr win, bool bf) { if (use_naked_driver) RegularCurses.immedok (win, bf); else CursesLinux.immedok (win, bf);}
  229. static public int leaveok (IntPtr win, bool bf) => use_naked_driver ? RegularCurses.leaveok (win, bf) : CursesLinux.leaveok (win, bf);
  230. static public int wsetscrreg (IntPtr win, int top, int bot) => use_naked_driver ? RegularCurses.wsetscrreg (win, top, bot) : CursesLinux.wsetscrreg (win, top, bot);
  231. static public int scrollok (IntPtr win, bool bf) => use_naked_driver ? RegularCurses.scrollok (win, bf) : CursesLinux.scrollok (win, bf);
  232. static public int nl() => use_naked_driver ? RegularCurses.nl() : CursesLinux.nl();
  233. static public int nonl() => use_naked_driver ? RegularCurses.nonl() : CursesLinux.nonl();
  234. static public int setscrreg (int top, int bot) => use_naked_driver ? RegularCurses.setscrreg (top, bot) : CursesLinux.setscrreg (top, bot);
  235. static public int refresh () => use_naked_driver ? RegularCurses.refresh () : CursesLinux.refresh ();
  236. static public int doupdate() => use_naked_driver ? RegularCurses.doupdate() : CursesLinux.doupdate();
  237. static public int wrefresh (IntPtr win) => use_naked_driver ? RegularCurses.wrefresh (win) : CursesLinux.wrefresh (win);
  238. static public int redrawwin (IntPtr win) => use_naked_driver ? RegularCurses.redrawwin (win) : CursesLinux.redrawwin (win);
  239. static public int wredrawwin (IntPtr win, int beg_line, int num_lines) => use_naked_driver ? RegularCurses.wredrawwin (win, beg_line, num_lines) : CursesLinux.wredrawwin (win, beg_line, lines);
  240. static public int wnoutrefresh (IntPtr win) => use_naked_driver ? RegularCurses.wnoutrefresh (win) : CursesLinux.wnoutrefresh (win);
  241. static public int move (int line, int col) => use_naked_driver ? RegularCurses.move (line, col) : CursesLinux.move (line, col);
  242. static public int _addch (int ch) => use_naked_driver ? RegularCurses._addch (ch) : CursesLinux._addch (ch);
  243. static public int addstr (string s) => use_naked_driver ? RegularCurses.addstr (s) : CursesLinux.addstr (s);
  244. static public int wmove (IntPtr win, int line, int col) => use_naked_driver ? RegularCurses.wmove (win, line, col) : CursesLinux.wmove (win, line, col);
  245. static public int waddch (IntPtr win, int ch) => use_naked_driver ? RegularCurses.waddch (win, ch) : CursesLinux.waddch (win, ch);
  246. static public int attron (int attrs) => use_naked_driver ? RegularCurses.attron (attrs) : CursesLinux.attron (attrs);
  247. static public int attroff (int attrs) => use_naked_driver ? RegularCurses.attroff (attrs) : CursesLinux.attroff (attrs);
  248. static public int attrset (int attrs) => use_naked_driver ? RegularCurses.attrset (attrs) : CursesLinux.attrset (attrs);
  249. static public int getch () => use_naked_driver ? RegularCurses.getch () : CursesLinux.getch ();
  250. static public int get_wch (out int sequence) => use_naked_driver ? RegularCurses.get_wch (out sequence) : CursesLinux.get_wch (out sequence);
  251. static public int ungetch (int ch) => use_naked_driver ? RegularCurses.ungetch (ch) : CursesLinux.ungetch (ch);
  252. static public int mvgetch (int y, int x) => use_naked_driver ? RegularCurses.mvgetch (y, x) : CursesLinux.mvgetch (y, x);
  253. static public bool has_colors () => use_naked_driver ? RegularCurses.has_colors () : CursesLinux.has_colors ();
  254. static public int start_color () => use_naked_driver ? RegularCurses.start_color () : CursesLinux.start_color ();
  255. static public int init_pair (short pair, short f, short b) => use_naked_driver ? RegularCurses.init_pair (pair, f, b) : CursesLinux.init_pair (pair, f, b);
  256. static public int use_default_colors () => use_naked_driver ? RegularCurses.use_default_colors () : CursesLinux.use_default_colors ();
  257. static public int COLOR_PAIRS() => use_naked_driver ? RegularCurses.COLOR_PAIRS() : CursesLinux.COLOR_PAIRS();
  258. static public uint getmouse (out MouseEvent ev) => use_naked_driver ? RegularCurses.getmouse (out ev) : CursesLinux.getmouse (out ev);
  259. static public uint ungetmouse (ref MouseEvent ev) => use_naked_driver ? RegularCurses.ungetmouse (ref ev) : CursesLinux.ungetmouse (ref ev);
  260. static public int mouseinterval (int interval) => use_naked_driver ? RegularCurses.mouseinterval (interval) : CursesLinux.mouseinterval (interval);
  261. }
  262. //
  263. // P/Invoke definitions for looking up symbols in the "ncurses" library, as resolved
  264. // by the dynamic linker, different than CursesLinux that looksup by "libncursesw.so.5"
  265. //
  266. internal class RegularCurses {
  267. [DllImport ("ncurses", EntryPoint="initscr")]
  268. extern static internal IntPtr real_initscr ();
  269. [DllImport ("ncurses")]
  270. extern static public int endwin ();
  271. [DllImport ("ncurses")]
  272. extern static public bool isendwin ();
  273. //
  274. // Screen operations are flagged as internal, as we need to
  275. // catch all changes so we can update newscr, curscr, stdscr
  276. //
  277. [DllImport ("ncurses")]
  278. extern static public IntPtr internal_newterm (string type, IntPtr file_outfd, IntPtr file_infd);
  279. [DllImport ("ncurses")]
  280. extern static public IntPtr internal_set_term (IntPtr newscreen);
  281. [DllImport ("ncurses")]
  282. extern static internal void internal_delscreen (IntPtr sp);
  283. [DllImport ("ncurses")]
  284. extern static public int cbreak ();
  285. [DllImport ("ncurses")]
  286. extern static public int nocbreak ();
  287. [DllImport ("ncurses")]
  288. extern static public int echo ();
  289. [DllImport ("ncurses")]
  290. extern static public int noecho ();
  291. [DllImport ("ncurses")]
  292. extern static public int halfdelay (int t);
  293. [DllImport ("ncurses")]
  294. extern static public int raw ();
  295. [DllImport ("ncurses")]
  296. extern static public int noraw ();
  297. [DllImport ("ncurses")]
  298. extern static public void noqiflush ();
  299. [DllImport ("ncurses")]
  300. extern static public void qiflush ();
  301. [DllImport ("ncurses")]
  302. extern static public int typeahead (IntPtr fd);
  303. [DllImport ("ncurses")]
  304. extern static public int timeout (int delay);
  305. //
  306. // Internal, as they are exposed in Window
  307. //
  308. [DllImport ("ncurses")]
  309. extern static internal int wtimeout (IntPtr win, int delay);
  310. [DllImport ("ncurses")]
  311. extern static internal int notimeout (IntPtr win, bool bf);
  312. [DllImport ("ncurses")]
  313. extern static internal int keypad (IntPtr win, bool bf);
  314. [DllImport ("ncurses")]
  315. extern static internal int meta (IntPtr win, bool bf);
  316. [DllImport ("ncurses")]
  317. extern static internal int intrflush (IntPtr win, bool bf);
  318. [DllImport ("ncurses")]
  319. extern internal static int clearok (IntPtr win, bool bf);
  320. [DllImport ("ncurses")]
  321. extern internal static int idlok (IntPtr win, bool bf);
  322. [DllImport ("ncurses")]
  323. extern internal static void idcok (IntPtr win, bool bf);
  324. [DllImport ("ncurses")]
  325. extern internal static void immedok (IntPtr win, bool bf);
  326. [DllImport ("ncurses")]
  327. extern internal static int leaveok (IntPtr win, bool bf);
  328. [DllImport ("ncurses")]
  329. extern internal static int wsetscrreg (IntPtr win, int top, int bot);
  330. [DllImport ("ncurses")]
  331. extern internal static int scrollok (IntPtr win, bool bf);
  332. [DllImport ("ncurses")]
  333. extern public static int nl();
  334. [DllImport ("ncurses")]
  335. extern public static int nonl();
  336. [DllImport ("ncurses")]
  337. extern public static int setscrreg (int top, int bot);
  338. [DllImport ("ncurses")]
  339. extern public static int refresh ();
  340. [DllImport ("ncurses")]
  341. extern public static int doupdate();
  342. [DllImport ("ncurses")]
  343. extern internal static int wrefresh (IntPtr win);
  344. [DllImport ("ncurses")]
  345. extern internal static int redrawwin (IntPtr win);
  346. [DllImport ("ncurses")]
  347. extern internal static int wredrawwin (IntPtr win, int beg_line, int num_lines);
  348. [DllImport ("ncurses")]
  349. extern internal static int wnoutrefresh (IntPtr win);
  350. [DllImport ("ncurses")]
  351. extern public static int move (int line, int col);
  352. [DllImport ("ncurses", EntryPoint="addch")]
  353. extern internal static int _addch (int ch);
  354. [DllImport ("ncurses")]
  355. extern public static int addstr (string s);
  356. [DllImport ("ncurses")]
  357. extern internal static int wmove (IntPtr win, int line, int col);
  358. [DllImport ("ncurses")]
  359. extern internal static int waddch (IntPtr win, int ch);
  360. [DllImport ("ncurses")]
  361. extern public static int attron (int attrs);
  362. [DllImport ("ncurses")]
  363. extern public static int attroff (int attrs);
  364. [DllImport ("ncurses")]
  365. extern public static int attrset (int attrs);
  366. [DllImport ("ncurses")]
  367. extern public static int getch ();
  368. [DllImport ("ncurses")]
  369. extern public static int get_wch (out int sequence);
  370. [DllImport ("ncurses")]
  371. extern public static int ungetch (int ch);
  372. [DllImport ("ncurses")]
  373. extern public static int mvgetch (int y, int x);
  374. [DllImport ("ncurses")]
  375. extern internal static bool has_colors ();
  376. [DllImport ("ncurses")]
  377. extern internal static int start_color ();
  378. [DllImport ("ncurses")]
  379. extern internal static int init_pair (short pair, short f, short b);
  380. [DllImport ("ncurses")]
  381. extern internal static int use_default_colors ();
  382. [DllImport ("ncurses")]
  383. extern internal static int COLOR_PAIRS();
  384. [DllImport ("ncurses")]
  385. public extern static uint getmouse (out Curses.MouseEvent ev);
  386. [DllImport ("ncurses")]
  387. public extern static uint ungetmouse (ref Curses.MouseEvent ev);
  388. [DllImport ("ncurses")]
  389. public extern static int mouseinterval (int interval);
  390. [DllImport ("ncurses", EntryPoint="mousemask")]
  391. public extern static IntPtr call_mousemask (IntPtr newmask, out IntPtr oldmask);
  392. }
  393. //
  394. // P/Invoke definitions for looking up symbols in the "libncursesw.so.5" library, as resolved
  395. // by the dynamic linker, different than RegularCurses that looksup by "ncurses"
  396. //
  397. internal class CursesLinux {
  398. [DllImport ("libncursesw.so.5", EntryPoint="mousemask")]
  399. public extern static IntPtr call_mousemask (IntPtr newmask, out IntPtr oldmask);
  400. [DllImport ("libncursesw.so.5", EntryPoint="initscr")]
  401. extern static internal IntPtr real_initscr ();
  402. [DllImport ("libncursesw.so.5")]
  403. extern static public int endwin ();
  404. [DllImport ("libncursesw.so.5")]
  405. extern static public bool isendwin ();
  406. //
  407. // Screen operations are flagged as internal, as we need to
  408. // catch all changes so we can update newscr, curscr, stdscr
  409. //
  410. [DllImport ("libncursesw.so.5")]
  411. extern static public IntPtr internal_newterm (string type, IntPtr file_outfd, IntPtr file_infd);
  412. [DllImport ("libncursesw.so.5")]
  413. extern static public IntPtr internal_set_term (IntPtr newscreen);
  414. [DllImport ("libncursesw.so.5")]
  415. extern static internal void internal_delscreen (IntPtr sp);
  416. [DllImport ("libncursesw.so.5")]
  417. extern static public int cbreak ();
  418. [DllImport ("libncursesw.so.5")]
  419. extern static public int nocbreak ();
  420. [DllImport ("libncursesw.so.5")]
  421. extern static public int echo ();
  422. [DllImport ("libncursesw.so.5")]
  423. extern static public int noecho ();
  424. [DllImport ("libncursesw.so.5")]
  425. extern static public int halfdelay (int t);
  426. [DllImport ("libncursesw.so.5")]
  427. extern static public int raw ();
  428. [DllImport ("libncursesw.so.5")]
  429. extern static public int noraw ();
  430. [DllImport ("libncursesw.so.5")]
  431. extern static public void noqiflush ();
  432. [DllImport ("libncursesw.so.5")]
  433. extern static public void qiflush ();
  434. [DllImport ("libncursesw.so.5")]
  435. extern static public int typeahead (IntPtr fd);
  436. [DllImport ("libncursesw.so.5")]
  437. extern static public int timeout (int delay);
  438. //
  439. // Internal, as they are exposed in Window
  440. //
  441. [DllImport ("libncursesw.so.5")]
  442. extern static internal int wtimeout (IntPtr win, int delay);
  443. [DllImport ("libncursesw.so.5")]
  444. extern static internal int notimeout (IntPtr win, bool bf);
  445. [DllImport ("libncursesw.so.5")]
  446. extern static internal int keypad (IntPtr win, bool bf);
  447. [DllImport ("libncursesw.so.5")]
  448. extern static internal int meta (IntPtr win, bool bf);
  449. [DllImport ("libncursesw.so.5")]
  450. extern static internal int intrflush (IntPtr win, bool bf);
  451. [DllImport ("libncursesw.so.5")]
  452. extern internal static int clearok (IntPtr win, bool bf);
  453. [DllImport ("libncursesw.so.5")]
  454. extern internal static int idlok (IntPtr win, bool bf);
  455. [DllImport ("libncursesw.so.5")]
  456. extern internal static void idcok (IntPtr win, bool bf);
  457. [DllImport ("libncursesw.so.5")]
  458. extern internal static void immedok (IntPtr win, bool bf);
  459. [DllImport ("libncursesw.so.5")]
  460. extern internal static int leaveok (IntPtr win, bool bf);
  461. [DllImport ("libncursesw.so.5")]
  462. extern internal static int wsetscrreg (IntPtr win, int top, int bot);
  463. [DllImport ("libncursesw.so.5")]
  464. extern internal static int scrollok (IntPtr win, bool bf);
  465. [DllImport ("libncursesw.so.5")]
  466. extern public static int nl();
  467. [DllImport ("libncursesw.so.5")]
  468. extern public static int nonl();
  469. [DllImport ("libncursesw.so.5")]
  470. extern public static int setscrreg (int top, int bot);
  471. [DllImport ("libncursesw.so.5")]
  472. extern public static int refresh ();
  473. [DllImport ("libncursesw.so.5")]
  474. extern public static int doupdate();
  475. [DllImport ("libncursesw.so.5")]
  476. extern internal static int wrefresh (IntPtr win);
  477. [DllImport ("libncursesw.so.5")]
  478. extern internal static int redrawwin (IntPtr win);
  479. [DllImport ("libncursesw.so.5")]
  480. extern internal static int wredrawwin (IntPtr win, int beg_line, int num_lines);
  481. [DllImport ("libncursesw.so.5")]
  482. extern internal static int wnoutrefresh (IntPtr win);
  483. [DllImport ("libncursesw.so.5")]
  484. extern public static int move (int line, int col);
  485. [DllImport ("libncursesw.so.5", EntryPoint="addch")]
  486. extern internal static int _addch (int ch);
  487. [DllImport ("libncursesw.so.5")]
  488. extern public static int addstr (string s);
  489. [DllImport ("libncursesw.so.5")]
  490. extern internal static int wmove (IntPtr win, int line, int col);
  491. [DllImport ("libncursesw.so.5")]
  492. extern internal static int waddch (IntPtr win, int ch);
  493. [DllImport ("libncursesw.so.5")]
  494. extern public static int attron (int attrs);
  495. [DllImport ("libncursesw.so.5")]
  496. extern public static int attroff (int attrs);
  497. [DllImport ("libncursesw.so.5")]
  498. extern public static int attrset (int attrs);
  499. [DllImport ("libncursesw.so.5")]
  500. extern public static int getch ();
  501. [DllImport ("libncursesw.so.5")]
  502. extern public static int get_wch (out int sequence);
  503. [DllImport ("libncursesw.so.5")]
  504. extern public static int ungetch (int ch);
  505. [DllImport ("libncursesw.so.5")]
  506. extern public static int mvgetch (int y, int x);
  507. [DllImport ("libncursesw.so.5")]
  508. extern internal static bool has_colors ();
  509. [DllImport ("libncursesw.so.5")]
  510. extern internal static int start_color ();
  511. [DllImport ("libncursesw.so.5")]
  512. extern internal static int init_pair (short pair, short f, short b);
  513. [DllImport ("libncursesw.so.5")]
  514. extern internal static int use_default_colors ();
  515. [DllImport ("libncursesw.so.5")]
  516. extern internal static int COLOR_PAIRS();
  517. [DllImport ("libncursesw.so.5")]
  518. public extern static uint getmouse (out Curses.MouseEvent ev);
  519. [DllImport ("libncursesw.so.5")]
  520. public extern static uint ungetmouse (ref Curses.MouseEvent ev);
  521. [DllImport ("libncursesw.so.5")]
  522. public extern static int mouseinterval (int interval);
  523. }
  524. }