5 // Dietmar Maurer (dietmar@ximian.com)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
8 // (C) Ximian, Inc. http://www.ximian.com
9 // (C) 2004,2005 Novell, Inc. (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45 private static TextWriter stdout;
46 private static TextWriter stderr;
47 private static TextReader stdin;
52 Encoding.InternalCodePage (ref code_page);
55 if (((int) Environment.Platform) == 128){
57 // On Unix systems (128), do not output the
58 // UTF-8 ZWNBSP (zero-width non-breaking space).
60 if (code_page == UTF8Encoding.UTF8_CODE_PAGE || ((code_page & 0x10000000) != 0))
61 encoding = Encoding.UTF8Unmarked;
63 encoding = Encoding.Default;
66 // On Windows, follow the Windows tradition
68 encoding = Encoding.Default;
71 stderr = new UnexceptionalStreamWriter (OpenStandardError (0), encoding);
72 ((StreamWriter)stderr).AutoFlush = true;
73 stderr = TextWriter.Synchronized (stderr, true);
75 stdout = new UnexceptionalStreamWriter (OpenStandardOutput (0), encoding);
76 ((StreamWriter)stdout).AutoFlush = true;
77 stdout = TextWriter.Synchronized (stdout, true);
79 stdin = new UnexceptionalStreamReader (OpenStandardInput (0), encoding);
80 stdin = TextReader.Synchronized (stdin);
89 public static TextWriter Error {
95 public static TextWriter Out {
101 public static TextReader In {
107 public static Stream OpenStandardError ()
109 return OpenStandardError (0);
112 public static Stream OpenStandardError (int bufferSize)
115 return new FileStream (MonoIO.ConsoleError, FileAccess.Write, false, bufferSize, false, bufferSize == 0);
116 } catch (IOException) {
117 return new NullStream ();
121 public static Stream OpenStandardInput ()
123 return OpenStandardInput (0);
126 public static Stream OpenStandardInput (int bufferSize)
129 return new FileStream (MonoIO.ConsoleInput, FileAccess.Read, false, bufferSize, false, bufferSize == 0);
130 } catch (IOException) {
131 return new NullStream ();
135 public static Stream OpenStandardOutput ()
137 return OpenStandardOutput (0);
140 public static Stream OpenStandardOutput (int bufferSize)
143 return new FileStream (MonoIO.ConsoleOutput, FileAccess.Write, false, bufferSize, false, bufferSize == 0);
144 } catch (IOException) {
145 return new NullStream ();
149 public static void SetError (TextWriter newError)
151 if (newError == null)
152 throw new ArgumentNullException ("newError");
157 public static void SetIn (TextReader newIn)
160 throw new ArgumentNullException ("newIn");
165 public static void SetOut (TextWriter newOut)
168 throw new ArgumentNullException ("newOut");
173 public static void Write (bool value)
175 stdout.Write (value);
178 public static void Write (char value)
180 stdout.Write (value);
183 public static void Write (char[] value)
185 stdout.Write (value);
188 public static void Write (decimal value)
190 stdout.Write (value);
193 public static void Write (double value)
195 stdout.Write (value);
198 public static void Write (int value)
200 stdout.Write (value);
203 public static void Write (long value)
205 stdout.Write (value);
208 public static void Write (object value)
210 stdout.Write (value);
213 public static void Write (float value)
215 stdout.Write (value);
218 public static void Write (string value)
220 stdout.Write (value);
223 [CLSCompliant (false)]
224 public static void Write (uint value)
226 stdout.Write (value);
229 [CLSCompliant (false)]
230 public static void Write (ulong value)
232 stdout.Write (value);
235 public static void Write (string format, object arg0)
237 stdout.Write (format, arg0);
240 public static void Write (string format, params object[] arg)
242 stdout.Write (format, arg);
245 public static void Write (char[] buffer, int index, int count)
247 stdout.Write (buffer, index, count);
250 public static void Write (string format, object arg0, object arg1)
252 stdout.Write (format, arg0, arg1);
255 public static void Write (string format, object arg0, object arg1, object arg2 )
257 stdout.Write (format, arg0, arg1, arg2);
260 #if ! BOOTSTRAP_WITH_OLDLIB
261 [CLSCompliant (false)]
262 public static void Write (string format, object arg0, object arg1, object arg2, object arg3, __arglist)
264 ArgIterator iter = new ArgIterator (__arglist);
265 int argCount = iter.GetRemainingCount();
267 object[] args = new object [argCount + 4];
272 for (int i = 0; i < argCount; i++) {
273 TypedReference typedRef = iter.GetNextArg ();
274 args [i + 4] = TypedReference.ToObject (typedRef);
277 stdout.Write (String.Format (format, args));
281 public static void WriteLine ()
286 public static void WriteLine (bool value)
288 stdout.WriteLine (value);
291 public static void WriteLine (char value)
293 stdout.WriteLine (value);
296 public static void WriteLine (char[] value)
298 stdout.WriteLine (value);
301 public static void WriteLine (decimal value)
303 stdout.WriteLine (value);
306 public static void WriteLine (double value)
308 stdout.WriteLine (value);
311 public static void WriteLine (int value)
313 stdout.WriteLine (value);
316 public static void WriteLine (long value)
318 stdout.WriteLine (value);
321 public static void WriteLine (object value)
323 stdout.WriteLine (value);
326 public static void WriteLine (float value)
328 stdout.WriteLine (value);
331 public static void WriteLine (string value)
333 stdout.WriteLine (value);
336 [CLSCompliant (false)]
337 public static void WriteLine (uint value)
339 stdout.WriteLine (value);
342 [CLSCompliant (false)]
343 public static void WriteLine (ulong value)
345 stdout.WriteLine (value);
348 public static void WriteLine (string format, object arg0)
350 stdout.WriteLine (format, arg0);
353 public static void WriteLine (string format, params object[] arg)
355 stdout.WriteLine (format, arg);
358 public static void WriteLine (char[] buffer, int index, int count)
360 stdout.WriteLine (buffer, index, count);
363 public static void WriteLine (string format, object arg0, object arg1)
365 stdout.WriteLine (format, arg0, arg1);
368 public static void WriteLine (string format, object arg0, object arg1, object arg2)
370 stdout.WriteLine (format, arg0, arg1, arg2);
373 #if ! BOOTSTRAP_WITH_OLDLIB
374 [CLSCompliant (false)]
375 public static void WriteLine (string format, object arg0, object arg1, object arg2, object arg3, __arglist)
377 ArgIterator iter = new ArgIterator (__arglist);
378 int argCount = iter.GetRemainingCount();
380 object[] args = new object [argCount + 4];
385 for (int i = 0; i < argCount; i++) {
386 TypedReference typedRef = iter.GetNextArg ();
387 args [i + 4] = TypedReference.ToObject (typedRef);
390 stdout.WriteLine (String.Format (format, args));
394 public static int Read ()
396 return stdin.Read ();
399 public static string ReadLine ()
403 if (ConsoleDriver.Initialized) {
404 prevEcho = ConsoleDriver.Echo;
405 ConsoleDriver.Echo = true;
408 return stdin.ReadLine ();
410 if (ConsoleDriver.Initialized)
411 ConsoleDriver.Echo = prevEcho;
416 // On windows, for en-US the Default is Windows-1252, while input/output is IBM437
417 // We might want to initialize these fields in the ConsoleDriver instead.
418 static Encoding inputEncoding = Encoding.Default;
419 static Encoding outputEncoding = Encoding.Default;
421 public static Encoding InputEncoding {
422 get { return inputEncoding; }
423 set { inputEncoding = value; }
426 public static Encoding OutputEncoding {
427 get { return outputEncoding; }
428 set { outputEncoding = value; }
431 public static ConsoleColor BackgroundColor {
432 get { return ConsoleDriver.BackgroundColor; }
433 set { ConsoleDriver.BackgroundColor = value; }
436 public static int BufferHeight {
437 get { return ConsoleDriver.BufferHeight; }
438 set { ConsoleDriver.BufferHeight = value; }
441 public static int BufferWidth {
442 get { return ConsoleDriver.BufferWidth; }
443 set { ConsoleDriver.BufferWidth = value; }
446 public static int CursorLeft {
447 get { return ConsoleDriver.CursorLeft; }
448 set { ConsoleDriver.CursorLeft = value; }
451 public static int CursorTop {
452 get { return ConsoleDriver.CursorTop; }
453 set { ConsoleDriver.CursorTop = value; }
456 public static bool CursorVisible {
457 get { return ConsoleDriver.CursorVisible; }
458 set { ConsoleDriver.CursorVisible = value; }
461 public static ConsoleColor ForegroundColor {
462 get { return ConsoleDriver.ForegroundColor; }
463 set { ConsoleDriver.ForegroundColor = value; }
466 public static bool KeyAvailable {
467 get { return ConsoleDriver.KeyAvailable; }
470 public static string Title {
471 get { return ConsoleDriver.Title; }
472 set { ConsoleDriver.Title = value; }
475 public static bool TreatControlCAsInput {
476 get { return ConsoleDriver.TreatControlCAsInput; }
477 set { ConsoleDriver.TreatControlCAsInput = value; }
480 public static int WindowHeight {
481 get { return ConsoleDriver.WindowHeight; }
482 set { ConsoleDriver.WindowHeight = value; }
485 public static int WindowLeft {
486 get { return ConsoleDriver.WindowLeft; }
487 set { ConsoleDriver.WindowLeft = value; }
490 public static int WindowTop {
491 get { return ConsoleDriver.WindowTop; }
492 set { ConsoleDriver.WindowTop = value; }
495 public static int WindowWidth {
496 get { return ConsoleDriver.WindowWidth; }
497 set { ConsoleDriver.WindowWidth = value; }
500 public static void Beep ()
505 public static void Beep (int frequency, int duration)
507 if (frequency < 37 || frequency > 32767)
508 throw new ArgumentOutOfRangeException ("frequency");
511 throw new ArgumentOutOfRangeException ("duration");
513 ConsoleDriver.Beep (frequency, duration);
516 public static void Clear ()
518 ConsoleDriver.Clear ();
522 public static void MoveBufferArea (int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight,
523 int targetLeft, int targetTop)
525 throw new NotImplementedException ();
529 public static void MoveBufferArea (int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight,
530 int targetLeft, int targetTop, Char sourceChar,
531 ConsoleColor sourceForeColor, ConsoleColor sourceBackColor)
533 throw new NotImplementedException ();
536 public static ConsoleKeyInfo ReadKey ()
538 return ReadKey (false);
541 public static ConsoleKeyInfo ReadKey (bool intercept)
543 return ConsoleDriver.ReadKey (intercept);
546 public static void ResetColor ()
548 ConsoleDriver.ResetColor ();
551 public static void SetBufferSize (int width, int height)
553 ConsoleDriver.SetBufferSize (width, height);
556 public static void SetCursorPosition (int left, int top)
558 ConsoleDriver.SetCursorPosition (left, top);
561 public static void SetWindowPosition (int left, int top)
563 ConsoleDriver.SetWindowPosition (left, top);
566 public static void SetWindowSize (int width, int height)
568 ConsoleDriver.SetWindowSize (width, height);
572 //public event ConsoleCancelEventHandler CancelKeyPress;