Permalink
Browse files

Add files

svn path=/trunk/mono-curses/; revision=75491
  • Loading branch information...
0 parents commit ecda91aa08de7e092933cd9c5d637f9abfc7d1aa @migueldeicaza migueldeicaza committed Apr 6, 2007
Showing with 352 additions and 0 deletions.
  1. +1 −0 AUTHORS
  2. +24 −0 Makefile
  3. +19 −0 README
  4. +143 −0 binding.cs.in
  5. +127 −0 handles.cs
  6. +17 −0 mono-curses.c
  7. +21 −0 test.cs
@@ -0,0 +1 @@
+Miguel de Icaza (miguel@gnome.org)
@@ -0,0 +1,24 @@
+CURSES=ncurses
+SOURCES = \
+ handles.cs \
+ binding.cs
+
+all: mono-curses.dll libmono-curses.so test.exe
+
+test.exe: test.cs mono-curses.dll libmono-curses.so
+ gmcs test.cs -r:mono-curses.dll
+
+mono-curses.dll: $(SOURCES)
+ gmcs -target:library -out:mono-curses.dll -debug $(SOURCES)
+
+binding.cs: binding.cs.in
+ sed -e 's/@CURSES@/$(CURSES)/' < binding.cs.in > binding.cs
+
+libmono-curses.so: mono-curses.c
+ gcc -shared -fPIC mono-curses.c -o libmono-curses.so
+
+test: test.exe
+ mono test.exe
+
+clean:
+ rm *.exe *dll binding.cs *.so
19 README
@@ -0,0 +1,19 @@
+console-sharp
+=============
+
+ Console sharp is an ncurses binding licensed under the terms
+ of the MIT X11 license.
+
+License
+=======
+
+ Console Sharp is licensed under the terms of M
+Implementation Notes
+====================
+
+ The initial implementation used SafeHandles, but since
+ SafeHandles only became available in recent versions of Mono,
+ I have switched the code to use IntPtrs for now, and will go
+ back to it when newer versions of Mono become more wildly
+ available.
+
@@ -0,0 +1,143 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace Mono.Terminal {
+
+ public partial class Curses {
+#region Screen initialization
+
+ [DllImport ("@CURSES@", EntryPoint="initscr")]
+ extern static internal IntPtr real_initscr ();
+
+ static Window main_window;
+
+ static public Window initscr ()
+ {
+ main_window = new Window (real_initscr ());
+ return main_window;
+ }
+
+ [DllImport ("@CURSES@")]
+ extern static public int endwin ();
+
+ [DllImport ("@CURSES@")]
+ extern static public bool isendwin ();
+
+ //
+ // Screen operations are flagged as internal, as we need to
+ // catch all changes so we can update newscr, curscr, stdscr
+ //
+ [DllImport ("@CURSES@")]
+ extern static public IntPtr internal_newterm (string type, IntPtr file_outfd, IntPtr file_infd);
+
+ [DllImport ("@CURSES@")]
+ extern static public IntPtr internal_set_term (IntPtr newscreen);
+
+ [DllImport ("@CURSES@")]
+ extern static internal void internal_delscreen (IntPtr sp);
+#endregion
+
+#region Input Options
+ [DllImport ("@CURSES@")]
+ extern static public int cbreak ();
+
+ [DllImport ("@CURSES@")]
+ extern static public int nocbreak ();
+
+ [DllImport ("@CURSES@")]
+ extern static public int echo ();
+
+ [DllImport ("@CURSES@")]
+ extern static public int noecho ();
+
+ [DllImport ("@CURSES@")]
+ extern static public int halfdelay (int t);
+
+ [DllImport ("@CURSES@")]
+ extern static public int raw ();
+
+ [DllImport ("@CURSES@")]
+ extern static public int noraw ();
+
+ [DllImport ("@CURSES@")]
+ extern static public void noqiflush ();
+
+ [DllImport ("@CURSES@")]
+ extern static public void qiflush ();
+
+ [DllImport ("@CURSES@")]
+ extern static public int typeahead (IntPtr fd);
+
+ [DllImport ("@CURSES@")]
+ extern static public int timeout (int delay);
+
+ //
+ // Internal, as they are exposed in Window
+ //
+ [DllImport ("@CURSES@")]
+ extern static internal int wtimeout (IntPtr win, int delay);
+
+ [DllImport ("@CURSES@")]
+ extern static internal int notimeout (IntPtr win, bool bf);
+
+ [DllImport ("@CURSES@")]
+ extern static internal int keypad (IntPtr win, bool bf);
+
+ [DllImport ("@CURSES@")]
+ extern static internal int meta (IntPtr win, bool bf);
+
+ [DllImport ("@CURSES@")]
+ extern static internal int intrflush (IntPtr win, bool bf);
+#endregion
+
+#region Output Options
+ [DllImport ("@CURSES@")]
+ extern internal static int clearok (IntPtr win, bool bf);
+ [DllImport ("@CURSES@")]
+ extern internal static int idlok (IntPtr win, bool bf);
+ [DllImport ("@CURSES@")]
+ extern internal static void idcok (IntPtr win, bool bf);
+ [DllImport ("@CURSES@")]
+ extern internal static void immedok (IntPtr win, bool bf);
+ [DllImport ("@CURSES@")]
+ extern internal static int leaveok (IntPtr win, bool bf);
+ [DllImport ("@CURSES@")]
+ extern internal static int wsetscrreg (IntPtr win, int top, int bot);
+ [DllImport ("@CURSES@")]
+ extern internal static int scrollok (IntPtr win, bool bf);
+
+ [DllImport ("@CURSES@")]
+ extern public static int nl();
+ [DllImport ("@CURSES@")]
+ extern public static int nonl();
+ [DllImport ("@CURSES@")]
+ extern public static int setscrreg (int top, int bot);
+
+#endregion
+
+#region refresh functions
+
+ [DllImport ("@CURSES@")]
+ extern public static int refresh ();
+ [DllImport ("@CURSES@")]
+ extern public static int doupdate();
+
+ [DllImport ("@CURSES@")]
+ extern internal static int wrefresh (IntPtr win);
+ [DllImport ("@CURSES@")]
+ extern internal static int redrawwin (IntPtr win);
+ [DllImport ("@CURSES@")]
+ extern internal static int wredrawwin (IntPtr win, int beg_line, int num_lines);
+ [DllImport ("@CURSES@")]
+ extern internal static int wnoutrefresh (IntPtr win);
+#endregion
+
+#region Helpers
+ [DllImport ("console-sharp")]
+ internal extern static IntPtr console_sharp_get_stdscr ();
+
+ [DllImport ("console-sharp")]
+ internal extern static IntPtr console_sharp_get_curscr ();
+#endregion
+ }
+}
@@ -0,0 +1,127 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace Mono.Curses {
+
+ public class Window {
+ public readonly IntPtr Handle;
+ static Window curscr;
+ static Window stdscr;
+
+ static Window ()
+ {
+ Curses.initscr ();
+ stdscr = new Window (Curses.console_sharp_get_stdscr ());
+ curscr = new Window (Curses.console_sharp_get_curscr ());
+ }
+
+ internal Window (IntPtr handle)
+ {
+ Handle = handle;
+ }
+
+ static public Window Standard {
+ get {
+ return stdscr;
+ }
+ }
+
+ static public Window Current {
+ get {
+ return curscr;
+ }
+ }
+
+
+ public int wtimeout (int delay)
+ {
+ return Curses.wtimeout (Handle, delay);
+ }
+
+ public int notimeout (bool bf)
+ {
+ return Curses.notimeout (Handle, bf);
+ }
+
+ public int keypad (bool bf)
+ {
+ return Curses.keypad (Handle, bf);
+ }
+
+ public int meta (bool bf)
+ {
+ return Curses.meta (Handle, bf);
+ }
+
+ public int intrflush (bool bf)
+ {
+ return Curses.intrflush (Handle, bf);
+ }
+
+ public int clearok (bool bf)
+ {
+ return Curses.clearok (Handle, bf);
+ }
+
+ public int idlok (bool bf)
+ {
+ return Curses.idlok (Handle, bf);
+ }
+
+ public void idcok (bool bf)
+ {
+ Curses.idcok (Handle, bf);
+ }
+
+ public void immedok (bool bf)
+ {
+ Curses.immedok (Handle, bf);
+ }
+
+ public int leaveok (bool bf)
+ {
+ return Curses.leaveok (Handle, bf);
+ }
+
+ public int setscrreg (int top, int bot)
+ {
+ return Curses.wsetscrreg (Handle, top, bot);
+ }
+
+ public int scrollok (bool bf)
+ {
+ return Curses.scrollok (Handle, bf);
+ }
+
+ public int wrefresh ()
+ {
+ return Curses.wrefresh (Handle);
+ }
+
+ public int redrawwin ()
+ {
+ return Curses.redrawwin (Handle);
+ }
+
+ public int wredrawwin (int beg_line, int num_lines)
+ {
+ return Curses.wredrawwin (Handle, beg_line, num_lines);
+ }
+
+ public int wnoutrefresh ()
+ {
+ return Curses.wnoutrefresh (Handle);
+ }
+
+ }
+
+ // Currently unused, to do later
+ public class Screen {
+ public readonly IntPtr Handle;
+
+ internal Screen (IntPtr handle)
+ {
+ Handle = handle;
+ }
+ }
+}
@@ -0,0 +1,17 @@
+#include <ncurses.h>
+
+void *console_sharp_get_stdscr ()
+{
+ return stdscr;
+}
+
+void *console_sharp_get_curscr ()
+{
+ return curscr;
+}
+
+void *console_sharp_get_newscr ()
+{
+ return newscr;
+}
+
21 test.cs
@@ -0,0 +1,21 @@
+using System;
+using Mono.Curses;
+
+class Demo {
+ static void Main ()
+ {
+ // Standard Init sequence
+ Curses.initscr ();
+ Curses.cbreak ();
+ Curses.noecho ();
+
+ // Recommended
+ Curses.nonl ();
+
+ Window.Standard.intrflush (false);
+ Window.Standard.keypad (true);
+
+ // Shutdown
+ Curses.endwin ();
+ }
+}

0 comments on commit ecda91a

Please sign in to comment.