-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Use NotifyEndApplication to re-enable VT mode instead of doing it in InputLoop.Run
#16612
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,28 +87,34 @@ internal ConsoleHostUserInterface(ConsoleHost parent) | |
|
|
||
| if (SupportsVirtualTerminal) | ||
| { | ||
| SupportsVirtualTerminal = TryTurnOnVtMode(); | ||
| SupportsVirtualTerminal = TryTurnOnVirtualTerminal(); | ||
| } | ||
| } | ||
|
|
||
| internal bool TryTurnOnVtMode() | ||
| internal bool TryTurnOnVirtualTerminal() | ||
| { | ||
| #if UNIX | ||
| return true; | ||
| #else | ||
| try | ||
| { | ||
| // Turn on virtual terminal if possible. | ||
|
|
||
| // This might throw - not sure how exactly (no console), but if it does, we shouldn't fail to start. | ||
| var handle = ConsoleControl.GetActiveScreenBufferHandle(); | ||
| var m = ConsoleControl.GetMode(handle); | ||
| if (ConsoleControl.NativeMethods.SetConsoleMode(handle.DangerousGetHandle(), (uint)(m | ConsoleControl.ConsoleModes.VirtualTerminal))) | ||
| var outputHandle = ConsoleControl.GetActiveScreenBufferHandle(); | ||
| var outputMode = ConsoleControl.GetMode(outputHandle); | ||
|
|
||
| if (outputMode.HasFlag(ConsoleControl.ConsoleModes.VirtualTerminal)) | ||
| { | ||
| return true; | ||
| } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the |
||
|
|
||
| outputMode |= ConsoleControl.ConsoleModes.VirtualTerminal; | ||
| if (ConsoleControl.NativeMethods.SetConsoleMode(outputHandle.DangerousGetHandle(), (uint)outputMode)) | ||
| { | ||
| // We only know if vt100 is supported if the previous call actually set the new flag, older | ||
| // systems ignore the setting. | ||
| m = ConsoleControl.GetMode(handle); | ||
| return (m & ConsoleControl.ConsoleModes.VirtualTerminal) != 0; | ||
| outputMode = ConsoleControl.GetMode(outputHandle); | ||
| return outputMode.HasFlag(ConsoleControl.ConsoleModes.VirtualTerminal); | ||
| } | ||
| } | ||
| catch | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -545,15 +545,14 @@ private void InitNativeProcess() | |
| Exception exceptionToRethrow = null; | ||
| try | ||
| { | ||
| // If this process is being run standalone, tell the host, which might want | ||
| // to save off the window title or other such state as might be tweaked by | ||
| // the native process | ||
| // Before start the executable, tell the host, which might want to save off the | ||
| // window title or other such state as might be tweaked by the native process. | ||
| Command.Context.EngineHostInterface.NotifyBeginApplication(); | ||
| _hasNotifiedBeginApplication = true; | ||
|
|
||
| if (_runStandAlone) | ||
| { | ||
| this.Command.Context.EngineHostInterface.NotifyBeginApplication(); | ||
| _hasNotifiedBeginApplication = true; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a native process tweaks the window title, it will do so no matter it's running |
||
|
|
||
| // Also, store the Raw UI coordinates so that we can scrape the screen after | ||
| // Store the Raw UI coordinates so that we can scrape the screen after | ||
| // if we are transcribing. | ||
| if (_isTranscribing && (s_supportScreenScrape == true)) | ||
| { | ||
|
|
@@ -1166,7 +1165,7 @@ private void CleanUp() | |
| // We need to call 'NotifyEndApplication' as appropriate during cleanup | ||
| if (_hasNotifiedBeginApplication) | ||
| { | ||
| this.Command.Context.EngineHostInterface.NotifyEndApplication(); | ||
| Command.Context.EngineHostInterface.NotifyEndApplication(); | ||
| } | ||
|
|
||
| try | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Interesting, is such console operations expensive?
In line 1105 we have already requested a handle and set mode, now TryTurnOnVirtualTerminal does the operations again. It seems we could do perf optimization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very likely not expensive, especially if this is done only after native command execution. The handle is already cached,
GetActiveScreenBufferHandle()returns a cached output handle.