Skip to content

Commit

Permalink
Fix output of esptool progress (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Dec 3, 2024
1 parent ec2ec5c commit 30174e7
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions nanoFirmwareFlasher.Library/Esp32Operations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,13 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(

if (verbosity >= VerbosityLevel.Normal)
{
// move cursor up and clear line
OutputWriter.Write("\u001b[A\r\u001b[K");
// clear output of the progress from esptool, move cursor up and clear line
Console.SetCursorPosition(0, Console.CursorTop);
Console.Write(new string(' ', Console.WindowWidth));
int currentLineCursor = Console.CursorTop;
Console.SetCursorPosition(0, currentLineCursor - 1);
Console.Write(new string(' ', Console.WindowWidth));
Console.SetCursorPosition(0, currentLineCursor - 1);

OutputWriter.ForegroundColor = ConsoleColor.White;
OutputWriter.Write($"Backup configuration...");
Expand Down Expand Up @@ -583,15 +588,21 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
if (verbosity >= VerbosityLevel.Normal)
{
// output the start of operation message for verbosity normal and above
// move cursor up and clear line
OutputWriter.Write("\u001b[A\r\u001b[K");

// clear output of the progress from esptool, move cursor up and clear line
Console.SetCursorPosition(0, Console.CursorTop);
Console.Write(new string(' ', Console.WindowWidth));
int currentLineCursor = Console.CursorTop;
Console.SetCursorPosition(0, currentLineCursor - 1);
Console.Write(new string(' ', Console.WindowWidth));
Console.SetCursorPosition(0, currentLineCursor - 1);

// operation completed output
// output the full message as usual after the progress from esptool
OutputWriter.ForegroundColor = ConsoleColor.White;
OutputWriter.Write($"Flashing firmware...");
OutputWriter.ForegroundColor = ConsoleColor.Green;
OutputWriter.WriteLine("OK".PadRight(110));
OutputWriter.WriteLine("OK".PadRight(Console.WindowWidth - Console.CursorLeft));

// warn user if reboot is not possible
if (espTool.CouldntResetTarget)
Expand Down

0 comments on commit 30174e7

Please sign in to comment.