Skip to content

Commit

Permalink
add - Added lap difference
Browse files Browse the repository at this point in the history
---

Lap difference to determine whether the last two laps are slower or faster is now shown!

---

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

namespace Nitrocid.Extras.Timers.Timers
{
Expand Down Expand Up @@ -85,8 +86,10 @@ public static void OpenStopwatch()
string LapsText = Translate.DoTranslation("Lap");
int HalfWidth = (int)Math.Round(ConsoleWrapper.WindowWidth / 2d);
int HalfHeight = (int)Math.Round(ConsoleWrapper.WindowHeight / 2d);
int TimeLeftPosition = (int)Math.Round(HalfWidth * 1.5d - Stopwatch.Elapsed.ToString(@"d\.hh\:mm\:ss\.fff", CultureManager.CurrentCult).Length / 2d);
int TimeTopPosition = HalfHeight;
var elapsed = Stopwatch.Elapsed;
string elapsedString = elapsed.ToString(@"d\.hh\:mm\:ss\.fff", CultureManager.CurrentCult);
int TimeLeftPosition = (int)Math.Round(HalfWidth * 1.5d - elapsedString.Length / 2d);
int TimeTopPosition = HalfHeight - 1;
int LapsCurrentLapLeftPosition = 2;
int LapsCurrentLapTopPosition = ConsoleWrapper.WindowHeight - 3;
Expand All @@ -98,10 +101,25 @@ public static void OpenStopwatch()
// Print the time interval and the current lap
builder.Append(
TextWriterWhereColor.RenderWhereColorBack(Stopwatch.Elapsed.ToString(@"d\.hh\:mm\:ss\.fff", CultureManager.CurrentCult), TimeLeftPosition, TimeTopPosition, true, LapColor, KernelColorTools.GetColor(KernelColorType.Background)) +
TextWriterWhereColor.RenderWhereColorBack(elapsedString, TimeLeftPosition, TimeTopPosition, true, LapColor, KernelColorTools.GetColor(KernelColorType.Background)) +
TextWriterWhereColor.RenderWhereColorBack(LapsText + " {0}: {1}", LapsCurrentLapLeftPosition, LapsCurrentLapTopPosition, true, LapColor, KernelColorTools.GetColor(KernelColorType.Background), Laps.Count + 1, LappedStopwatch.Elapsed.ToString(@"d\.hh\:mm\:ss\.fff", CultureManager.CurrentCult))
);
// Also, print the time difference of the last lap if required
if (Laps.Count > 1)
{
var firstLastLap = Laps[^1];
var secondLastLap = Laps[^2];
int lapTopPosition = HalfHeight + 1;
var diff = secondLastLap.LapInterval - firstLastLap.LapInterval;
bool slower = diff < TimeSpan.Zero;
string elapsedDiff = diff.ToString((slower ? "\\+" : "\\-") + @"d\.hh\:mm\:ss\.fff", CultureManager.CurrentCult);
Color finalLapColor = slower ? new Color(ConsoleColors.Red) : new Color(ConsoleColors.Lime);
builder.Append(
TextWriterWhereColor.RenderWhereColorBack(elapsedDiff, TimeLeftPosition, lapTopPosition, true, finalLapColor, KernelColorTools.GetColor(KernelColorType.Background))
);
}
// Print the border
int SeparatorHalfConsoleWidth = ConsoleWrapper.WindowWidth / 2;
int SeparatorHalfConsoleWidthInterior = ConsoleWrapper.WindowWidth / 2 - 2;
Expand Down

0 comments on commit 7596620

Please sign in to comment.