Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error debugging a console app in VSCode when running AnsiConsole.Live(table) #1393

Open
eduherminio opened this issue Dec 2, 2023 · 3 comments
Labels
bug Something isn't working needs triage

Comments

@eduherminio
Copy link
Contributor

eduherminio commented Dec 2, 2023

Information

  • OS: Windows
  • Version: 0.47.0, 0.48.0
  • Terminal: VSCode debug console

Describe the bug

Unable to debug in in VSCode a console app that renders a table via AnsiConsole.Live(table).

Works as expected running directly from pwsh inside VSCode, and debugging from VS.

Stacktrace:

System.IO.IOException: 'The handle is invalid'
   at System.ConsolePal.set_CursorVisible(Boolean value)
   at Spectre.Console.LegacyConsoleCursor.Show(Boolean show) in /_/src/Spectre.Console/Internal/Backends/Legacy/LegacyConsoleCursor.cs:line 7
   at Spectre.Console.CursorExtensions.Hide(IAnsiConsoleCursor cursor) in /_/src/Spectre.Console/Extensions/CursorExtensions.cs:line 33
   at Spectre.Console.LiveDisplayRenderer.Started() in /_/src/Spectre.Console/Live/LiveDisplayRenderer.cs:line 16
   at Spectre.Console.LiveDisplay.<>c__DisplayClass18_0`1.<<StartAsync>b__0>d.MoveNext() in /_/src/Spectre.Console/Live/LiveDisplay.cs:line 104
--- End of stack trace from previous location ---
   at Spectre.Console.Internal.DefaultExclusivityMode.RunAsync[T](Func`1 func) in /_/src/Spectre.Console/Internal/DefaultExclusivityMode.cs:line 40
   at Spectre.Console.LiveDisplay.StartAsync[T](Func`2 func) in /_/src/Spectre.Console/Live/LiveDisplay.cs:line 98
   at Spectre.Console.LiveDisplay.StartAsync(Func`2 func) in /_/src/Spectre.Console/Live/LiveDisplay.cs:line 78
   at AoCHelper.Solver.SolveAll(Action`1 options) in C:\dev\_Competitive_Programming\AoCHelper\src\AoCHelper\Solver.cs:line 227
   at Program.<Main>$(String[] args) in C:\dev\_Competitive_Programming\AoCHelper\src\AoCHelper.PoC\Program.cs:line 4
   at Program.<Main>(String[] args)

To Reproduce

Simplest code to reproduce it (debug from VSCode):

using Spectre.Console;

var table = new Table()
    .AddColumns("1", "2");

await AnsiConsole.Live(table)
    .StartAsync(async ctx =>
    {
    });

return;

Real project:

git clone https://github.com/eduherminio/AoCHelper
cd AoCHelper/src/AoCHelper.PoC
code .
<debug from VSCode>

Expected behavior
No exception is thrown

Screenshots

From someone consuming the library that has the spectre.console dependency via NuGet (eduherminio/AoCHelper#183)
image

From my PoC project (second repro above) that uses the library which spectre.console dependency via project reference
image


Please upvote 👍 this issue if you are interested in it.

@eduherminio eduherminio added bug Something isn't working needs triage labels Dec 2, 2023
@rafaelsc
Copy link

rafaelsc commented Dec 5, 2023

This error happens in more situations:

  • When piping out the console output to another console.in. Exs:
mycode.exe > textoutput.txt
mycode.exe | more
  • When running with SYSTEM account: (Download psexec from Microsoft site to run a command with the System account)
psExec -s mycode.exe

I believe this are the same issue than piping above. Psexec should be piping the result to show in the source console.

@patriksvensson
Copy link
Contributor

Hmm, since stdout is redirected, you shouldn't be able to do live output at all (by design). We will need to investigate this.

@eduherminio
Copy link
Contributor Author

Just FYI I do check Environment.UserInteractive && !Console.IsOutputRedirected as a requirement to calling AnsiConsole.Clear(), after having issues with CI runners (#151), but never found an issue there with AnsiConsole.Live(table).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
Status: Todo 🕑
Development

No branches or pull requests

3 participants