Skip to content

Commit

Permalink
Separate 'q' from ctrl-c
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbilas committed Aug 17, 2024
1 parent b100f2f commit a9e6311
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Stale.Cli/Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void FlushStdout()
if (_cb.Span.IsEmpty)
return;

_terminal.Out(_cb.Memory);
_terminal.Out(_cb.Span);
_cb.Clear(10*1024);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Stale.Cli/Stale.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="BannedSymbols.txt" />
<ProjectReference Include="..\Core.Terminal\Core.Terminal.csproj" />

<PackageReference Include="Dumpify" />
<PackageReference Include="Spectre.Console" />

Expand Down
14 changes: 11 additions & 3 deletions src/Stale.Cli/StaleApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
using Vezel.Cathode.Text.Control;
using Color = Spectre.Console.Color;

class CliExitException : Exception
{
public CliExitException(string message)
: base(message) {}
}

readonly struct StaleOptions
{
public StaleOptions(StaleCliArguments args)
Expand Down Expand Up @@ -171,7 +177,7 @@ void ControlPrintLogLine(bool isStdErr, ReadOnlyMemory<char> chars, bool newline
if (isStdErr)
_screen.Control.Print(chars.ToString(), k_stdErrStyle);
else
_screen.Control.Print(chars);
_screen.Control.Print(chars.Span);
ControlFinishLogLine(newline);
}

Expand Down Expand Up @@ -238,6 +244,7 @@ async ValueTask OutLineAsync(bool isStdErr, ReadOnlyMemory<char> chars)
await _screen.FlushStdoutAsync(_ctx.CancelToken);
}

// ReSharper disable once UnusedMember.Local
void DebugRenderCursorPos()
{
{
Expand Down Expand Up @@ -269,8 +276,9 @@ void Pause()
}

if (evt is { Char: 'q', Modifiers: 0 })
_ctx.Cancel();
else if (evt is { Char: '\r', Modifiers: 0 })
throw new CliExitException("User quit");

if (evt is { Char: '\r', Modifiers: 0 })
_pauseSkip = 0;
else if (evt is { Char: ' ', Modifiers: 0 })
_pauseSkip = 9;
Expand Down
7 changes: 7 additions & 0 deletions src/Stale.Cli/StaleCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@

return await Exec(async () => (int)await StaleApp.Run(ctx, staleOptions, child));
}
catch (CliExitException x)
{
ctx.LongTasks.AbortAll();
if (ctx.IsVerbose)
ctx.Verbose(x.Message);
return (int)CliExitCode.Success;
}
catch (CliErrorException x)
{
ctx.ErrorLine(x.Message);
Expand Down

0 comments on commit a9e6311

Please sign in to comment.