Terminal.Gui icon indicating copy to clipboard operation
Terminal.Gui copied to clipboard

Driver "v2win" broken in `conhost`

Open GitHubThor opened this issue 8 months ago • 34 comments

Hello,

Driver "v2win" is broken in version v2.0.0-develop.4401 when used in Console Host. It happens inside de VS IDE and now it also happens running it outside the IDE in Windows Explorer.

It shows escape codes along with a wrong rendering.

Image

Remapping the glyphs does not fix the issue, so seems not related to glyphs.

WindowsDriver works.

Originally posted by @GitHubThor in https://github.com/gui-cs/Terminal.Gui/discussions/4003

GitHubThor avatar Mar 27 '25 15:03 GitHubThor

From your discussion, I believe the problem you are describing is simply that some of the default glyphs don't render correctly in conhost.

If there are other "escape codes" problems beyond what you described in the other post, that was cleared up becaues you were not calling Shutdown, please let me know.

Otherwise, I'm closing this as "by design; workaround available; won't fix".

  • By design: V2 is optimized for modern fonts by default.

  • Workaround available: See my guidance on creating a config.json that lets you remap the default glpyhs to those that conhost supports

  • won't fix: We will make this better via fixing this issue:

  • #3493

I wish there were a way to reliably detect "bad/legacy" consoles so we could apply a Theme optimized for those. But we've tried many times to come up with something and it ends up just adding more problems.

I do think it would be a good idea to include a built-in Theme that only uses known-good glyphs. Perhaps you could add one and submit it as a PR?

tig avatar Mar 27 '25 23:03 tig

The more strange is v2net not rendering the glyphs as the v2win does using Windows Terminal. This worth to being investigate.

BDisp avatar Mar 27 '25 23:03 BDisp

The more strange is v2net not rendering the glyphs as the v2win does using Windows Terminal. This worth to being investigate.

I agree. But this issues title and description says nothing about that.

tig avatar Mar 28 '25 05:03 tig

I agree. But this issues title and description says nothing about that.

It's in the discussion #4003 as OP mention above.

BDisp avatar Mar 28 '25 11:03 BDisp

If there are other "escape codes" problems beyond what you described in the other post, that was cleared up becaues you were not calling Shutdown, please let me know.

Let me explain this, sorry for the language barrier. I do use Shutdown and Shutdown is not related with this issue, neither making it better.

Today I tested both 2.0.0-develop.4401 and 2.0.0-prealpha.1895, both same issue only when running inside VS with conhost and "v2win" driver. (conhost is the only way to go when application requires admin privileges in windows)

"WindowsDriver" seems to work well now both 2.0.0-develop.4401 and 2.0.0-prealpha.1895. "v2win" driver is not working!

Yesterday I was using 2.0.0-v2-develop.2203 since it appeared as the latest in nuget. In that version yesterday was the opposite, "WindowsDriver" was not working inside VS with conhost and "v2win" was not even accepted driver.

I hope this helps, don't hesitate to ask me fore more clarifications if needed.

BTW: I'm still confused of what versions to use 2.0.0-develop.YYYY or 2.0.0-prealpha.YYYY, independently of what VS Nuget manager offers in the list. Thanks!

GitHubThor avatar Mar 28 '25 12:03 GitHubThor

Just use the 2.0.0-develop.YYYY with the highest YYYY number.

I don't understand why nuget is even showing 2203. That version is NOT listed on Nuget.

Image

tig avatar Mar 28 '25 20:03 tig

It is very challenging trying to keep track of multiple topics when they are scattered throughout Discussions and Issues.

@GitHubThor: Would you please:

a) Update the title of this Issue with a more precise description of the issue. If it only happens in v2win, state that. b) Update the 1st post in this Issue with a screenshot, GIF, or other evidence that shows the behavior you are seeing.

tig avatar Mar 28 '25 20:03 tig

I don't understand why nuget is even showing 2203. That version is NOT listed on Nuget.

I think nuget it's using the user cached local package.

BDisp avatar Mar 28 '25 21:03 BDisp

Hello,

Driver "v2win" is broken in version v2.0.0-develop.4401 when used in Console Host. It happens inside de VS IDE and now it also happens running it outside the IDE in Windows Explorer.

It shows escape codes along with a wrong rendering.

Image

Remapping the glyphs does not fix the issue, so seems not related to glyphs.

WindowsDriver works.

Originally posted by @GitHubThor in #4003

From this image, there is nothing wrong with the Glyphs. This is due to something else. Not sure what.

tig avatar Mar 29 '25 16:03 tig

From this image, there is nothing wrong with the Glyphs. This is due to something else. Not sure what.

Agreed, I tried next remapping and did not fix or change anything:

{ "Themes": [ { "Default": { "Glyphs.ULCorner": "", "Glyphs.URCorner": "", "Glyphs.LLCorner": "", "Glyphs.LRCorner": "", "Glyphs.HLine": "-", "Glyphs.VLine": "|" } } ] }

GitHubThor avatar Mar 29 '25 16:03 GitHubThor

BTW, just tested, TerminalGuiDesigner.exe using 2.0.0-develop.4400 has the same issue inside and outside the VS IDE. Detected too when used with conhost terminal and v2win:

So seems like the broken thing is v2win dirver + Windows conhost (Console Host).

Image

GitHubThor avatar Mar 29 '25 17:03 GitHubThor

Image

THIS issue, which I just reproduced in conhost, is releated to glyphs and shows something I previoulsy didn't notice:

SOMETIMES the troublesome glyphs (e.g ) render correctly.

In my previous investigations of this I didn't see that.

After using this ~/.tui/config.json file:

{
    "$schema": "https://gui-cs.github.io/Terminal.GuiV2Docs/schemas/tui-config-schema.json",
    "Theme": "Default",
    "Themes": [
        {
            "Default": {
                "Glyphs.LeftBracket": "[",
                "Glyphs.RightBracket": "]"                
            }
        }
    ]
}

I get this:

Image

{
    "$schema": "https://gui-cs.github.io/Terminal.GuiV2Docs/schemas/tui-config-schema.json",
    "Theme": "Default",
    "Themes": [
        {
            "Default": {
                "Button.DefaultShadow": "None",
                "Glyphs.LeftBracket": "[",
                "Glyphs.RightBracket": "]"                
            }
        }
    ]
}

makes it even better:

Image

I'm going to open a separate issue to track

SOMETIMES the troublesome glyphs (e.g ) render correctly.

tig avatar Mar 29 '25 17:03 tig

I've reproduced v2win not working in conhost:

Image

@GitHubThor for now, I recommend you just use "NetDriver". It works fine in Conhost as long as you remap the glyphs as I've shown in

  • #4006

tig avatar Mar 29 '25 17:03 tig

Please can you run the latest TGD and upload the generated logs. This will show trace logging from conhost and we might be able to see why it releases the escape codes.

Logs appear in %appdata% in TerminalGuiDesigner folder logs subdir.

Incidentally, you can still run designer with -d WindowsDriver

The v2 drivers are still very new so this kind of feedback is very helpful!

tznind avatar Mar 29 '25 17:03 tznind

Please can you run the latest TGD and upload the generated logs. This will show trace logging from conhost and we might be able to see why it releases the escape codes.

Logs appear in %appdata% in TerminalGuiDesigner folder logs subdir.

Incidentally, you can still run designer with -d WindowsDriver

The v2 drivers are still very new so this kind of feedback is very helpful!

@tznind this repros on all TG apps. It has nothing to do with TGD.

As noted in another issue, for users running in conhost they should use NetDriver.

Yes, we should see if we can make v2win/v2net work in conhost as well.

tig avatar Mar 29 '25 17:03 tig

Please can you run the latest TGD and upload the generated logs. This will show trace logging from conhost and we might be able to see why it releases the escape codes.

My logs using v2win:

logfile20250329.zip

I will use NetDriver from now on, works well. This is just in case it helps, although

seems to me nothing interesting in the logs.

GitHubThor avatar Mar 29 '25 17:03 GitHubThor

From this image, there is nothing wrong with the Glyphs. This is due to something else. Not sure what.

This is due the conhost.exe or cmd.exe doesn't support escape sequence to save/restore the terminal. Thus, if it isn't a WT then escape sequences must be avoid. Perhaps may need to have a separate issue for that.

BDisp avatar Mar 29 '25 17:03 BDisp

interesting, the mouse input came direct to console screen not to input processor. There is literally nothing read from input stream. How odd.

This is due the conhost.exe or cmd.exe doesn't support escape sequence to save/restore the terminal.

Its more like for the v2win it is deciding to send mouse sequences direct to the output stream instead of input 😕

tznind avatar Mar 29 '25 19:03 tznind

@tig what version of conhost? Do I just hit start menu and type conhost? when I do that I get a terminal that seems to work fine with v2win...

Is it just immediately on bot UICatalog it gives this behaviour?

tznind avatar Mar 29 '25 19:03 tznind

You can experience that by two ways:

1 - Set WT to Windows Console Host and start debugging --driver v2win from VS2022. 2 - Open VS2022 as admin and start debugging --driver v2win.

BDisp avatar Mar 29 '25 21:03 BDisp

I have tried both of these things and do not get any corruption...

To be clear I just have to run admin mode vs and run UICatalog and move mouse - I should instantly see ansi codes fill up all over screen?

@tig did you also do anything special?

I also do not get this behaviour running conhost.exe directy from the System32 directory.

This is the version I am running

PS C:\Windows\System32> (Get-Item "C:\Windows\System32\conhost.exe").VersionInfo.FileVersion
10.0.19041.320 (WinBuild.160101.0800)

Image

tznind avatar Mar 30 '25 08:03 tznind

Ok I can reproduce, you have to tick this to cause the breakage:

Image

tznind avatar Mar 30 '25 09:03 tznind

Here is the driver behaviours with legacy mode on the version of conhost I am using:

Driver Behaviour
v2win corrupt UI splurge mouse
v2net crash on start
NetDriver crash on start
WindowsDriver Runs without mose, black screen on opening any scenario

Without legacy mode all work perfectly.

v2net

Here is logs with -dl Trace

So both input and output have compatibility issues in terms of the sequences they are sending.

2025-03-30 10:28:19.041 +01:00 [INF] Main Loop Coordinator booting...
2025-03-30 10:28:19.059 +01:00 [INF] Creating NetOutput
2025-03-30 10:28:19.062 +01:00 [INF] Creating NetInput
2025-03-30 10:28:19.063 +01:00 [FTL] NetWinVTConsole could not be constructed i.e. could not configure terminal modes. May indicate running in non-interactive session e.g. unit testing CI
System.ApplicationException: Failed to set input console mode, error code: 87.
   at Terminal.Gui.NetWinVTConsole..ctor() in D:\Repos\temp\gui.cs\Terminal.Gui\ConsoleDrivers\NetDriver\NetWinVTConsole.cs:line 54
   at Terminal.Gui.NetInput..ctor() in D:\Repos\temp\gui.cs\Terminal.Gui\ConsoleDrivers\V2\NetInput.cs:line 26
2025-03-30 10:28:19.070 +01:00 [FTL] Input loop crashed
System.IO.IOException: The parameter is incorrect.
   at System.ConsolePal.set_TreatControlCAsInput(Boolean value)
   at Terminal.Gui.NetInput..ctor() in D:\Repos\temp\gui.cs\Terminal.Gui\ConsoleDrivers\V2\NetInput.cs:line 38
   at Terminal.Gui.ApplicationV2.<>c.<.ctor>b__7_0() in D:\Repos\temp\gui.cs\Terminal.Gui\ConsoleDrivers\V2\ApplicationV2.cs:line 28
   at Terminal.Gui.MainLoopCoordinator`1.RunInput() in D:\Repos\temp\gui.cs\Terminal.Gui\ConsoleDrivers\V2\MainLoopCoordinator.cs:line 105

This is the crash:

[?1049h[?25l[?1003h[?1015h[?1006hUnhandled exception. System.AggregateException: One or more errors occurred. (One
or more errors occurred. (The parameter is incorrect.))
 ---> System.AggregateException: One or more errors occurred. (The parameter is incorrect.)adPoolThread)
 ---> System.IO.IOException: The parameter is incorrect.
   at System.ConsolePal.set_TreatControlCAsInput(Boolean value)os\temp\gui.cs\Terminal.Gui\ConsoleDrivers\V2\MainLoopCo
   at Terminal.Gui.NetInput..ctor() in D:\Repos\temp\gui.cs\Terminal.Gui\ConsoleDrivers\V2\NetInput.cs:line 38
   at Terminal.Gui.ApplicationV2.<>c.<.ctor>b__7_0() in D:\Repos\temp\gui.cs\Terminal.Gui\ConsoleDrivers\V2\Application
2.cs:line 28.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at Terminal.Gui.MainLoopCoordinator`1.RunInput() in D:\Repos\temp\gui.cs\Terminal.Gui\ConsoleDrivers\V2\MainLoopCoor
inator.cs:line 105ding.Tasks.Task.Wait()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executi
nContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---ver driver, String driverName) in D:\Repos\temp\gui.cs\Terminal.Gui\Co
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executi
nContext, ContextCallback callback, Object state)r driver, String driverName) in D:\Repos\temp\gui.cs\Terminal.Gui\Appl
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
   --- End of inner exception stack trace ---evel() in D:\Repos\temp\gui.cs\UICatalog\UICatalog.cs:line 323
   at Terminal.Gui.MainLoopCoordinator`1.StartAsync() in D:\Repos\temp\gui.cs\Terminal.Gui\ConsoleDrivers\V2\MainLoopCo
rdinator.cs:line 89atalogApp.Main(String[] args) in D:\Repos\temp\gui.cs\UICatalog\UICatalog.cs:line 234
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at Terminal.Gui.ApplicationV2.CreateDriver(String driverName) in D:\Repos\temp\gui.cs\Terminal.Gui\ConsoleDrivers\V2
ApplicationV2.cs:line 110talog>clear
   at Terminal.Gui.ApplicationV2.Init(IConsoleDriver driver, String driverName) in D:\Repos\temp\gui.cs\Terminal.Gui\Co
soleDrivers\V2\ApplicationV2.cs:line 73
   at Terminal.Gui.Application.Init(IConsoleDriver driver, String driverName) in D:\Repos\temp\gui.cs\Terminal.Gui\Appl
cation\Application.Initialization.cs:line 47 -d v2net
   at UICatalog.UICatalogApp.RunUICatalogTopLevel() in D:\Repos\temp\gui.cs\UICatalog\UICatalog.cs:line 323curred. (One
   at UICatalog.UICatalogApp.UICatalogMain(Options options) in D:\Repos\temp\gui.cs\UICatalog\UICatalog.cs:line 450
   at UICatalog.UICatalogApp.Main(String[] args) in D:\Repos\temp\gui.cs\UICatalog\UICatalog.cs:line 234
 ---> System.IO.IOException: The parameter is incorrect.
D:\Repos\temp\gui.cs\UICatalog>atControlCAsInput(Boolean value)
   at Terminal.Gui.NetInput..ctor() in D:\Repos\temp\gui.cs\Terminal.Gui\ConsoleDrivers\V2\NetInput.cs:line 38
   at Terminal.Gui.ApplicationV2.<>c.<.ctor>b__7_0() in D:\Repos\temp\gui.cs\Terminal.Gui\ConsoleDrivers\V2\Application
2.cs:line 28
   at Terminal.Gui.MainLoopCoordinator`1.RunInput() in D:\Repos\temp\gui.cs\Terminal.Gui\ConsoleDrivers\V2\MainLoopCoor
