Advertisement
filmee24

Controller Class for ShellEmulator

Apr 17th, 2016
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.59 KB | None | 0 0
  1. using System.Drawing;
  2. using System.Threading.Tasks;
  3. using UILibrary;
  4.  
  5.     public static class Shell
  6.     {
  7.         public static Color ForeColor
  8.         {
  9.             get { return _shell.ShellTextForeColor; }
  10.             set { _shell.ShellTextForeColor = value; }
  11.         }
  12.  
  13.         public static Color BackColor
  14.         {
  15.             get { return _shell.ShellTextBackColor; }
  16.             set { _shell.ShellTextBackColor = value; }
  17.         }
  18.  
  19.         public static Font Font
  20.         {
  21.             get { return _shell.ShellTextFont; }
  22.             set { _shell.ShellTextFont = value; }
  23.         }
  24.  
  25.         private static ShellControl _shell;
  26.  
  27.         public static void Init(ShellControl shell)
  28.         {
  29.             _shell = shell;
  30.         }
  31.  
  32.         public static void Write(object obj)
  33.         {
  34.             _shell.WriteText(obj.ToString());
  35.         }
  36.  
  37.         public static void WriteLine(object obj)
  38.         {
  39.             _shell.WriteText(obj.ToString() + "\r");
  40.         }
  41.  
  42.         public static Task<string> ReadLineAsync()
  43.         {
  44.             EventCommandEntered handler = null;
  45.             string value = null;
  46.             var tcs = new TaskCompletionSource<string>();
  47.  
  48.             handler = new EventCommandEntered((s, e) =>
  49.             {
  50.                 value = e.Command;
  51.                 tcs.SetResult(value);
  52.  
  53.                 _shell.CommandEntered -= handler;
  54.             });
  55.  
  56.             _shell.CommandEntered += handler;
  57.  
  58.             return tcs.Task;
  59.         }
  60.  
  61.         public static void Clear()
  62.         {
  63.             _shell.Clear();
  64.         }
  65.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement