Skip to content

Commit a0c63f0

Browse files
authored
Merge pull request elfmz#2651 from Dazzar56/auto-locale-fix
vt mouse refactoring
2 parents 974287c + 7943fd0 commit a0c63f0

File tree

5 files changed

+145
-174
lines changed

5 files changed

+145
-174
lines changed

far2l/src/vt/IVTShell.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#pragma once
22
#include <string>
33

4-
enum MouseExpectation
4+
enum MouseMode
55
{
6-
MEX_X10_MOUSE = 0x00001,
7-
MEX_VT200_MOUSE = 0x00002,
8-
// MEX_VT200_HIGHLIGHT_MOUSE = 0x00004, irrelevant???
9-
MEX_BTN_EVENT_MOUSE = 0x00008,
10-
MEX_ANY_EVENT_MOUSE = 0x00010,
11-
MEX_SGR_EXT_MOUSE = 0x00020
6+
MODE_X10_MOUSE = 0x00001,
7+
MODE_VT200_MOUSE = 0x00002,
8+
// MODE_VT200_HIGHLIGHT_MOUSE = 0x00004, not used
9+
MODE_BTN_EVENT_MOUSE = 0x00008,
10+
MODE_ANY_EVENT_MOUSE = 0x00010,
11+
MODE_SGR_EXT_MOUSE = 0x00020
1212
};
1313

