dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] pnetlib/runtime/System Console.cs,1.14,1.15


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] pnetlib/runtime/System Console.cs,1.14,1.15
Date: Sun, 02 Nov 2003 02:55:26 +0000

Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System
In directory subversions:/tmp/cvs-serv23800/runtime/System

Modified Files:
        Console.cs 
Log Message:


Reflect the extended console routines through to interncalls
in "Platform.Stdio" so that the runtime engine can handle them.


Index: Console.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Console.cs,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** Console.cs  1 Nov 2003 11:53:51 -0000       1.14
--- Console.cs  2 Nov 2003 02:55:24 -0000       1.15
***************
*** 181,184 ****
--- 181,185 ----
        public static int Read()
                        {
+                               NormalMode();
                                return In.Read();
                        }
***************
*** 187,190 ****
--- 188,192 ----
        public static String ReadLine()
                        {
+                               NormalMode();
                                return In.ReadLine();
                        }
***************
*** 400,403 ****
--- 402,406 ----
                                StringBuilder builder = new StringBuilder();
                                int ch;
+                               NormalMode();
                                while((ch = Stdio.StdRead(0)) != -1 && ch != 
'\n')
                                {
***************
*** 551,653 ****
  #if CONFIG_EXTENDED_CONSOLE
  
        // Output a beep on the console.
-       [TODO]
        public static void Beep()
                        {
!                               // TODO
                        }
  
        // Clear the display to the current foreground and background color.
-       [TODO]
        public static void Clear()
                        {
!                               // TODO
                        }
  
        // Read a key from the console.  If "intercept" is "false",
        // then the key is echoed to the console.
-       [TODO]
        public static ConsoleKeyInfo ReadKey()
                        {
                                return ReadKey(false);
                        }
-       [TODO]
        public static ConsoleKeyInfo ReadKey(bool intercept)
                        {
!                               // TODO
!                               return new ConsoleKeyInfo('\0', (ConsoleKey)0,
!                                                                               
  (ConsoleModifiers)0);
                        }
  
        // Set the cursor position.
        // This is a guess - fix later.
-       [TODO]
        public static void SetCursorPosition(int x, int y)
                        {
!                               // TODO
                        }
  
        // Set the current text foreground and background attributes.
        // This is a guess - fix later.
-       [TODO]
        public static void SetTextAttribute(ConsoleColor foreground,
                                                                                
ConsoleColor background)
                        {
!                               // TODO
                        }
  
        // Console properties.
-       [TODO]
        public static int BufferHeight
                        {
                                get
                                {
!                                       // TODO
!                                       return 25;
                                }
                        }
-       [TODO]
        public static int BufferWidth
                        {
                                get
                                {
!                                       // TODO
!                                       return 80;
                                }
                        }
-       [TODO]
        public static int CursorLeft
                        {
                                get
                                {
!                                       // TODO
!                                       return 0;
                                }
                        }
-       [TODO]
        public static int CursorTop
                        {
                                get
                                {
!                                       // TODO
!                                       return 0;
                                }
                        }
-       [TODO]
        public static bool KeyAvailable
                        {
                                get
                                {
!                                       // TODO
!                                       return false;
                                }
                        }
-       [TODO]
        public static String Title
                        {
                                get
                                {
!                                       // TODO
!                                       return String.Empty;
                                }
                                set
--- 554,733 ----
  #if CONFIG_EXTENDED_CONSOLE
  
+       // Global state for the extended console.
+       private static String title = String.Empty;
+       private static bool specialMode = false;
+       private static bool treatControlCAsInput = false;
+ 
+       // Enable the "normal" input mode on the console.
+       private static void NormalMode()
+                       {
+                               lock(typeof(Console))
+                               {
+                                       if(specialMode)
+                                       {
+                                               specialMode = false;
+                                               
Stdio.SetConsoleMode(Stdio.MODE_NORMAL);
+                                       }
+                               }
+                       }
+ 
+       // Enable the "special" character-at-a-time input mode on the console.
+       private static void SpecialMode()
+                       {
+                               lock(typeof(Console))
+                               {
+                                       if(!specialMode)
+                                       {
+                                               specialMode = true;
+                                               if(treatControlCAsInput)
+                                               {
+                                                       
Stdio.SetConsoleMode(Stdio.MODE_RAW);
+                                               }
+                                               else
+                                               {
+                                                       
Stdio.SetConsoleMode(Stdio.MODE_CBREAK);
+                                               }
+                                       }
+                               }
+                       }
+ 
        // Output a beep on the console.
        public static void Beep()
                        {
!                               lock(typeof(Console))
!                               {
!                                       SpecialMode();
!                                       Stdio.Beep();
!                               }
                        }
  
        // Clear the display to the current foreground and background color.
        public static void Clear()
                        {
!                               lock(typeof(Console))
!                               {
!                                       SpecialMode();
!                                       Stdio.Clear();
!                               }
                        }
  
        // Read a key from the console.  If "intercept" is "false",
        // then the key is echoed to the console.
        public static ConsoleKeyInfo ReadKey()
                        {
                                return ReadKey(false);
                        }
        public static ConsoleKeyInfo ReadKey(bool intercept)
                        {
!                               lock(typeof(Console))
!                               {
!                                       SpecialMode();
!                                       char ch;
!                                       int key, modifiers;
!                                       Stdio.ReadKey(out ch, out key, out 
modifiers);
!                                       return new ConsoleKeyInfo
!                                               (ch, (ConsoleKey)key, 
(ConsoleModifiers)modifiers);
!                               }
                        }
  
        // Set the cursor position.
        // This is a guess - fix later.
        public static void SetCursorPosition(int x, int y)
                        {
!                               lock(typeof(Console))
!                               {
!                                       SpecialMode();
!                                       Stdio.SetCursorPosition(x, y);
!                               }
                        }
  
        // Set the current text foreground and background attributes.
        // This is a guess - fix later.
        public static void SetTextAttribute(ConsoleColor foreground,
                                                                                
ConsoleColor background)
                        {
!                               lock(typeof(Console))
!                               {
!                                       SpecialMode();
!                                       Stdio.SetTextAttributes
!                                               (((int)foreground) | 
(((int)background) << 4));
!                               }
                        }
  
        // Console properties.
        public static int BufferHeight
                        {
                                get
                                {
!                                       lock(typeof(Console))
!                                       {
!                                               SpecialMode();
!                                               int width, height;
!                                               Stdio.GetBufferSize(out width, 
out height);
!                                               return height;
!                                       }
                                }
                        }
        public static int BufferWidth
                        {
                                get
                                {
!                                       lock(typeof(Console))
!                                       {
!                                               SpecialMode();
!                                               int width, height;
!                                               Stdio.GetBufferSize(out width, 
out height);
!                                               return width;
!                                       }
                                }
                        }
        public static int CursorLeft
                        {
                                get
                                {
!                                       lock(typeof(Console))
!                                       {
!                                               SpecialMode();
!                                               int x, y;
!                                               Stdio.GetCursorPosition(out x, 
out y);
!                                               return x;
!                                       }
                                }
                        }
        public static int CursorTop
                        {
                                get
                                {
!                                       lock(typeof(Console))
!                                       {
!                                               SpecialMode();
!                                               int x, y;
!                                               Stdio.GetCursorPosition(out x, 
out y);
!                                               return y;
!                                       }
                                }
                        }
        public static bool KeyAvailable
                        {
                                get
                                {
!                                       lock(typeof(Console))
!                                       {
!                                               SpecialMode();
!                                               return Stdio.KeyAvailable();
!                                       }
                                }
                        }
        public static String Title
                        {
                                get
                                {
!                                       // Note: we never query the initial 
console title
!                                       // from the system because it may 
contain sensitive
!                                       // data that we don't want the program 
to have access to.
!                                       lock(typeof(Console))
!                                       {
!                                               return title;
!                                       }
                                }
                                set
***************
*** 657,710 ****
                                                throw new 
ArgumentNullException("value");
                                        }
!                                       // TODO
                                }
                        }
