EraConsoleInstance.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. AddText(message, Color.Red);
  45. }
  46. public void PrintSystemLine(string message)
  47. {
  48. AddText(message, Color.Gray);
  49. }
  50. public void DebugClearTraceLog()
  51. {
  52. }
  53. public void DebugAddTraceLog(string message)
  54. {
  55. }
  56. public void DebugRemoveTraceLog()
  57. {
  58. }
  59. public bool RunERBFromMemory { get; set; }
  60. public void PrintWarning(string message, int level)
  61. {
  62. AddText(message, Color.Yellow);
  63. }
  64. public void setStBar(string bar)
  65. {
  66. }
  67. public void ReadAnyKey()
  68. {
  69. IsRunning = false;
  70. Thread.Sleep(500);
  71. IsRunning = true;
  72. }
  73. public void WaitInput(InputRequest request)
  74. {
  75. CurrentRequest = request;
  76. IsRunning = false;
  77. InputResetEvent.WaitOne();
  78. CurrentRequest = null;
  79. IsRunning = true;
  80. }
  81. public void ResetStyle()
  82. {
  83. }
  84. public void OutputLog(string log)
  85. {
  86. AddText(log);
  87. }
  88. public bool noOutputLog { get; set; }
  89. public void ThrowTitleError(bool something)
  90. {
  91. }
  92. public void PrintBar()
  93. {
  94. printCustomBar("-");
  95. }
  96. public void PrintSingleLine(string line, bool temporary = false)
  97. {
  98. AddText(line, print: true);
  99. }
  100. public void RefreshStrings(bool something)
  101. {
  102. }
  103. public void SetWindowTitle(string title)
  104. {
  105. }
  106. public void ThrowError(bool playSound)
  107. {
  108. }
  109. public void PrintErrorButton(string message)
  110. {
  111. }
  112. protected StringBuilder bodyBuilder = new StringBuilder();
  113. public void Write(string message)
  114. {
  115. //message.Replace(' ', ' ');
  116. //bodyBuilder.Append(message);
  117. AddText(message, print: false);
  118. }
  119. public void NewLine()
  120. {
  121. AddText(bodyBuilder.ToString());
  122. bodyBuilder.Length = 0;
  123. }
  124. public bool UseSetColorStyle { get; set; }
  125. public void PrintC(string message, bool something)
  126. {
  127. AddText(message);
  128. }
  129. public DisplayLineAlignment Alignment { get; set; } = DisplayLineAlignment.LEFT;
  130. public void deleteLine(int line)
  131. {
  132. }
  133. public void PrintTemporaryLine(string line)
  134. {
  135. AddText(line);
  136. }
  137. public bool updatedGeneration { get; set; }
  138. public void PrintFlush(bool something)
  139. {
  140. }
  141. public bool LastLineIsTemporary { get; set; }
  142. public bool LastLineIsEmpty { get; set; }
  143. public void ReloadErbFinished()
  144. {
  145. }
  146. public bool MesSkip { get; set; }
  147. public Color bgColor { get; set; }
  148. public ConsoleRedraw Redraw { get; set; }
  149. public bool EmptyLine { get; set; }
  150. public string getStBar(string something)
  151. {
  152. return "";
  153. }
  154. public void PrintButton(string something, long something1)
  155. {
  156. Write(something);
  157. }
  158. public void PrintButton(string something, string something1)
  159. {
  160. Write(something);
  161. }
  162. public void PrintButtonC(string something, long something1, bool something2)
  163. {
  164. Write(something);
  165. }
  166. public void PrintButtonC(string something, string something1, bool something2)
  167. {
  168. Write(something);
  169. }
  170. public void PrintPlain(string message)
  171. {
  172. AddText(message);
  173. }
  174. public void printCustomBar(string bar)
  175. {
  176. AddText("".PadRight(300, bar[0]));
  177. }
  178. public bool UseUserStyle { get; set; }
  179. public void Quit()
  180. {
  181. }
  182. public void PrintHtml(string html, bool newline)
  183. {
  184. foreach (var item in HtmlParser.ParseHtml(html, ScriptEngine.GetImage))
  185. Renderer.PrintItem(item);
  186. }
  187. public void PrintImg(string img)
  188. {
  189. var image = ScriptEngine.GetImage(img);
  190. Renderer.WriteItem(new ImageRenderItem(image.Bitmap, image.Rectangle, alignment: Alignment));
  191. }
  192. public void PrintShape(string shape, int[] param)
  193. {
  194. AddText(shape);
  195. }
  196. public void DebugPrint(string message)
  197. {
  198. AddText(message);
  199. }
  200. public void DebugNewLine()
  201. {
  202. }
  203. public void DebugClear()
  204. {
  205. }
  206. public void ReadAnyKey(bool something, bool something2)
  207. {
  208. Thread.Sleep(500);
  209. }
  210. public void SetStringStyle(Color color)
  211. {
  212. ForeColor = color;
  213. }
  214. public void SetStringStyle(FontStyle fontStyle)
  215. {
  216. }
  217. public void SetBgColor(Color color)
  218. {
  219. }
  220. public void SetToolTipColor(Color fc, Color bc)
  221. {
  222. }
  223. public void SetToolTipDelay(int delay)
  224. {
  225. }
  226. public void SetToolTipDuration(int duration)
  227. {
  228. }
  229. public void SetFont(string font)
  230. {
  231. }
  232. public void SetRedraw(long value)
  233. {
  234. }
  235. public int NewButtonGeneration { get; set; }
  236. public void UpdateGeneration()
  237. {
  238. }
  239. public string GetWindowTitle()
  240. {
  241. return "title";
  242. }
  243. public long LineCount { get; set; }
  244. public string getDefStBar()
  245. {
  246. return "";
  247. }
  248. public bool IsTimeOut { get; set; }
  249. }
  250. }