2 // System.ConsoleDriver
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Runtime.CompilerServices;
36 static IConsoleDriver driver;
38 static ConsoleDriver ()
40 if (Environment.IsRunningOnWindows) {
41 driver = new WindowsConsoleDriver ();
43 driver = new TermInfoDriver (Environment.GetEnvironmentVariable ("TERM"));
47 public static bool Echo {
48 get { return driver.Echo; }
49 set { driver.Echo = value; }
52 public static bool Initialized {
53 get { return driver.Initialized; }
56 public static ConsoleColor BackgroundColor {
57 get { return driver.BackgroundColor; }
59 if (value < ConsoleColor.Black || value > ConsoleColor.White)
60 throw new ArgumentOutOfRangeException ("value", "Not a ConsoleColor value.");
62 driver.BackgroundColor = value;
66 public static int BufferHeight {
67 get { return driver.BufferHeight; }
68 set { driver.BufferHeight = value; }
71 public static int BufferWidth {
72 get { return driver.BufferWidth; }
73 set { driver.BufferWidth = value; }
76 public static bool CapsLock {
77 get { return driver.CapsLock; }
80 public static int CursorLeft {
81 get { return driver.CursorLeft; }
82 set { driver.CursorLeft = value; }
85 public static int CursorSize {
86 get { return driver.CursorSize; }
87 set { driver.CursorSize = value; }
90 public static int CursorTop {
91 get { return driver.CursorTop; }
92 set { driver.CursorTop = value; }
95 public static bool CursorVisible {
96 get { return driver.CursorVisible; }
97 set { driver.CursorVisible = value; }
100 public static bool KeyAvailable {
101 get { return driver.KeyAvailable; }
104 public static ConsoleColor ForegroundColor {
105 get { return driver.ForegroundColor; }
107 if (value < ConsoleColor.Black || value > ConsoleColor.White)
108 throw new ArgumentOutOfRangeException ("value", "Not a ConsoleColor value.");
110 driver.ForegroundColor = value;
114 public static int LargestWindowHeight {
115 get { return driver.LargestWindowHeight; }
118 public static int LargestWindowWidth {
119 get { return driver.LargestWindowWidth; }
122 public static bool NumberLock {
123 get { return driver.NumberLock; }
126 public static string Title {
127 get { return driver.Title; }
128 set { driver.Title = value; }
131 public static bool TreatControlCAsInput {
132 get { return driver.TreatControlCAsInput; }
133 set { driver.TreatControlCAsInput = value; }
136 public static int WindowHeight {
137 get { return driver.WindowHeight; }
138 set { driver.WindowHeight = value; }
141 public static int WindowLeft {
142 get { return driver.WindowLeft; }
143 set { driver.WindowLeft = value; }
146 public static int WindowTop {
147 get { return driver.WindowTop; }
148 set { driver.WindowTop = value; }
151 public static int WindowWidth {
152 get { return driver.WindowWidth; }
153 set { driver.WindowWidth = value; }
156 public static void Beep (int frequency, int duration)
158 driver.Beep (frequency, duration);
161 public static void Clear ()
166 public static void MoveBufferArea (int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight,
167 int targetLeft, int targetTop)
169 MoveBufferArea (sourceLeft, sourceTop, sourceWidth, sourceHeight,
170 targetLeft, targetTop, ' ', 0, 0);
173 public static void MoveBufferArea (int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight,
174 int targetLeft, int targetTop, char sourceChar,
175 ConsoleColor sourceForeColor, ConsoleColor sourceBackColor)
177 driver.MoveBufferArea (sourceLeft, sourceTop, sourceWidth, sourceHeight,
178 targetLeft, targetTop, sourceChar, sourceForeColor, sourceBackColor);
181 public static ConsoleKeyInfo ReadKey (bool intercept)
183 return driver.ReadKey (intercept);
186 public static void ResetColor ()
188 driver.ResetColor ();
191 public static void SetBufferSize (int width, int height)
193 driver.SetBufferSize (width, height);
196 public static void SetCursorPosition (int left, int top)
198 driver.SetCursorPosition (left, top);
201 public static void SetWindowPosition (int left, int top)
203 driver.SetWindowPosition (left, top);
206 public static void SetWindowSize (int width, int height)
208 driver.SetWindowSize (width, height);
211 [MethodImplAttribute(MethodImplOptions.InternalCall)]
212 internal static extern bool Isatty (IntPtr handle);
214 [MethodImplAttribute(MethodImplOptions.InternalCall)]
215 internal static extern int InternalKeyAvailable (int ms_timeout);
217 [MethodImplAttribute(MethodImplOptions.InternalCall)]
218 internal static extern bool TtySetup (string teardown);
220 [MethodImplAttribute(MethodImplOptions.InternalCall)]
221 internal static extern bool SetEcho (bool wantEcho);
223 [MethodImplAttribute(MethodImplOptions.InternalCall)]
224 internal static extern bool SetBreak (bool wantBreak);