inator.cs:line 105
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executi
nContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executi
nContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
   --- End of inner exception stack trace ---
   at Terminal.Gui.MainLoopCoordinator`1.StartAsync() in D:\Repos\temp\gui.cs\Terminal.Gui\ConsoleDrivers\V2\MainLoopCo
rdinator.cs:line 89
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at Terminal.Gui.ApplicationV2.CreateDriver(String driverName) in D:\Repos\temp\gui.cs\Terminal.Gui\ConsoleDrivers\V2
ApplicationV2.cs:line 110
   at Terminal.Gui.ApplicationV2.Init(IConsoleDriver driver, String driverName) in D:\Repos\temp\gui.cs\Terminal.Gui\Co
soleDrivers\V2\ApplicationV2.cs:line 73
   at Terminal.Gui.Application.Init(IConsoleDriver driver, String driverName) in D:\Repos\temp\gui.cs\Terminal.Gui\Appl
cation\Application.Initialization.cs:line 47
   at UICatalog.UICatalogApp.RunUICatalogTopLevel() in D:\Repos\temp\gui.cs\UICatalog\UICatalog.cs:line 323
   at UICatalog.UICatalogApp.UICatalogMain(Options options) in D:\Repos\temp\gui.cs\UICatalog\UICatalog.cs:line 450
   at UICatalog.UICatalogApp.Main(String[] args) in D:\Repos\temp\gui.cs\UICatalog\UICatalog.cs:line 234

tznind avatar Mar 30 '25 09:03 tznind

Ok I can reproduce, you have to tick this to cause the breakage:

It crashes on my side without the legacy console enabled:

Image

GitHubThor avatar Mar 30 '25 09:03 GitHubThor

It crashes on my side without the legacy console enabled:

what do you get running

PS C:\Windows\System32> (Get-Item "C:\Windows\System32\conhost.exe").VersionInfo.FileVersion

tznind avatar Mar 30 '25 10:03 tznind

PS C:\Windows\System32> (Get-Item "C:\Windows\System32\conhost.exe").VersionInfo.FileVersion

I get an error but the version shows:

Image

Also here there are the cmd.exe details:

Image

GitHubThor avatar Mar 30 '25 10:03 GitHubThor

what do you get running

PS C:\Windows\System32> (Get-Item "C:\Windows\System32\conhost.exe").VersionInfo.FileVersion

Mine is:

10.0.26100.2308 (WinBuild.160101.0800)

BDisp avatar Mar 30 '25 10:03 BDisp

Ok I can reproduce, you have to tick this to cause the breakage:

Image

This is the properties window of the Command Prompt (cmd.exe). You also need to check the conhost.exe properties window.

BDisp avatar Mar 30 '25 10:03 BDisp

@GitHubThor you only need to write in a pwsh this command and not the whole line PS C:\Windows\System32> is the prompt:

(Get-Item "C:\Windows\System32\conhost.exe").VersionInfo.FileVersion

BDisp avatar Mar 30 '25 10:03 BDisp

@GitHubThor you only need to write in a pwsh this command and not the whole line PS C:\Windows\System32> is the prompt:

Done:

PS C:> (Get-Item "C:\Windows\System32\conhost.exe").VersionInfo.FileVersion 10.0.26100.1 (WinBuild.160101.0800)

I also have terminal settings at settings like this:

Image

GitHubThor avatar Mar 30 '25 11:03 GitHubThor