-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interaction.cs
57 lines (48 loc) · 1.77 KB
/
Interaction.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System.Globalization;
using ElitechLog.Consts;
using ElitechLog.Models;
using Humanizer;
using Humanizer.Localisation;
using Kurukuru;
namespace ElitechLogCLI;
public static class Interaction
{
public static Spinner StartSpinner()
{
var spinner = new Spinner("Waiting for device...", Patterns.GrowVertical);
if (!Console.IsOutputRedirected)
{
spinner.Start();
}
return spinner;
}
public static void DisplayDevice(Parameters parms)
{
Console.Write($"Device: {parms.TravelDesc}, serial number: {parms.SerialNum}");
if (!string.IsNullOrEmpty(parms.DeviceStateDesc))
{
Console.Write($", state: {parms.DeviceStateDesc.TrimEnd('.', ' ')}");
}
if (!string.IsNullOrEmpty(parms.BatteryDesc))
{
Console.Write($", battery: {parms.BatteryDesc}");
}
if (parms.DevicerCapacityMax > 0)
{
Console.Write($", storage: {(double)parms.RecordsNumberActual / parms.DevicerCapacityMax:P1}");
if (DateTime.TryParseExact(parms.expectStopTime, Default.DateTimeFormat, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out var stopTime))
{
Console.Write($" ({(stopTime - DateTime.Now).Humanize(maxUnit: TimeUnit.Year)})");
}
}
Console.WriteLine();
}
public static bool Confirm(bool yes, string action, int recordCount)
{
if (yes) return true;
Console.WriteLine($"Are you sure you want to {action}? The device will be stopped and {recordCount:N0} reading(s) deleted. Enter [y]es to confirm.");
if (Console.ReadKey(true).KeyChar is not (not 'y' or 'Y')) return true;
Console.WriteLine("Aborted");
return false;
}
}