Skip to content

Commit edfa254

Browse files
authored
More improvements in progress output (#226)
1 parent bcdefb6 commit edfa254

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

nanoFirmwareFlasher.Library/Esp32Operations.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
399399
if (verbosity >= VerbosityLevel.Normal)
400400
{
401401
Console.ForegroundColor = ConsoleColor.White;
402-
Console.WriteLine($"Erasing flash...");
402+
Console.Write($"Erasing flash...");
403403
}
404404

405405
// erase flash
@@ -425,7 +425,7 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
425425

426426
if (verbosity >= VerbosityLevel.Normal)
427427
{
428-
Console.WriteLine($"Flashing firmware...");
428+
Console.Write($"Flashing firmware...");
429429
}
430430

431431
// write to flash
@@ -435,8 +435,10 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
435435
{
436436
if (verbosity >= VerbosityLevel.Normal)
437437
{
438+
Console.Write($"Flashing firmware...");
439+
438440
Console.ForegroundColor = ConsoleColor.Green;
439-
Console.WriteLine("OK ");
441+
Console.WriteLine("OK".PadRight(110));
440442

441443
// warn user if reboot is not possible
442444
if (espTool.CouldntResetTarget)

nanoFirmwareFlasher.Library/EspTool.cs

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -487,20 +487,6 @@ internal ExitCodes WriteFlash(
487487
throw new WriteEsp32FlashException(messages);
488488
}
489489

490-
var match = Regex.Match(messages, regexPattern.ToString());
491-
if (!match.Success)
492-
{
493-
throw new WriteEsp32FlashException(messages);
494-
}
495-
496-
if (Verbosity >= VerbosityLevel.Detailed)
497-
{
498-
foreach (string groupName in regexGroupNames)
499-
{
500-
Console.WriteLine(match.Groups[groupName].ToString().Trim());
501-
}
502-
}
503-
504490
// check if there is any mention of not being able to run the app
505491
CouldntResetTarget = messages.Contains("To run the app, reset the chip manually");
506492

@@ -621,6 +607,7 @@ private bool RunEspTool(
621607
connectPromptShown = false;
622608
connectPatternFound = false;
623609
connectTimeStamp = DateTime.UtcNow;
610+
var progressStarted = false;
624611

625612
// showing progress is a little bit tricky
626613
if (Verbosity > VerbosityLevel.Quiet)
@@ -643,9 +630,17 @@ private bool RunEspTool(
643630

644631
// try to find a progress message
645632
string progress = FindProgress(messageBuilder, progressTestChar.Value);
646-
if (progress != null && Verbosity > VerbosityLevel.Quiet)
633+
if (progress != null && Verbosity >= VerbosityLevel.Detailed)
647634
{
648-
// print progress and set the cursor to the beginning of the line (\r)
635+
if (!progressStarted)
636+
{
637+
// need to print the first line of the progress message
638+
Console.Write("\r");
639+
640+
progressStarted = true;
641+
}
642+
643+
// print progress... and set the cursor to the beginning of the line (\r)
649644
Console.Write(progress);
650645
Console.Write("\r");
651646
}
@@ -654,6 +649,15 @@ private bool RunEspTool(
654649
}
655650
else
656651
{
652+
if (Verbosity >= VerbosityLevel.Detailed)
653+
{
654+
// need to clear all progress lines
655+
for (int i = 0; i < messageBuilder.Length; i++)
656+
{
657+
Console.Write("\b");
658+
}
659+
}
660+
657661
break;
658662
}
659663
}
@@ -788,10 +792,17 @@ private string FindProgress(
788792
{
789793
// trim the test char and convert \r\n into \r
790794
string progress = messageBuilder.ToString().Trim(progressTestChar).Replace("\r\n", "\r");
795+
796+
// trim initial message with device features
797+
int startIndex = progress.LastIndexOf("MAC:");
798+
791799
// another test char in the message?
792-
int delimiter = progress.LastIndexOf(progressTestChar);
793-
if (delimiter > 0)
800+
int delimiter = progress.LastIndexOf(progressTestChar, progress.Length - 1);
801+
if (startIndex > 0
802+
&& delimiter > 0
803+
&& delimiter > startIndex)
794804
{
805+
//var nextDelimiter = progress.LastIndexOf(progressTestChar, delimiter);
795806
// then we found a progress message; pad the message to 110 chars because no message is longer than 110 chars
796807
return progress.Substring(delimiter + 1).PadRight(110);
797808
}

nanoFirmwareFlasher.Library/FirmwarePackage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ private static async Task<DownloadUrlResult> GetDownloadUrlAsync(
599599
return new DownloadUrlResult(string.Empty, string.Empty, ExitCodes.E9005);
600600
}
601601

602-
if (verbosity > VerbosityLevel.Quiet)
602+
if (verbosity >= VerbosityLevel.Detailed)
603603
{
604604
Console.ForegroundColor = ConsoleColor.Green;
605605
Console.WriteLine($"OK");

0 commit comments

Comments
 (0)