From 32467191f6ce777899d8818bcc38b78954e3eba6 Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 21 May 2023 02:11:47 +0200 Subject: [PATCH] Added New CLI Options to list enqueued task and view last 20 loglines --- Logging/MemoryLogger.cs | 33 +++++++++++++++------------------ Tranga-CLI/Tranga_Cli.cs | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/Logging/MemoryLogger.cs b/Logging/MemoryLogger.cs index bc22579..efdb591 100644 --- a/Logging/MemoryLogger.cs +++ b/Logging/MemoryLogger.cs @@ -18,25 +18,22 @@ public class MemoryLogger : LoggerBase public string[] GetLogMessage() { - string[] ret = new string[logMessages.Count]; - for (int logMessageIndex = 0; logMessageIndex < ret.Length; logMessageIndex++) - { - DateTime logTime = logMessages.GetValueAtIndex(logMessageIndex).logTime; - string dateTimeString = $"{logTime.ToShortDateString()} {logTime.ToShortTimeString()}"; - string callerString = logMessages.GetValueAtIndex(logMessageIndex).caller.ToString(); - string value = $"[{dateTimeString}] {callerString} | {logMessages.GetValueAtIndex(logMessageIndex).value}"; - ret[logMessageIndex] = value; - } + return Tail(Convert.ToUInt32(logMessages.Count)); + } + + public string[] Tail(uint? length) + { + int retLength; + if (length is null || length > logMessages.Count) + retLength = logMessages.Count; + else + retLength = (int)length; + + string[] ret = new string[retLength]; + + for (int logMessageIndex = logMessages.Count - retLength; logMessageIndex < logMessages.Count; logMessageIndex++) + ret[logMessageIndex + retLength - logMessages.Count] = logMessages.GetValueAtIndex(logMessageIndex).ToString(); return ret; } - - public string[] Tail(uint length) - { - string[] ret = new string[length]; - for (int logMessageIndex = logMessages.Count - 1; logMessageIndex > logMessageIndex - length; logMessageIndex--) - ret[logMessageIndex] = logMessages.GetValueAtIndex(logMessageIndex).ToString(); - - return ret.Reverse().ToArray(); - } } \ No newline at end of file diff --git a/Tranga-CLI/Tranga_Cli.cs b/Tranga-CLI/Tranga_Cli.cs index 042a562..d3d42f2 100644 --- a/Tranga-CLI/Tranga_Cli.cs +++ b/Tranga-CLI/Tranga_Cli.cs @@ -110,6 +110,18 @@ public static class Tranga_Cli Console.WriteLine("Press any key."); Console.ReadKey(); break; + case ConsoleKey.K: + PrintTasks(taskManager.GetAllTasks().Where(qTask => qTask.state is TrangaTask.ExecutionState.Enqueued).ToArray(), logger); + Console.WriteLine("Press any key."); + Console.ReadKey(); + break; + case ConsoleKey.F: + Console.Clear(); + foreach (string message in logger.Tail(20)) + Console.Write(message); + Console.WriteLine("Press any key."); + Console.ReadKey(); + break; } selection = PrintMenu(taskManager, settings.downloadLocation, logger); } @@ -140,7 +152,9 @@ public static class Tranga_Cli Console.WriteLine($"{"C: Create Task",-30}{"L: List tasks",-30}"); Console.WriteLine($"{"D: Delete Task",-30}{"R: List Running Tasks", -30}"); Console.WriteLine($"{"E: Execute Task now",-30}{"S: Search Tasks", -30}"); - Console.WriteLine(); + Console.WriteLine($"{"",-30}{"K: List Task Queue", -30}"); + //Console.WriteLine(); + Console.WriteLine($"{"F: Show last 20 Log-lines",-30}{"",-30}"); Console.WriteLine($"{"U: Update this Screen",-30}{"Q: Exit",-30}"); ConsoleKey selection = Console.ReadKey().Key; logger.WriteLine("Tranga_CLI", $"Menu selection: {selection}");