EraConsoleInstance.cs 5.5 KB

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