Program.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using ConFrames;
  7. namespace Sample
  8. {
  9. class Window1 : Window
  10. {
  11. public Window1() :base("Window 1", new Rect(0, 0, 50, 20))
  12. {
  13. }
  14. public override void OnPaint(PaintContext ctx)
  15. {
  16. ctx.ForegroundColor = ConsoleColor.Cyan;
  17. for (int i=0; i<20; i++)
  18. {
  19. ctx.WriteLine("This is line {0}", _baseNumber + i);
  20. }
  21. }
  22. public override bool OnKey(ConsoleKeyInfo key)
  23. {
  24. _baseNumber += 5;
  25. Invalidate();
  26. return base.OnKey(key);
  27. }
  28. int _baseNumber = 1;
  29. }
  30. class Window2 : Window
  31. {
  32. public Window2() : base("Window 2", new Rect(50, 0, 50, 20))
  33. {
  34. CursorVisible = true;
  35. CursorX = 5;
  36. CursorY = 1;
  37. }
  38. public override void OnPaint(PaintContext ctx)
  39. {
  40. ctx.WriteLine("Type something, or use Ctrl+Tab to switch windows");
  41. ctx.Write("blah>");
  42. }
  43. public override bool OnKey(ConsoleKeyInfo key)
  44. {
  45. if (key.KeyChar != 0)
  46. {
  47. var ctx = GetPaintContext();
  48. ctx.SetChar(CursorX++, CursorY, key.KeyChar);
  49. }
  50. else
  51. {
  52. switch (key.Key)
  53. {
  54. case ConsoleKey.LeftArrow:
  55. if (CursorX > 0)
  56. CursorX--;
  57. break;
  58. case ConsoleKey.RightArrow:
  59. if (CursorX < ClientSize.Width)
  60. CursorX++;
  61. break;
  62. }
  63. }
  64. return base.OnKey(key);
  65. }
  66. }
  67. class CommandWindow : ConsoleWindow
  68. {
  69. public CommandWindow() : base("Command", new Rect(0, 20, 100, 20))
  70. {
  71. Prompt = ">";
  72. WriteLine("Type something and press enter. Use Shift+Up/Down to scroll");
  73. }
  74. protected override void OnCommand(string command)
  75. {
  76. WriteLine("You typed: '{0}'", command);
  77. // Call base to update command history (up/down arrow)
  78. base.OnCommand(command);
  79. }
  80. }
  81. class Program
  82. {
  83. static void Main(string[] args)
  84. {
  85. var desktop = new Desktop(100, 40);
  86. var w1 = new Window1();
  87. var w2 = new Window2();
  88. var cmd = new CommandWindow();
  89. w1.Open(desktop);
  90. w2.Open(desktop);
  91. cmd.Open(desktop);
  92. desktop.Process();
  93. }
  94. }
  95. }