EraConsoleInstance.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. using System.Drawing;
  2. using System.Text;
  3. using System.Threading;
  4. using NTERA.Console.RenderItem;
  5. using NTERA.Core;
  6. using NTERA.Core.Interop;
  7. namespace NTERA.Console
  8. {
  9. public class EraConsoleInstance : IConsole
  10. {
  11. public ConsoleRenderer Renderer { get; }
  12. public IScriptEngine ScriptEngine { get; }
  13. public AutoResetEvent InputResetEvent { get; protected set; } = new AutoResetEvent(false);
  14. public Color ForeColor = Color.White;
  15. public void AddText(string text, Color? color = null, bool print = true)
  16. {
  17. var item = new TextRenderItem(text)
  18. {
  19. TextBrush = new SolidBrush(color ?? ForeColor),
  20. Alignment = Alignment
  21. };
  22. if (print)
  23. Renderer.PrintItem(item);
  24. else
  25. Renderer.WriteItem(item);
  26. }
  27. public bool IsRunning { get; set; } = true;
  28. public bool Enabled { get; set; } = true;
  29. public string LastInput { get; protected set; }
  30. public EraConsoleInstance(ConsoleRenderer renderer, IScriptEngine scriptEngine)
  31. {
  32. Renderer = renderer;
  33. ScriptEngine = scriptEngine;
  34. }
  35. public InputRequest CurrentRequest { get; set; }
  36. public void GiveInput(string input)
  37. {
  38. LastInput = input;
  39. PrintSingleLine(input);
  40. InputResetEvent.Set();
  41. }
  42. public void PrintError(string message)
  43. {
  44. System.Console.Write("ERROR: " + message + "\n");
  45. AddText(message, Color.Red);
  46. }
  47. public void PrintSystemLine(string message)
  48. {
  49. System.Console.Write("INFO: " + message + "\n");
  50. AddText(message, Color.Gray);
  51. }
  52. public void DebugClearTraceLog()
  53. {
  54. }
  55. public void DebugAddTraceLog(string message)
  56. {
  57. }
  58. public void DebugRemoveTraceLog()
  59. {
  60. }
  61. public bool RunERBFromMemory { get; set; }
  62. public void PrintWarning(string message, int level)
  63. {
  64. System.Console.Write("WARNING: " + message + "\n");
  65. AddText(message, Color.Yellow);
  66. }
  67. public void setStBar(string bar)
  68. {
  69. }
  70. public void ReadAnyKey()
  71. {
  72. IsRunning = false;
  73. Thread.Sleep(500);
  74. IsRunning = true;
  75. }
  76. public void WaitInput(InputRequest request)
  77. {
  78. CurrentRequest = request;
  79. IsRunning = false;
  80. InputResetEvent.WaitOne();
  81. CurrentRequest = null;
  82. IsRunning = true;
  83. }
  84. public void ResetStyle()
  85. {
  86. ForeColor = Color.White;
  87. }
  88. public void OutputLog(string log)
  89. {
  90. AddText(log);
  91. }
  92. public bool noOutputLog { get; set; }
  93. public void ThrowTitleError(bool something)
  94. {
  95. }
  96. public void PrintBar()
  97. {
  98. printCustomBar("-");
  99. }
  100. public void PrintSingleLine(string line, bool temporary = false)
  101. {
  102. AddText(line, print: true);
  103. }
  104. public void RefreshStrings(bool something)
  105. {
  106. }
  107. public void SetWindowTitle(string title)
  108. {
  109. }
  110. public void ThrowError(bool playSound)
  111. {
  112. }
  113. public void PrintErrorButton(string message)
  114. {
  115. }
  116. protected StringBuilder bodyBuilder = new StringBuilder();
  117. public void Write(string message)
  118. {
  119. //message.Replace(' ', ' ');
  120. //bodyBuilder.Append(message);
  121. AddText(message, print: false);
  122. }
  123. public void NewLine()
  124. {
  125. AddText(bodyBuilder.ToString());
  126. bodyBuilder.Length = 0;
  127. }
  128. public bool UseSetColorStyle { get; set; }
  129. public void PrintC(string message, bool something)
  130. {
  131. AddText(message);
  132. }
  133. public DisplayLineAlignment Alignment { get; set; } = DisplayLineAlignment.LEFT;
  134. public void ClearLine(int line)
  135. {
  136. }
  137. public void PrintTemporaryLine(string line)
  138. {
  139. AddText(line);
  140. }
  141. public bool updatedGeneration { get; set; }
  142. public void PrintFlush(bool something)
  143. {
  144. }
  145. public bool LastLineIsTemporary { get; set; }
  146. public bool LastLineIsEmpty { get; set; }
  147. public void ReloadErbFinished()
  148. {
  149. }
  150. public bool MesSkip { get; set; }
  151. public Color bgColor { get; set; }
  152. public ConsoleRedraw Redraw { get; set; }
  153. public bool EmptyLine { get; set; }
  154. public string getStBar(string something)
  155. {
  156. return "";
  157. }
  158. public void PrintButton(string something, long something1)
  159. {
  160. Write(something);
  161. }
  162. public void PrintButton(string something, string something1)
  163. {
  164. Write(something);
  165. }
  166. public void PrintButtonC(string something, long something1, bool something2)
  167. {
  168. Write(something);
  169. }
  170. public void PrintButtonC(string something, string something1, bool something2)
  171. {
  172. Write(something);
  173. }
  174. public void PrintPlain(string message)
  175. {
  176. AddText(message);
  177. }
  178. public void printCustomBar(string bar)
  179. {
  180. AddText("".PadRight(300, bar[0]));
  181. }
  182. public bool UseUserStyle { get; set; }
  183. public void Quit()
  184. {
  185. }
  186. public void PrintHtml(string html, bool newline)
  187. {
  188. foreach (var item in HtmlParser.ParseHtml(html, ScriptEngine.GetImage))
  189. Renderer.PrintItem(item);
  190. }
  191. public void PrintImg(string img)
  192. {
  193. var image = ScriptEngine.GetImage(img);
  194. Renderer.WriteItem(new ImageRenderItem(image.Bitmap, image.Rectangle, alignment: Alignment));
  195. }
  196. public void PrintShape(string shape, int[] param)
  197. {
  198. AddText(shape);
  199. }
  200. public void DebugPrint(string message)
  201. {
  202. AddText(message);
  203. }
  204. public void DebugNewLine()
  205. {
  206. }
  207. public void DebugClear()
  208. {
  209. }
  210. public void ReadAnyKey(bool something, bool something2)
  211. {
  212. Thread.Sleep(500);
  213. }
  214. public void SetStringStyle(Color color)
  215. {
  216. ForeColor = color;
  217. }
  218. public void SetStringStyle(FontStyle fontStyle)
  219. {
  220. }
  221. public void SetBgColor(Color color)
  222. {
  223. }
  224. public void SetToolTipColor(Color fc, Color bc)
  225. {
  226. }
  227. public void SetToolTipDelay(int delay)
  228. {
  229. }
  230. public void SetToolTipDuration(int duration)
  231. {
  232. }
  233. public void SetFont(string font)
  234. {
  235. }
  236. public void SetRedraw(long value)
  237. {
  238. }
  239. public int NewButtonGeneration { get; set; }
  240. public void UpdateGeneration()
  241. {
  242. }
  243. public string GetWindowTitle()
  244. {
  245. return "title";
  246. }
  247. public long LineCount { get; set; }
  248. public string getDefStBar()
  249. {
  250. return "";
  251. }
  252. public bool IsTimeOut { get; set; }
  253. }
  254. }