47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using System;
|
|
using SlatedGameToolkit.Framework.Logging;
|
|
|
|
namespace SlatedGameToolkit.Tools.CommandSystem.Interaction
|
|
{
|
|
public class ConsoleInteraction : IInteractable, ILogListener
|
|
{
|
|
private volatile bool listening;
|
|
string prefix;
|
|
public bool Debug { get; set; }
|
|
public LogLevel Level => Debug ? LogLevel.DEBUG : LogLevel.INFO;
|
|
|
|
public ConsoleInteraction(string prefix) {
|
|
this.prefix = prefix;
|
|
}
|
|
|
|
public void Separate()
|
|
{
|
|
listening = false;
|
|
Console.WriteLine();
|
|
}
|
|
|
|
public string Listen()
|
|
{
|
|
listening = true;
|
|
Console.Write(prefix + "> ");
|
|
return Console.ReadLine();
|
|
}
|
|
|
|
public void Tell(string message)
|
|
{
|
|
listening = false;
|
|
Console.SetCursorPosition(0, Console.CursorTop);
|
|
Console.WriteLine(message);
|
|
}
|
|
|
|
public void LogMesesage(string message, DateTime time, LogLevel level)
|
|
{
|
|
Console.SetCursorPosition(0, Console.CursorTop);
|
|
Console.WriteLine(string.Format("Playground [{0}] [{1}]: {2}", level, time.ToString("H:mm:ss"), message));
|
|
if (listening) {
|
|
Console.SetCursorPosition(0, Console.CursorTop);
|
|
Console.Write(prefix + "> ");
|
|
}
|
|
}
|
|
}
|
|
} |