using System.Drawing; using System.Text; using System.Threading; using NTERA.Console.RenderItem; using NTERA.Core; using NTERA.Core.Interop; namespace NTERA.Console { public class EraConsoleInstance : IConsole { public ConsoleRenderer Renderer { get; } public IScriptEngine ScriptEngine { get; } public AutoResetEvent InputResetEvent { get; protected set; } = new AutoResetEvent(false); public Color ForeColor = Color.White; public void AddText(string text, Color? color = null, bool print = true) { var item = new TextRenderItem(text) { TextBrush = new SolidBrush(color ?? ForeColor), Alignment = Alignment }; if (print) Renderer.PrintItem(item); else Renderer.WriteItem(item); } public bool IsRunning { get; set; } = true; public bool Enabled { get; set; } = true; public EraConsoleInstance(ConsoleRenderer renderer, IScriptEngine scriptEngine) { Renderer = renderer; ScriptEngine = scriptEngine; } public InputRequest CurrentRequest { get; set; } public void GiveInput(string input) { PrintSingleLine(input); InputResetEvent.Set(); } public void PrintError(string message) { AddText(message, Color.Red); } public void PrintSystemLine(string message) { AddText(message, Color.Gray); } public void DebugClearTraceLog() { } public void DebugAddTraceLog(string message) { } public void DebugRemoveTraceLog() { } public bool RunERBFromMemory { get; set; } public void PrintWarning(string message, int level) { AddText(message, Color.Yellow); } public void setStBar(string bar) { } public void ReadAnyKey() { IsRunning = false; Thread.Sleep(500); IsRunning = true; } public void WaitInput(InputRequest request) { CurrentRequest = request; IsRunning = false; InputResetEvent.WaitOne(); CurrentRequest = null; IsRunning = true; } public void ResetStyle() { } public void OutputLog(string log) { AddText(log); } public bool noOutputLog { get; set; } public void ThrowTitleError(bool something) { } public void PrintBar() { printCustomBar("-"); } public void PrintSingleLine(string line, bool temporary = false) { AddText(line, print: true); } public void RefreshStrings(bool something) { } public void SetWindowTitle(string title) { } public void ThrowError(bool playSound) { } public void PrintErrorButton(string message) { } protected StringBuilder bodyBuilder = new StringBuilder(); public void Write(string message) { //message.Replace(' ', ' '); //bodyBuilder.Append(message); AddText(message, print: false); } public void NewLine() { AddText(bodyBuilder.ToString()); bodyBuilder.Length = 0; } public bool UseSetColorStyle { get; set; } public void PrintC(string message, bool something) { AddText(message); } public DisplayLineAlignment Alignment { get; set; } = DisplayLineAlignment.LEFT; public void deleteLine(int line) { } public void PrintTemporaryLine(string line) { AddText(line); } public bool updatedGeneration { get; set; } public void PrintFlush(bool something) { } public bool LastLineIsTemporary { get; set; } public bool LastLineIsEmpty { get; set; } public void ReloadErbFinished() { } public bool MesSkip { get; set; } public Color bgColor { get; set; } public ConsoleRedraw Redraw { get; set; } public bool EmptyLine { get; set; } public string getStBar(string something) { return ""; } public void PrintButton(string something, long something1) { Write(something); } public void PrintButton(string something, string something1) { Write(something); } public void PrintButtonC(string something, long something1, bool something2) { Write(something); } public void PrintButtonC(string something, string something1, bool something2) { Write(something); } public void PrintPlain(string message) { AddText(message); } public void printCustomBar(string bar) { AddText("".PadRight(300, bar[0])); } public bool UseUserStyle { get; set; } public void Quit() { } public void PrintHtml(string html, bool newline) { foreach (var item in HtmlParser.ParseHtml(html, ScriptEngine.GetImage)) Renderer.PrintItem(item); } public void PrintImg(string img) { var image = ScriptEngine.GetImage(img); Renderer.WriteItem(new ImageRenderItem(image.Bitmap, image.Rectangle, alignment: Alignment)); } public void PrintShape(string shape, int[] param) { AddText(shape); } public void DebugPrint(string message) { AddText(message); } public void DebugNewLine() { } public void DebugClear() { } public void ReadAnyKey(bool something, bool something2) { Thread.Sleep(500); } public void SetStringStyle(Color color) { ForeColor = color; } public void SetStringStyle(FontStyle fontStyle) { } public void SetBgColor(Color color) { } public void SetToolTipColor(Color fc, Color bc) { } public void SetToolTipDelay(int delay) { } public void SetToolTipDuration(int duration) { } public void SetFont(string font) { } public void SetRedraw(long value) { } public int NewButtonGeneration { get; set; } public void UpdateGeneration() { } public string GetWindowTitle() { return "title"; } public long LineCount { get; set; } public string getDefStBar() { return ""; } public bool IsTimeOut { get; set; } } }