Skip to content

Commit

Permalink
add - doc - Added an option to get lap list
Browse files Browse the repository at this point in the history
---

We've made lap lists more accessible!

---

Type: add
Breaking: False
Doc Required: True
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Sep 7, 2024
1 parent 16a4092 commit 98888c2
Showing 1 changed file with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
using Terminaux.Writer.MiscWriters.Tools;
using Terminaux.Writer.MiscWriters;
using Terminaux.Writer.FancyWriters;
using Terminaux.Inputs.Styles.Infobox;

namespace Nitrocid.Extras.Timers.Timers
{
Expand All @@ -51,6 +52,7 @@ public static class StopwatchScreen
[
new( /* Localizable */ "Start or stop", ConsoleKey.Enter),
new( /* Localizable */ "Lap", ConsoleKey.L),
new( /* Localizable */ "Lap list", ConsoleKey.L, ConsoleModifiers.Shift),
new( /* Localizable */ "Reset", ConsoleKey.R),
new( /* Localizable */ "Exit", ConsoleKey.Escape),
];
Expand Down Expand Up @@ -142,21 +144,21 @@ public static void OpenStopwatch()
ScreenTools.Render(watchScreen);

// Check to see if the timer is running to continually update the timer render
ConsoleKey KeysKeypress = default;
ConsoleKeyInfo KeysKeypress = default;
if (running)
{
// Wait for a keypress
if (ConsoleWrapper.KeyAvailable)
KeysKeypress = Input.ReadKey().Key;
KeysKeypress = Input.ReadKey();
}
else
{
// Wait for a keypress
KeysKeypress = Input.ReadKey().Key;
KeysKeypress = Input.ReadKey();
}

// Check for a keypress
switch (KeysKeypress)
switch (KeysKeypress.Key)
{
case ConsoleKey.Enter:
{
Expand All @@ -176,6 +178,12 @@ public static void OpenStopwatch()
{
if (LappedStopwatch.IsRunning)
{
if (KeysKeypress.Modifiers == ConsoleModifiers.Shift)
{
InfoBoxColor.WriteInfoBox(GenerateLapList());
watchScreen.RequireRefresh();
break;
}
var Lap = new LapDisplayInfo(LapColor, LappedStopwatch.Elapsed);
Laps.Add(Lap);
LappedStopwatch.Restart();
Expand Down Expand Up @@ -225,5 +233,17 @@ public static void OpenStopwatch()
ConsoleWrapper.CursorVisible = true;
}

private static string GenerateLapList()
{
var lapsListBuilder = new StringBuilder();
for (int i = 0; i < Laps.Count; i++)
{
LapDisplayInfo? lap = Laps[i];
lapsListBuilder.AppendLine(lap.LapColor.VTSequenceForeground + Translate.DoTranslation("Lap") + $" {i + 1}: {lap.LapInterval.ToString(@"d\.hh\:mm\:ss\.fff", CultureManager.CurrentCult)}");
}
if (Laps.Count == 0)
lapsListBuilder.AppendLine(Translate.DoTranslation("No laps yet..."));
return lapsListBuilder.ToString();
}
}
}

0 comments on commit 98888c2

Please sign in to comment.