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

Fixes #2793. Windows Terminal still show vertical scroll bar using WindowsDriver. #2794

Merged
22 changes: 14 additions & 8 deletions Terminal.Gui/ConsoleDrivers/WindowsDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ internal class WindowsDriver : ConsoleDriver {
WindowsConsole.SmallRect damageRegion;
IClipboard clipboard;
int [,,] contents;
readonly bool isWindowsTerminal;

public override int Cols => cols;
public override int Rows => rows;
Expand All @@ -732,6 +733,8 @@ public WindowsDriver ()
{
WinConsole = new WindowsConsole ();
clipboard = new WindowsClipboard ();

isWindowsTerminal = Environment.GetEnvironmentVariable ("WT_SESSION") != null;
}

public override void PrepareToRun (MainLoop mainLoop, Action<KeyEvent> keyHandler, Action<KeyEvent> keyDownHandler, Action<KeyEvent> keyUpHandler, Action<MouseEvent> mouseHandler)
Expand Down Expand Up @@ -1426,15 +1429,17 @@ public override void Init (Action terminalResized)

try {
// Needed for Windows Terminal
// ESC [ ? 1047 h Activate xterm alternative buffer (no backscroll)
// ESC [ ? 1047 l Restore xterm working buffer (with backscroll)
// ESC [ ? 1047 h Save cursor position and activate xterm alternative buffer (no backscroll)
// ESC [ ? 1047 l Restore cursor position and restore xterm working buffer (with backscroll)
// ESC [ ? 1048 h Save cursor position
// ESC [ ? 1048 l Restore cursor position
// ESC [ ? 1049 h Save cursor position and activate xterm alternative buffer (no backscroll)
// ESC [ ? 1049 l Restore cursor position and restore xterm working buffer (with backscroll)
// Per Issue #2264 using the alterantive screen buffer is required for Windows Terminal to not
// ESC [ ? 1049 h Activate xterm alternative buffer (no backscroll)
// ESC [ ? 1049 l Restore xterm working buffer (with backscroll)
// Per Issue #2264 using the alternative screen buffer is required for Windows Terminal to not
// wipe out the backscroll buffer when the application exits.
Console.Out.Write ("\x1b[?1047h");
if (isWindowsTerminal) {
Console.Out.Write ("\x1b[?1049h");
}

var winSize = WinConsole.GetConsoleOutputWindow (out Point pos);
cols = winSize.Width;
Expand Down Expand Up @@ -1676,12 +1681,13 @@ public override void UpdateCursor ()

public override void End ()
{

WinConsole.Cleanup ();
WinConsole = null;

// Disable alternative screen buffer.
Console.Out.Write ("\x1b[?1047l");
if (isWindowsTerminal) {
Console.Out.Write ("\x1b[?1049l");
}
}

/// <inheritdoc/>
Expand Down
7 changes: 6 additions & 1 deletion UICatalog/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@
"commandLineArgs": "\"Windows & FrameViews\""
},
"Docker": {
"commandName": "Docker"
"commandName": "Docker"
},
"UICatalog WT": {
"commandName": "Executable",
"executablePath": "wt",
"commandLineArgs": "UICatalog.exe"
}
}
}
Loading