command-line-api icon indicating copy to clipboard operation
command-line-api copied to clipboard

ScreenView.Dispose crashes because the Terminal is null

Open justinmchase opened this issue 2 years ago • 2 comments

In ScreenView.Dispose its calling _console.GetTerminal().ShowCursor() but the terminal is null and so crashes with a null reference exception here.

I'm trying to run the cli in a GitHub Action the same code works fine on my local machine but not in the action. The code is basically:

using var screen new ScreenView(
  new ConsoleRenderer(context.Console, context.BindingContext.OutputMode()),
  context.Console
)
{
}

I tried commenting out .UseAnsiTerminalWhenAvailable() on my builder but it still does the same thing. It seems like

justinmchase avatar Sep 19 '23 00:09 justinmchase

Actually I think its this line right here: https://github.com/dotnet/command-line-api/blob/main/src/System.CommandLine.Rendering/Terminal.cs#L50

The return type for GetTerminal() should probably be changed to be ITerminal?

justinmchase avatar Sep 19 '23 00:09 justinmchase

You can reproduce this in any shell by redirecting the output, such as:

example           # ok
echo "$(example)" # crash

justinmchase avatar Nov 02 '23 22:11 justinmchase