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 #2305. Improves the handling of escape sequence. #2375

Merged
merged 43 commits into from
Feb 25, 2023
Merged
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2c3c396
Changed ansi esc sequence used on exit.
tig Jan 1, 2023
7dec9f7
Changed ansi esc sequence used on exit.
tig Jan 1, 2023
1560267
Merge branch 'develop' into fixes_2261_scroll_buffer_cleared_on_exit
tig Jan 2, 2023
c5ebfcf
Improves HeightAsBuffer although currently only works on Windows.
BDisp Jan 14, 2023
1aab780
Fixes #2267. Toplevel.EnsureVisibleBounds throws an exception if bord…
BDisp Jan 3, 2023
c23cbd5
Changing comment as requested.
BDisp Jan 18, 2023
de45dd9
Fixes indentation.
BDisp Jan 18, 2023
4832e73
Seems not needed for now, maybe some update, comment for now.
BDisp Jan 18, 2023
2e55705
Renamed HeightAsBuffer to EnableConsoleScrolling and made it obsolete.
BDisp Jan 18, 2023
7c832e8
Add comment on remarks for EnableConsoleScrolling.
BDisp Jan 18, 2023
47b3acf
Merge pull request #8 from BDisp/fixes_2261_scroll_buffer_cleared_on_…
tig Jan 22, 2023
ad13b85
merged @bdisp's EnableConsoleScrolling PR
tig Jan 22, 2023
acb6060
Fixes buffer for Windows Terminal.
BDisp Jan 22, 2023
d56b4dc
Fixes issue in Windows Terminal on resizing causing some lines not be…
BDisp Jan 22, 2023
2e8dbf9
merge #9
tig Jan 23, 2023
12e664e
merged #9
tig Jan 23, 2023
912b0e7
use ESC [ ? 1047
tig Jan 23, 2023
f3d1284
Tweaks with new esc codes
tig Jan 23, 2023
697e068
Fixed curses driver to not nuke scroll buffer and to resize properly
tig Jan 23, 2023
e85fd20
merge
tig Jan 23, 2023
202f0f0
Cleand up netdriver escape codes
tig Jan 24, 2023
76d51a0
Merge branch 'fixes_2261_scroll_buffer_cleared_on_exit' of tig:tig/Te…
tig Jan 24, 2023
c462c3b
fixed spaces->tabs
tig Jan 24, 2023
7298eee
fixed spaces->tabs
tig Jan 24, 2023
9576a91
fixed spaces->tabs
tig Jan 24, 2023
f90a482
fixed spaces->tabs
tig Jan 24, 2023
636904f
fixed merge issue and spaces->tabs
tig Jan 24, 2023
0695904
fixed spaces->tabs
tig Jan 24, 2023
ce37be8
fixed spaces->tabs
tig Jan 24, 2023
60524c7
fixed spaces->tabs
tig Jan 24, 2023
89fd87e
fixed build error
tig Jan 24, 2023
c95ce32
removed old comments
tig Jan 24, 2023
fe6cd77
Merge branch 'develop' into fixes_2261_scroll_buffer_cleared_on_exit
tig Jan 25, 2023
372f3fa
Merge branch 'develop' into fixes_2261_scroll_buffer_cleared_on_exit
tig Feb 5, 2023
436715f
Resolving merge conflicts.
BDisp Feb 24, 2023
8369418
Resolving merge conflicts.
BDisp Feb 24, 2023
d53fe68
Ensuring reset the EnableConsoleScrolling.
BDisp Feb 24, 2023
a1b42f7
Changing from HeightAsBuffer to EnableConsoleScrolling.
BDisp Feb 24, 2023
66d0753
Done requested changes.
BDisp Feb 24, 2023
9a73e70
Reformatting.
BDisp Feb 24, 2023
09e69d5
Rename to EscSeqReqStatus.
BDisp Feb 24, 2023
5c63d1d
Removing Console.Out.Flush ();
BDisp Feb 24, 2023
e540028
Merge branch 'develop' into escape-sequence-utils_2305
tig Feb 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed spaces->tabs
  • Loading branch information
tig committed Jan 24, 2023
commit c462c3b48b32b7a35b797a5c9d91d066e906cc1e
152 changes: 76 additions & 76 deletions Terminal.Gui/ConsoleDrivers/NetDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void WaitWinChange ()
} else {
largestWindowHeight = Math.Max (Console.BufferHeight, largestWindowHeight);
if (Console.BufferWidth != consoleDriver.Cols || Console.BufferHeight != consoleDriver.Rows
|| Console.WindowHeight != lastWindowHeight) {
|| Console.WindowHeight != lastWindowHeight) {
lastWindowHeight = Math.Max (Console.WindowHeight, 0);
GetWindowSizeEvent (new Size (Console.BufferWidth, largestWindowHeight));
return;
Expand Down Expand Up @@ -225,7 +225,7 @@ void GetConsoleInputType (ConsoleKeyInfo consoleKeyInfo)
var keyChar = consoleKeyInfo.KeyChar;
switch ((uint)keyChar) {
case 0:
if (consoleKeyInfo.Key == (ConsoleKey)64) { // Ctrl+Space in Windows.
if (consoleKeyInfo.Key == (ConsoleKey)64) { // Ctrl+Space in Windows.
newConsoleKeyInfo = new ConsoleKeyInfo (' ', ConsoleKey.Spacebar,
(consoleKeyInfo.Modifiers & ConsoleModifiers.Shift) != 0,
(consoleKeyInfo.Modifiers & ConsoleModifiers.Alt) != 0,
Expand Down Expand Up @@ -270,9 +270,9 @@ void GetConsoleInputType (ConsoleKeyInfo consoleKeyInfo)
return;
case 127:
newConsoleKeyInfo = new ConsoleKeyInfo (consoleKeyInfo.KeyChar, ConsoleKey.Backspace,
(consoleKeyInfo.Modifiers & ConsoleModifiers.Shift) != 0,
(consoleKeyInfo.Modifiers & ConsoleModifiers.Alt) != 0,
(consoleKeyInfo.Modifiers & ConsoleModifiers.Control) != 0);
(consoleKeyInfo.Modifiers & ConsoleModifiers.Shift) != 0,
(consoleKeyInfo.Modifiers & ConsoleModifiers.Alt) != 0,
(consoleKeyInfo.Modifiers & ConsoleModifiers.Control) != 0);
break;
default:
newConsoleKeyInfo = consoleKeyInfo;
Expand Down Expand Up @@ -366,56 +366,56 @@ void DecodeCSI (ref InputResult inputResult, ref ConsoleKeyInfo newConsoleKeyInf
if ((uint)cki [1].KeyChar >= 1 && (uint)cki [1].KeyChar <= 26) {
key = (ConsoleKey)(char)(cki [1].KeyChar + (uint)ConsoleKey.A - 1);
newConsoleKeyInfo = new ConsoleKeyInfo (cki [1].KeyChar,
key,
false,
true,
true);
key,
false,
true,
true);
} else {
if (cki [1].KeyChar >= 97 && cki [1].KeyChar <= 122) {
key = (ConsoleKey)cki [1].KeyChar.ToString ().ToUpper () [0];
} else {
key = (ConsoleKey)cki [1].KeyChar;
}
newConsoleKeyInfo = new ConsoleKeyInfo ((char)key,
(ConsoleKey)Math.Min ((uint)key, 255),
false,
true,
false);
(ConsoleKey)Math.Min ((uint)key, 255),
false,
true,
false);
}
break;
case 3:
if (cki [1].KeyChar == '[' || cki [1].KeyChar == 79) {
key = GetConsoleKey (cki [2].KeyChar, ref mod, cki.Length);
}
newConsoleKeyInfo = new ConsoleKeyInfo ('\0',
key,
(mod & ConsoleModifiers.Shift) != 0,
(mod & ConsoleModifiers.Alt) != 0,
(mod & ConsoleModifiers.Control) != 0);
key,
(mod & ConsoleModifiers.Shift) != 0,
(mod & ConsoleModifiers.Alt) != 0,
(mod & ConsoleModifiers.Control) != 0);
break;
case 4:
if (cki [1].KeyChar == '[' && cki [3].KeyChar == 126) {
key = GetConsoleKey (cki [2].KeyChar, ref mod, cki.Length);
newConsoleKeyInfo = new ConsoleKeyInfo ('\0',
key,
(mod & ConsoleModifiers.Shift) != 0,
(mod & ConsoleModifiers.Alt) != 0,
(mod & ConsoleModifiers.Control) != 0);
key,
(mod & ConsoleModifiers.Shift) != 0,
(mod & ConsoleModifiers.Alt) != 0,
(mod & ConsoleModifiers.Control) != 0);
}
break;
case 5:
if (cki [1].KeyChar == '[' && (cki [2].KeyChar == 49 || cki [2].KeyChar == 50)
&& cki [4].KeyChar == 126) {
&& cki [4].KeyChar == 126) {
key = GetConsoleKey (cki [3].KeyChar, ref mod, cki.Length);
} else if (cki [1].KeyChar == 49 && cki [2].KeyChar == ';') { // For WSL
mod |= GetConsoleModifiers (cki [3].KeyChar);
key = ConsoleKey.End;
}
newConsoleKeyInfo = new ConsoleKeyInfo ('\0',
key,
(mod & ConsoleModifiers.Shift) != 0,
(mod & ConsoleModifiers.Alt) != 0,
(mod & ConsoleModifiers.Control) != 0);
key,
(mod & ConsoleModifiers.Shift) != 0,
(mod & ConsoleModifiers.Alt) != 0,
(mod & ConsoleModifiers.Control) != 0);
break;
case 6:
if (cki [1].KeyChar == '[' && cki [2].KeyChar == 49 && cki [3].KeyChar == ';') {
Expand All @@ -426,10 +426,10 @@ void DecodeCSI (ref InputResult inputResult, ref ConsoleKeyInfo newConsoleKeyInf
key = GetConsoleKey (cki [2].KeyChar, ref mod, cki.Length);
}
newConsoleKeyInfo = new ConsoleKeyInfo ('\0',
key,
(mod & ConsoleModifiers.Shift) != 0,
(mod & ConsoleModifiers.Alt) != 0,
(mod & ConsoleModifiers.Control) != 0);
key,
(mod & ConsoleModifiers.Shift) != 0,
(mod & ConsoleModifiers.Alt) != 0,
(mod & ConsoleModifiers.Control) != 0);
break;
case 7:
GetRequestEvent (GetKeyCharArray (cki));
Expand Down Expand Up @@ -561,7 +561,7 @@ void GetMouseEvent (ConsoleKeyInfo [] cki)
case 48:
case 56:
buttonState = c == 'M' ? MouseButtonState.Button1Pressed
: MouseButtonState.Button1Released;
: MouseButtonState.Button1Released;
break;
case 1:
case 9:
Expand All @@ -576,7 +576,7 @@ void GetMouseEvent (ConsoleKeyInfo [] cki)
case 57:
case 61:
buttonState = c == 'M' ? MouseButtonState.Button2Pressed
: MouseButtonState.Button2Released;
: MouseButtonState.Button2Released;
break;
case 2:
case 10:
Expand All @@ -593,7 +593,7 @@ void GetMouseEvent (ConsoleKeyInfo [] cki)
case 58:
case 62:
buttonState = c == 'M' ? MouseButtonState.Button3Pressed
: MouseButtonState.Button3Released;
: MouseButtonState.Button3Released;
break;
case 35:
case 39:
Expand All @@ -613,12 +613,12 @@ void GetMouseEvent (ConsoleKeyInfo [] cki)
case 68:
case 72:
case 80:
buttonState = MouseButtonState.ButtonWheeledLeft; // Shift/Ctrl+ButtonWheeledUp
buttonState = MouseButtonState.ButtonWheeledLeft; // Shift/Ctrl+ButtonWheeledUp
break;
case 69:
case 73:
case 81:
buttonState = MouseButtonState.ButtonWheeledRight; // Shift/Ctrl+ButtonWheeledDown
buttonState = MouseButtonState.ButtonWheeledRight; // Shift/Ctrl+ButtonWheeledDown
break;
}
// Modifiers.
Expand Down Expand Up @@ -710,8 +710,8 @@ void GetMouseEvent (ConsoleKeyInfo [] cki)
}

