updating to the latest module.
[mono.git] / mcs / class / corlib / System / ConsoleDriver.cs
1 //
2 // System.ConsoleDriver
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30 #if NET_2_0
31 using System.IO;
32 using System.Runtime.CompilerServices;
33
34 namespace System {
35         class ConsoleDriver {
36                 static IConsoleDriver driver;
37
38                 static ConsoleDriver ()
39                 {
40                         if (Environment.IsRunningOnWindows) {
41                                 driver = new WindowsConsoleDriver ();
42                         } else {
43                                 driver = new TermInfoDriver (Environment.GetEnvironmentVariable ("TERM"));
44                         }
45                 }
46
47                 public static bool Echo {
48                         get { return driver.Echo; }
49                         set { driver.Echo = value; }
50                 }
51
52                 public static bool Initialized {
53                         get { return driver.Initialized; }
54                 }
55
56                 public static ConsoleColor BackgroundColor {
57                         get { return driver.BackgroundColor; }
58                         set {
59                                 if (value < ConsoleColor.Black || value > ConsoleColor.White)
60                                         throw new ArgumentOutOfRangeException ("value", "Not a ConsoleColor value.");
61
62                                 driver.BackgroundColor = value;
63                         }
64                 }
65
66                 public static int BufferHeight {
67                         get { return driver.BufferHeight; }
68                         set { driver.BufferHeight = value; }
69                 }
70
71                 public static int BufferWidth {
72                         get { return driver.BufferWidth; }
73                         set { driver.BufferWidth = value; }
74                 }
75
76                 public static bool CapsLock {
77                         get { return driver.CapsLock; }
78                 }
79
80                 public static int CursorLeft {
81                         get { return driver.CursorLeft; }
82                         set { driver.CursorLeft = value; }
83                 }
84
85                 public static int CursorSize {
86                         get { return driver.CursorSize; }
87                         set { driver.CursorSize = value; }
88                 }
89
90                 public static int CursorTop {
91                         get { return driver.CursorTop; }
92                         set { driver.CursorTop = value; }
93                 } 
94                 
95                 public static bool CursorVisible {
96                         get { return driver.CursorVisible; }
97                         set { driver.CursorVisible = value; }
98                 }
99
100                 public static bool KeyAvailable {
101                         get { return driver.KeyAvailable; }
102                 }
103
104                 public static ConsoleColor ForegroundColor {
105                         get { return driver.ForegroundColor; }
106                         set {
107                                 if (value < ConsoleColor.Black || value > ConsoleColor.White)
108                                         throw new ArgumentOutOfRangeException ("value", "Not a ConsoleColor value.");
109
110                                 driver.ForegroundColor = value;
111                         }
112                 }
113
114                 public static int LargestWindowHeight {
115                         get { return driver.LargestWindowHeight; }
116                 }
117
118                 public static int LargestWindowWidth {
119                         get { return driver.LargestWindowWidth; }
120                 }
121
122                 public static bool NumberLock {
123                         get { return driver.NumberLock; }
124                 }
125
126                 public static string Title {
127                         get { return driver.Title; }
128                         set { driver.Title = value; }
129                 }
130
131                 public static bool TreatControlCAsInput {
132                         get { return driver.TreatControlCAsInput; }
133                         set { driver.TreatControlCAsInput = value; }
134                 } 
135
136                 public static int WindowHeight {
137                         get { return driver.WindowHeight; }
138                         set { driver.WindowHeight = value; }
139                 }
140
141                 public static int WindowLeft {
142                         get { return driver.WindowLeft; }
143                         set { driver.WindowLeft = value; }
144                 }
145
146                 public static int WindowTop {
147                         get { return driver.WindowTop; }
148                         set { driver.WindowTop = value; }
149                 }
150
151                 public static int WindowWidth {
152                         get { return driver.WindowWidth; }
153                         set { driver.WindowWidth = value; }
154                 }
155
156                 public static void Beep (int frequency, int duration)
157                 {
158                         driver.Beep (frequency, duration);
159                 }
160                 
161                 public static void Clear ()
162                 {
163                         driver.Clear ();
164                 }
165
166                 public static void MoveBufferArea (int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight,
167                                         int targetLeft, int targetTop)
168                 {
169                         MoveBufferArea (sourceLeft, sourceTop, sourceWidth, sourceHeight,
170                                         targetLeft, targetTop, ' ', 0, 0);
171                 }
172
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)
176                 {
177                         driver.MoveBufferArea (sourceLeft, sourceTop, sourceWidth, sourceHeight,
178                                         targetLeft, targetTop, sourceChar, sourceForeColor, sourceBackColor);
179                 }
180
181                 public static ConsoleKeyInfo ReadKey (bool intercept)
182                 {
183                         return driver.ReadKey (intercept);
184                 }
185
186                 public static void ResetColor ()
187                 {
188                         driver.ResetColor ();
189                 }
190
191                 public static void SetBufferSize (int width, int height)
192                 {
193                         driver.SetBufferSize (width, height);
194                 }
195
196                 public static void SetCursorPosition (int left, int top)
197                 {
198                         driver.SetCursorPosition (left, top);
199                 }
200
201                 public static void SetWindowPosition (int left, int top)
202                 {
203                         driver.SetWindowPosition (left, top);
204                 }
205
206                 public static void SetWindowSize (int width, int height)
207                 {
208                         driver.SetWindowSize (width, height);
209                 }
210
211                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
212                 internal static extern bool Isatty (IntPtr handle);
213
214                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
215                 internal static extern int InternalKeyAvailable (int ms_timeout);
216
217                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
218                 internal static extern bool TtySetup (string teardown);
219
220                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
221                 internal static extern bool SetEcho (bool wantEcho);
222
223                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
224                 internal static extern bool SetBreak (bool wantBreak);
225         }
226 }
227 #endif
228