-       [TODO]
        public static bool TreatControlCAsInput
                        {
                                get
                                {
!                                       // TODO
!                                       return false;
                                }
                                set
                                {
!                                       // TODO
                                }
                        }
-       [TODO]
        public static int WindowHeight
                        {
                                get
                                {
!                                       // TODO
!                                       return 25;
                                }
                        }
-       [TODO]
        public static int WindowLeft
                        {
                                get
                                {
!                                       // TODO
!                                       return 0;
                                }
                        }
-       [TODO]
        public static int WindowTop
                        {
                                get
                                {
!                                       // TODO
!                                       return 0;
                                }
                        }
-       [TODO]
        public static int WindowWidth
                        {
                                get
                                {
!                                       // TODO
!                                       return 80;
                                }
                        }
--- 737,824 ----
                                                throw new 
ArgumentNullException("value");
                                        }
!                                       lock(typeof(Console))
!                                       {
!                                               SpecialMode();
!                                               title = value;
!                                               Stdio.SetConsoleTitle(title);
!                                       }
                                }
                        }
        public static bool TreatControlCAsInput
                        {
                                get
                                {
!                                       lock(typeof(Console))
!                                       {
!                                               return treatControlCAsInput;
!                                       }
                                }
                                set
                                {
!                                       lock(typeof(Console))
!                                       {
!                                               if(treatControlCAsInput != 
value)
!                                               {
!                                                       specialMode = false;
!                                                       treatControlCAsInput = 
value;
!                                                       SpecialMode();
!                                               }
!                                       }
                                }
                        }
        public static int WindowHeight
                        {
                                get
                                {
!                                       lock(typeof(Console))
!                                       {
!                                               SpecialMode();
!                                               int left, top, width, height;
!                                               Stdio.GetWindowSize
!                                                       (out left, out top, out 
width, out height);
!                                               return height;
!                                       }
                                }
                        }
        public static int WindowLeft
                        {
                                get
                                {
!                                       lock(typeof(Console))
!                                       {
!                                               SpecialMode();
!                                               int left, top, width, height;
!                                               Stdio.GetWindowSize
!                                                       (out left, out top, out 
width, out height);
!                                               return left;
!                                       }
                                }
                        }
        public static int WindowTop
                        {
                                get
                                {
!                                       lock(typeof(Console))
!                                       {
!                                               SpecialMode();
!                                               int left, top, width, height;
!                                               Stdio.GetWindowSize
!                                                       (out left, out top, out 
width, out height);
!                                               return top;
!                                       }
                                }
                        }
        public static int WindowWidth
                        {
                                get
                                {
!                                       lock(typeof(Console))
!                                       {
!                                               SpecialMode();
!                                               int left, top, width, height;
!                                               Stdio.GetWindowSize
!                                                       (out left, out top, out 
width, out height);
!                                               return width;
!                                       }
                                }
                        }
***************
*** 713,717 ****
        public static event ConsoleCancelEventHandler CancelKeyPress;
  
! #endif // CONFIG_EXTENDED_CONSOLE
  
  }; // class Console
--- 827,853 ----
        public static event ConsoleCancelEventHandler CancelKeyPress;
  
!       // Method that is called from the runtime engine to handle "cancel" 
events.
!       // Returns "false" to quit the application, or "true" to continue.
!       private static bool HandleCancel(int specialKeys)
!                       {
!                               ConsoleCancelEventArgs args;
!                               args = new ConsoleCancelEventArgs
!                                       ((ConsoleSpecialKeys)specialKeys);
!                               if(CancelKeyPress != null)
!                               {
!                                       CancelKeyPress(null, args);
!                               }
!                               return args.Cancel;
!                       }
! 
! #else // !CONFIG_EXTENDED_CONSOLE
! 
!       // Enable the "normal" input mode on the console.
!       private static void NormalMode()
!                       {
!                               // Nothing to do if we don't have an extended 
console.
!                       }
! 
! #endif // !CONFIG_EXTENDED_CONSOLE
  
  }; // class Console





reply via email to

[Prev in Thread] Current Thread [Next in Thread]