if ((buttonState & MouseButtonState.Button1Pressed) != 0
|| (buttonState & MouseButtonState.Button2Pressed) != 0
|| (buttonState & MouseButtonState.Button3Pressed) != 0) {
|| (buttonState & MouseButtonState.Button2Pressed) != 0
|| (buttonState & MouseButtonState.Button3Pressed) != 0) {

if ((buttonState & MouseButtonState.ReportMousePosition) == 0) {
buttonPressedCount++;
Expand All @@ -726,18 +726,18 @@ void GetMouseEvent (ConsoleKeyInfo [] cki)
}

if (buttonPressedCount == 2 && !isButtonDoubleClicked
&& (lastMouseEvent.ButtonState == MouseButtonState.Button1Pressed
|| lastMouseEvent.ButtonState == MouseButtonState.Button2Pressed
|| lastMouseEvent.ButtonState == MouseButtonState.Button3Pressed)) {
&& (lastMouseEvent.ButtonState == MouseButtonState.Button1Pressed
|| lastMouseEvent.ButtonState == MouseButtonState.Button2Pressed
|| lastMouseEvent.ButtonState == MouseButtonState.Button3Pressed)) {

isButtonDoubleClicked = true;
ProcessButtonDoubleClicked (mouseEvent);
inputReady.Set ();
return;
} else if (buttonPressedCount == 3 && isButtonDoubleClicked
&& (lastMouseEvent.ButtonState == MouseButtonState.Button1Pressed
|| lastMouseEvent.ButtonState == MouseButtonState.Button2Pressed
|| lastMouseEvent.ButtonState == MouseButtonState.Button3Pressed)) {
&& (lastMouseEvent.ButtonState == MouseButtonState.Button1Pressed
|| lastMouseEvent.ButtonState == MouseButtonState.Button2Pressed
|| lastMouseEvent.ButtonState == MouseButtonState.Button3Pressed)) {

isButtonDoubleClicked = false;
isButtonTripleClicked = true;
Expand All @@ -750,9 +750,9 @@ void GetMouseEvent (ConsoleKeyInfo [] cki)

//System.Diagnostics.Debug.WriteLine ($"isButtonClicked: {isButtonClicked} isButtonDoubleClicked: {isButtonDoubleClicked} isButtonTripleClicked: {isButtonTripleClicked}");
if ((isButtonClicked || isButtonDoubleClicked || isButtonTripleClicked)
&& ((buttonState & MouseButtonState.Button1Released) != 0
|| (buttonState & MouseButtonState.Button2Released) != 0
|| (buttonState & MouseButtonState.Button3Released) != 0)) {
&& ((buttonState & MouseButtonState.Button1Released) != 0
|| (buttonState & MouseButtonState.Button2Released) != 0
|| (buttonState & MouseButtonState.Button3Released) != 0)) {

//isButtonClicked = false;
//isButtonDoubleClicked = false;
Expand All @@ -762,12 +762,12 @@ void GetMouseEvent (ConsoleKeyInfo [] cki)
}

if (isButtonClicked && !isButtonDoubleClicked && lastMouseEvent.Position != default && lastMouseEvent.Position == point
&& ((buttonState & MouseButtonState.Button1Pressed) != 0
|| (buttonState & MouseButtonState.Button2Pressed) != 0
|| (buttonState & MouseButtonState.Button3Pressed) != 0
|| (buttonState & MouseButtonState.Button1Released) != 0
|| (buttonState & MouseButtonState.Button2Released) != 0
|| (buttonState & MouseButtonState.Button3Released) != 0)) {
&& ((buttonState & MouseButtonState.Button1Pressed) != 0
|| (buttonState & MouseButtonState.Button2Pressed) != 0
|| (buttonState & MouseButtonState.Button3Pressed) != 0
|| (buttonState & MouseButtonState.Button1Released) != 0
|| (buttonState & MouseButtonState.Button2Released) != 0
|| (buttonState & MouseButtonState.Button3Released) != 0)) {

isButtonClicked = false;
isButtonDoubleClicked = true;
Expand All @@ -783,12 +783,12 @@ void GetMouseEvent (ConsoleKeyInfo [] cki)
return;
}
if (isButtonDoubleClicked && lastMouseEvent.Position != default && lastMouseEvent.Position == point
&& ((buttonState & MouseButtonState.Button1Pressed) != 0
|| (buttonState & MouseButtonState.Button2Pressed) != 0
|| (buttonState & MouseButtonState.Button3Pressed) != 0
|| (buttonState & MouseButtonState.Button1Released) != 0
|| (buttonState & MouseButtonState.Button2Released) != 0
|| (buttonState & MouseButtonState.Button3Released) != 0)) {
&& ((buttonState & MouseButtonState.Button1Pressed) != 0
|| (buttonState & MouseButtonState.Button2Pressed) != 0
|| (buttonState & MouseButtonState.Button3Pressed) != 0
|| (buttonState & MouseButtonState.Button1Released) != 0
|| (buttonState & MouseButtonState.Button2Released) != 0
|| (buttonState & MouseButtonState.Button3Released) != 0)) {

isButtonDoubleClicked = false;
isButtonTripleClicked = true;
Expand All @@ -813,10 +813,10 @@ void GetMouseEvent (ConsoleKeyInfo [] cki)
});

if (!isButtonClicked && !lastMouseEvent.ButtonState.HasFlag (MouseButtonState.ReportMousePosition)
&& lastMouseEvent.Position != default && lastMouseEvent.Position == point
&& ((buttonState & MouseButtonState.Button1Released) != 0
|| (buttonState & MouseButtonState.Button2Released) != 0
|| (buttonState & MouseButtonState.Button3Released) != 0)) {
&& lastMouseEvent.Position != default && lastMouseEvent.Position == point
&& ((buttonState & MouseButtonState.Button1Released) != 0
|| (buttonState & MouseButtonState.Button2Released) != 0
|| (buttonState & MouseButtonState.Button3Released) != 0)) {
isButtonClicked = true;
ProcessButtonClicked (mouseEvent);
Application.MainLoop.AddIdle (() => {
Expand Down Expand Up @@ -1232,12 +1232,12 @@ public override void AddRune (Rune rune)

if (validClip) {
if (runeWidth < 2 && ccol > 0
&& Rune.ColumnWidth ((char)contents [crow, ccol - 1, 0]) > 1) {
&& Rune.ColumnWidth ((char)contents [crow, ccol - 1, 0]) > 1) {

contents [crow, ccol - 1, 0] = (int)(uint)' ';

} else if (runeWidth < 2 && ccol <= Clip.Right - 1
&& Rune.ColumnWidth ((char)contents [crow, ccol, 0]) > 1) {
&& Rune.ColumnWidth ((char)contents [crow, ccol, 0]) > 1) {

contents [crow, ccol + 1, 0] = (int)(uint)' ';
contents [crow, ccol + 1, 2] = 1;
Expand Down Expand Up @@ -1304,10 +1304,10 @@ static Attribute MakeColor (ConsoleColor f, ConsoleColor b)
{
// Encode the colors into the int value.
return new Attribute (
value: ((((int)f) & 0xffff) << 16) | (((int)b) & 0xffff),
foreground: (Color)f,
background: (Color)b
);
value: ((((int)f) & 0xffff) << 16) | (((int)b) & 0xffff),
foreground: (Color)f,
background: (Color)b
);
}

public override void Init (Action terminalResized)
Expand Down Expand Up @@ -1360,7 +1360,7 @@ public override void ResizeScreen ()
} else {
//Console.Out.Write ($"\x1b[8;{Console.WindowHeight};{Console.WindowWidth}t");
Console.Out.Write ($"\x1b[0;0" +
$";{Rows};{Cols}w");
$";{Rows};{Cols}w");
}
} catch (System.IO.IOException) {
setClip ();
Expand Down Expand Up @@ -1389,7 +1389,7 @@ public override void ResizeScreen ()
}
} else {
Console.Out.Write ($"\x1b[{top};{Console.WindowLeft}" +
$";{Rows};{Cols}w");
$";{Rows};{Cols}w");
}
}
setClip ();
Expand Down Expand Up @@ -1444,8 +1444,8 @@ public override void Refresh ()
public override void UpdateScreen ()
{
if (Console.WindowHeight == 0 || contents.Length != Rows * Cols * 3
|| (!EnableConsoleScrolling && Rows != Console.WindowHeight)
|| (EnableConsoleScrolling && Rows != largestBufferHeight)) {
|| (!EnableConsoleScrolling && Rows != Console.WindowHeight)
|| (EnableConsoleScrolling && Rows != largestBufferHeight)) {
return;
}

Expand Down Expand Up @@ -1539,8 +1539,8 @@ System.Text.StringBuilder WriteAttributes (int attr)

redrawAttr = attr;
IEnumerable<int> values = Enum.GetValues (typeof (ConsoleColor))
.OfType<ConsoleColor> ()
.Select (s => (int)s);
.OfType<ConsoleColor> ()
.Select (s => (int)s);
if (values.Contains (attr & 0xffff)) {
bg = MapColors ((ConsoleColor)(attr & 0xffff), false);
}
Expand Down Expand Up @@ -1994,8 +1994,8 @@ public override bool GetColors (int value, out Color foreground, out Color backg
foreground = default;
background = default;
IEnumerable<int> values = Enum.GetValues (typeof (ConsoleColor))
.OfType<ConsoleColor> ()
.Select (s => (int)s);
.OfType<ConsoleColor> ()
.Select (s => (int)s);
if (values.Contains (value & 0xffff)) {
hasColor = true;
background = (Color)(ConsoleColor)(value & 0xffff);
Expand Down