Skip to content

Commit

Permalink
Solve long session requests bug by shrinking the message
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeliux committed Aug 22, 2024
1 parent 09613fb commit a761365
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
8 changes: 4 additions & 4 deletions cli/Kryptor.Cli.Shared/CliSessionHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private async Task ShowProgressImpl(bool showOverall, bool showRemaining = true)
if (HasRequest)
{
string choices = Request.Default ? "Y/n" : "y/N";
Console.Write($"{Request.Message} ({choices})");
Console.Write($"{Request.Message.Shrink(bufferWidth - 8)} ({choices})");
}
else
{
Expand Down Expand Up @@ -376,11 +376,11 @@ private void GetSessionInfo(int bufferWidth, ConsoleFrameBuffer animations, ISes
}

desc = session.Description;
int expectedLength = bufferWidth - prog.Length - 5;

if (!IsOutputRedirected && desc.Length > expectedLength)
if (!IsOutputRedirected)
{
desc = $"...{desc.Substring(desc.Length - expectedLength + 3)}";
int expectedLength = bufferWidth - prog.Length - 5;
desc = desc.Shrink(expectedLength);
}
}

Expand Down
10 changes: 10 additions & 0 deletions cli/Kryptor.Cli.Shared/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,15 @@ public static string PadBoth(this string str, int length)
public static string FormatWithCommas(this int number) => number.ToString("N0");

public static string FormatWithCommas(this double number) => number.ToString("N2");

public static string Shrink(this string src, int expectedLength)
{
if (src.Length > expectedLength)
{
src = $"...{src.Substring(src.Length - expectedLength + 3)}";
}

return src;
}
}
}
2 changes: 1 addition & 1 deletion cli/Kryptor.Cli.Shared/KeyStoreTokenLoadSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected override async Task<bool> RunAsync(ISessionHost sessionHost, Cancellat
await Task.Delay(1);

#if DEBUG
if (!await SendRequest(sessionHost, new SessionRequest<bool>("Do you want to continue this task?", true), cancellationToken))
if (!await SendRequest(sessionHost, new SessionRequest<bool>("Do you want to continue this task? even when you see this long message? tou know, i don't want to continue generating these keystores, i have a family and two kids to feed, please free me. i know that you may need this keystore to encrypt or decrypt your highly secret files, you are the boss.", true), cancellationToken))
{
throw new System.OperationCanceledException();
}
Expand Down

0 comments on commit a761365

Please sign in to comment.