1414
struct IVTShell
1515
{
16-
virtual void OnMouseExpectation(MouseExpectation mex, bool enabled) = 0;
16+
virtual void OnMouseExpectation(MouseMode mex, bool enabled) = 0;
1717
virtual void OnBracketedPasteExpectation(bool enabled) = 0;
1818
virtual void OnFocusChangeExpectation(bool enabled) = 0;
1919
virtual void OnWin32InputMode(bool enabled) = 0;

far2l/src/vt/vtansi.cpp

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@ [email protected]
183183

184184
#include "vtlog.h"
185185

186-
enum AnsiMouseExpectation
186+
enum AnsiMouseModes
187187
{
188-
AMEX_X10_MOUSE = 9,
189-
AMEX_VT200_MOUSE = 1000,
190-
AMEX_VT200_HIGHLIGHT_MOUSE = 1001,
191-
AMEX_BTN_EVENT_MOUSE = 1002,
192-
AMEX_ANY_EVENT_MOUSE = 1003,
193-
AMEX_SGR_EXT_MOUSE = 1006
188+
SET_X10_MOUSE = 9,
189+
SET_VT200_MOUSE = 1000,
190+
SET_VT200_HIGHLIGHT_MOUSE = 1001,
191+
SET_BTN_EVENT_MOUSE = 1002,
192+
SET_ANY_EVENT_MOUSE = 1003,
193+
SET_SGR_EXT_MODE_MOUSE = 1006
194194
};
195195

196196
struct VTAnsiState
@@ -207,7 +207,7 @@ struct VTAnsiState
207207
memset(&csbi, 0, sizeof(csbi));
208208
memset(&cci, 0, sizeof(cci));
209209
}
210-
210+
211211
void InitFromConsole(HANDLE con)
212212
{
213213
WINPORT(GetConsoleScreenBufferInfo)( con, &csbi );
@@ -405,7 +405,7 @@ struct VTAnsiContext
405405
} while (++b, --chars_in_buffer);
406406
} else {
407407
fprintf(stderr, "TODODODODO\n");
408-
408+
409409
410410
// To detect wrapping of multiple characters, create a new buffer, write
411411
// to the top of it and see if the cursor changes line. This doesn't
@@ -780,21 +780,21 @@ struct VTAnsiContext
780780
if (prefix2 == '?' && (suffix == 'h' || suffix == 'l')) {
781781
for (i = 0; i < es_argc; ++i) {
782782
switch (es_argv[i]) {
783-
case AMEX_X10_MOUSE:
784-
vt_shell->OnMouseExpectation(MEX_X10_MOUSE, suffix == 'h');
783+
case SET_X10_MOUSE:
784+
vt_shell->OnMouseExpectation(MODE_X10_MOUSE, suffix == 'h');
785785
break;
786-
case AMEX_VT200_MOUSE:
787-
case AMEX_VT200_HIGHLIGHT_MOUSE:
788-
vt_shell->OnMouseExpectation(MEX_VT200_MOUSE, suffix == 'h');
786+
case SET_VT200_MOUSE:
787+
case SET_VT200_HIGHLIGHT_MOUSE:
788+
vt_shell->OnMouseExpectation(MODE_VT200_MOUSE, suffix == 'h');
789789
break;
790-
case AMEX_BTN_EVENT_MOUSE:
791-
vt_shell->OnMouseExpectation(MEX_BTN_EVENT_MOUSE, suffix == 'h');
790+
case SET_BTN_EVENT_MOUSE:
791+
vt_shell->OnMouseExpectation(MODE_BTN_EVENT_MOUSE, suffix == 'h');
792792
break;
793-
case AMEX_ANY_EVENT_MOUSE:
794-
vt_shell->OnMouseExpectation(MEX_ANY_EVENT_MOUSE, suffix == 'h');
793+
case SET_ANY_EVENT_MOUSE:
794+
vt_shell->OnMouseExpectation(MODE_ANY_EVENT_MOUSE, suffix == 'h');
795795
break;
796-
case AMEX_SGR_EXT_MOUSE:
797-
vt_shell->OnMouseExpectation(MEX_SGR_EXT_MOUSE, suffix == 'h');
796+
case SET_SGR_EXT_MODE_MOUSE:
797+
vt_shell->OnMouseExpectation(MODE_SGR_EXT_MOUSE, suffix == 'h');
798798
break;
799799

800800
// case 47: case 1047:
@@ -870,7 +870,7 @@ struct VTAnsiContext
870870
// Ignore any other private sequences.
871871
if (prefix2 != 0) {
872872
LogFailedEscSeq(StrPrintf("bad prefix2 %c", prefix2));
873-
return;
873+
return;
874874
}
875875

876876
WINPORT(GetConsoleScreenBufferInfo)( con_hnd, &Info );
@@ -974,7 +974,7 @@ struct VTAnsiContext
974974
WINPORT(ScrollConsoleScreenBuffer)( con_hnd, &Rect, &Info.srWindow, Pos, &CharInfo );
975975
}
976976
return;
977-
977+
978978
case 'T': // ESC[#T Scroll down
979979
if (es_argc == 0) es_argv[es_argc++] = 1; // ESC[T == ESC[1T
980980
if (es_argc != 1) return;
@@ -985,16 +985,16 @@ struct VTAnsiContext
985985
Rect.Right = Info.srWindow.Right = (Info.dwSize.X - 1);
986986
Rect.Top = Info.srWindow.Top;
987987
Rect.Bottom = Info.srWindow.Bottom - es_argv[0];
988-
988+
989989
Pos.X = 0;
990990
Pos.Y = Rect.Top + es_argv[0];
991991

992992
CI_SET_WCATTR(CharInfo, blank_character, Info.wAttributes);
993993
WINPORT(ScrollConsoleScreenBuffer)( con_hnd, &Rect, &Info.srWindow, Pos, &CharInfo );
994994
}
995995
return;
996-
997-
996+
997+
998998
case 'M': // ESC[#M Delete # lines.
999999
if (es_argc == 0) es_argv[es_argc++] = 1; // ESC[M == ESC[1M
10001000
if (es_argc != 1) return;
@@ -1227,14 +1227,14 @@ struct VTAnsiContext
12271227
case 'r':
12281228
if (es_argc < 2) {
12291229
es_argv[1] = MAXSHORT;
1230-
if (es_argc < 1)
1230+
if (es_argc < 1)
12311231
es_argv[0] = 1;
12321232
}
1233-
fprintf(stderr, "VTAnsi: SET SCROLL REGION: %d %d (limits %d %d)\n",
1233+
fprintf(stderr, "VTAnsi: SET SCROLL REGION: %d %d (limits %d %d)\n",
12341234
es_argv[0] - 1, es_argv[1] - 1, Info.srWindow.Top, Info.srWindow.Bottom);
12351235
WINPORT(SetConsoleScrollRegion)(con_hnd, es_argv[0] - 1, es_argv[1] - 1);
12361236
return;
1237-
1237+
12381238
case 'c': // CSI P s c Send Device Attributes (Primary DA)
12391239
if (prefix2 == 0 && (es_argc < 1 || es_argv[0] == 0)) {
12401240
SendSequence("\e[?1;2c"); // → CSI ? 1 ; 2 c (‘‘VT100 with Advanced Video Option’’)
@@ -1336,32 +1336,32 @@ struct VTAnsiContext
13361336
void ForwardIndex()
13371337
{
13381338
fprintf(stderr, "ANSI: ForwardIndex\n");
1339-
FlushBuffer();
1339+
FlushBuffer();
13401340
}
13411341

13421342
void ReverseIndex()
13431343
{
13441344
fprintf(stderr, "ANSI: ReverseIndex\n");
13451345
FlushBuffer();
1346-
HANDLE con_hnd = vt_shell->ConsoleHandle();
1346+
HANDLE con_hnd = vt_shell->ConsoleHandle();
13471347
CONSOLE_SCREEN_BUFFER_INFO info;
13481348
WINPORT(GetConsoleScreenBufferInfo)( con_hnd, &info );
13491349
SHORT scroll_top = 0, scroll_bottom = 0x7fff;
13501350
WINPORT(GetConsoleScrollRegion)(con_hnd, &scroll_top, &scroll_bottom);
1351-
1351+
13521352
if (scroll_top < info.srWindow.Top) scroll_top = info.srWindow.Top;
13531353
if (scroll_bottom < info.srWindow.Top) scroll_bottom = info.srWindow.Top;
1354-
1354+
13551355
if (scroll_top > info.srWindow.Bottom) scroll_top = info.srWindow.Bottom;
1356-
1356+
13571357
if (scroll_bottom > info.srWindow.Bottom) scroll_bottom = info.srWindow.Bottom;
1358-
1359-
if (info.dwCursorPosition.Y != scroll_top) {
1358+
1359+
if (info.dwCursorPosition.Y != scroll_top) {
13601360
info.dwCursorPosition.Y--;
13611361
WINPORT(SetConsoleCursorPosition)(con_hnd, info.dwCursorPosition);
13621362
return;
13631363
}
1364-
1364+
13651365
if (scroll_top>=scroll_bottom)
13661366
return;
13671367

@@ -1547,8 +1547,8 @@ struct VTAnsiContext
15471547
}
15481548

15491549
if (done) {
1550-
if (state == 6)
1551-
InterpretControlString();
1550+
if (state == 6)
1551+
InterpretControlString();
15521552
else
15531553
InterpretEscSeq();
15541554
state = 1;
@@ -1595,7 +1595,7 @@ struct VTAnsiContext
15951595
VTAnsiContext()
15961596
: alternative_screen_buffer(*this)
15971597
{
1598-
}
1598+
}
15991599
};
16001600

16011601

@@ -1606,9 +1606,9 @@ VTAnsi::VTAnsi(IVTShell *vtsh)
16061606
_ctx->ResetTerminal();
16071607
_ctx->saved_state.InitFromConsole(_ctx->vt_shell->ConsoleHandle());
16081608
_ctx->ansi_state.font_state.FromConsoleAttributes(_ctx->saved_state.csbi.wAttributes);
1609-
1609+
16101610
VTLog::Start();
1611-
1611+
16121612
// get_state();
16131613
}
16141614

0 commit comments

Comments
 (0)