diff --git a/SabreTools.Helper/Logger.cs b/SabreTools.Helper/Logger.cs index 894064c7..fb96589e 100644 --- a/SabreTools.Helper/Logger.cs +++ b/SabreTools.Helper/Logger.cs @@ -137,7 +137,9 @@ namespace SabreTools.Helper // USER and ERROR writes to console if (loglevel == LogLevel.USER || loglevel == LogLevel.ERROR) { - Console.WriteLine((loglevel == LogLevel.ERROR ? loglevel.ToString() + " " : "") + output); + int padlength = (int)(Math.Ceiling((double)output.Length / 80) * 80) - 1; + string tempoutput = output.PadRight(padlength, ' '); + Console.WriteLine((loglevel == LogLevel.ERROR ? loglevel.ToString() + " " : "") + tempoutput); } // If we're writing to file, use the existing stream @@ -162,11 +164,22 @@ namespace SabreTools.Helper /// Write the given exact string to the log output /// /// String to be written log - /// Severity of the information being logged + /// Line number to write out to + /// Column number to write out to /// True if the output could be written, false otherwise - public bool LogExact(string output) + public bool Log(string output, int line, int column) { - Console.Write(output); + // Set the cursor position (if not being redirected) + if (!Console.IsOutputRedirected) + { + Console.CursorTop = line; + Console.CursorLeft = column; + } + + // Write out to the console + int padlength = (int)(Math.Ceiling((double)output.Length / 80) * 80) - 1; + string tempoutput = output.PadRight(padlength, ' '); + Console.Write(tempoutput); // If we're writing to file, use the existing stream if (_tofile) diff --git a/SimpleSort/SimpleSort.cs b/SimpleSort/SimpleSort.cs index d4f3fc3c..c1735b2a 100644 --- a/SimpleSort/SimpleSort.cs +++ b/SimpleSort/SimpleSort.cs @@ -21,6 +21,10 @@ namespace SabreTools private ArchiveScanLevel _zip; private Logger _logger; + // Other private variables + private int _cursorTop; + private int _cursorLeft; + /// /// Create a new SimpleSort object /// @@ -307,6 +311,7 @@ namespace SabreTools // Then, loop through and check each of the inputs _logger.User("Processing files:\n"); + _cursorTop = Console.CursorTop; for (int i = 0; i < files.Count; i++) { success &= RebuildToOutputHelper(files[i], i, files.Count); @@ -347,8 +352,9 @@ namespace SabreTools bool success = true; // Get the full path of the input for movement purposes - string statement = "\r" + (100 * index / total) + "% - " + Path.GetFileName(input); - _logger.LogExact(statement.PadRight(79, ' ')); + string percentage = Math.Round((100 * ((double)index / total)), 2, MidpointRounding.AwayFromZero).ToString(); + string statement = percentage + "% - " + input; + _logger.Log(statement, _cursorTop, 0); // Get if the file should be scanned internally and externally bool shouldExternalScan = true;