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

vt mouse refactoring #2651

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 8 additions & 8 deletions far2l/src/vt/IVTShell.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#pragma once
#include <string>

enum MouseExpectation
enum MouseMode
{
MEX_X10_MOUSE = 0x00001,
MEX_VT200_MOUSE = 0x00002,
// MEX_VT200_HIGHLIGHT_MOUSE = 0x00004, irrelevant???
MEX_BTN_EVENT_MOUSE = 0x00008,
MEX_ANY_EVENT_MOUSE = 0x00010,
MEX_SGR_EXT_MOUSE = 0x00020
MODE_X10_MOUSE = 0x00001,
MODE_VT200_MOUSE = 0x00002,
// MODE_VT200_HIGHLIGHT_MOUSE = 0x00004, not used
MODE_BTN_EVENT_MOUSE = 0x00008,
MODE_ANY_EVENT_MOUSE = 0x00010,
MODE_SGR_EXT_MOUSE = 0x00020
};

struct IVTShell
{
virtual void OnMouseExpectation(MouseExpectation mex, bool enabled) = 0;
virtual void OnMouseExpectation(MouseMode mex, bool enabled) = 0;
virtual void OnBracketedPasteExpectation(bool enabled) = 0;
virtual void OnFocusChangeExpectation(bool enabled) = 0;
virtual void OnWin32InputMode(bool enabled) = 0;
Expand Down
82 changes: 41 additions & 41 deletions far2l/src/vt/vtansi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@ [email protected]

#include "vtlog.h"

enum AnsiMouseExpectation
enum AnsiMouseModes
{
AMEX_X10_MOUSE = 9,
AMEX_VT200_MOUSE = 1000,
AMEX_VT200_HIGHLIGHT_MOUSE = 1001,
AMEX_BTN_EVENT_MOUSE = 1002,
AMEX_ANY_EVENT_MOUSE = 1003,
AMEX_SGR_EXT_MOUSE = 1006
SET_X10_MOUSE = 9,
SET_VT200_MOUSE = 1000,
SET_VT200_HIGHLIGHT_MOUSE = 1001,
SET_BTN_EVENT_MOUSE = 1002,
SET_ANY_EVENT_MOUSE = 1003,
SET_SGR_EXT_MODE_MOUSE = 1006
};

struct VTAnsiState
Expand All @@ -206,7 +206,7 @@ struct VTAnsiState
memset(&csbi, 0, sizeof(csbi));
memset(&cci, 0, sizeof(cci));
}

void InitFromConsole(HANDLE con)
{
WINPORT(GetConsoleScreenBufferInfo)( con, &csbi );
Expand Down Expand Up @@ -404,7 +404,7 @@ struct VTAnsiContext
} while (++b, --chars_in_buffer);
} else {
fprintf(stderr, "TODODODODO\n");


// To detect wrapping of multiple characters, create a new buffer, write
// to the top of it and see if the cursor changes line. This doesn't
Expand Down Expand Up @@ -779,21 +779,21 @@ struct VTAnsiContext
if (prefix2 == '?' && (suffix == 'h' || suffix == 'l')) {
for (i = 0; i < es_argc; ++i) {
switch (es_argv[i]) {
case AMEX_X10_MOUSE:
vt_shell->OnMouseExpectation(MEX_X10_MOUSE, suffix == 'h');
case SET_X10_MOUSE:
vt_shell->OnMouseExpectation(MODE_X10_MOUSE, suffix == 'h');
break;
case AMEX_VT200_MOUSE:
case AMEX_VT200_HIGHLIGHT_MOUSE:
vt_shell->OnMouseExpectation(MEX_VT200_MOUSE, suffix == 'h');
case SET_VT200_MOUSE:
case SET_VT200_HIGHLIGHT_MOUSE:
vt_shell->OnMouseExpectation(MODE_VT200_MOUSE, suffix == 'h');
break;
case AMEX_BTN_EVENT_MOUSE:
vt_shell->OnMouseExpectation(MEX_BTN_EVENT_MOUSE, suffix == 'h');
case SET_BTN_EVENT_MOUSE:
vt_shell->OnMouseExpectation(MODE_BTN_EVENT_MOUSE, suffix == 'h');
break;
case AMEX_ANY_EVENT_MOUSE:
vt_shell->OnMouseExpectation(MEX_ANY_EVENT_MOUSE, suffix == 'h');
case SET_ANY_EVENT_MOUSE:
vt_shell->OnMouseExpectation(MODE_ANY_EVENT_MOUSE, suffix == 'h');
break;
case AMEX_SGR_EXT_MOUSE:
vt_shell->OnMouseExpectation(MEX_SGR_EXT_MOUSE, suffix == 'h');
case SET_SGR_EXT_MODE_MOUSE:
vt_shell->OnMouseExpectation(MODE_SGR_EXT_MOUSE, suffix == 'h');
break;

// case 47: case 1047:
Expand Down Expand Up @@ -868,7 +868,7 @@ struct VTAnsiContext
// Ignore any other private sequences.
if (prefix2 != 0) {
LogFailedEscSeq(StrPrintf("bad prefix2 %c", prefix2));
return;
return;
}

WINPORT(GetConsoleScreenBufferInfo)( con_hnd, &Info );
Expand Down Expand Up @@ -972,7 +972,7 @@ struct VTAnsiContext
WINPORT(ScrollConsoleScreenBuffer)( con_hnd, &Rect, &Info.srWindow, Pos, &CharInfo );
}
return;

case 'T': // ESC[#T Scroll down
if (es_argc == 0) es_argv[es_argc++] = 1; // ESC[T == ESC[1T
if (es_argc != 1) return;
Expand All @@ -983,16 +983,16 @@ struct VTAnsiContext
Rect.Right = Info.srWindow.Right = (Info.dwSize.X - 1);
Rect.Top = Info.srWindow.Top;
Rect.Bottom = Info.srWindow.Bottom - es_argv[0];

Pos.X = 0;
Pos.Y = Rect.Top + es_argv[0];

CI_SET_WCATTR(CharInfo, blank_character, Info.wAttributes);
WINPORT(ScrollConsoleScreenBuffer)( con_hnd, &Rect, &Info.srWindow, Pos, &CharInfo );
}
return;


case 'M': // ESC[#M Delete # lines.
if (es_argc == 0) es_argv[es_argc++] = 1; // ESC[M == ESC[1M
if (es_argc != 1) return;
Expand Down Expand Up @@ -1225,14 +1225,14 @@ struct VTAnsiContext
case 'r':
if (es_argc < 2) {
es_argv[1] = MAXSHORT;
if (es_argc < 1)
if (es_argc < 1)
es_argv[0] = 1;
}
fprintf(stderr, "VTAnsi: SET SCROLL REGION: %d %d (limits %d %d)\n",
fprintf(stderr, "VTAnsi: SET SCROLL REGION: %d %d (limits %d %d)\n",
es_argv[0] - 1, es_argv[1] - 1, Info.srWindow.Top, Info.srWindow.Bottom);
WINPORT(SetConsoleScrollRegion)(con_hnd, es_argv[0] - 1, es_argv[1] - 1);
return;

case 'c': // CSI P s c Send Device Attributes (Primary DA)
if (prefix2 == 0 && (es_argc < 1 || es_argv[0] == 0)) {
SendSequence("\e[?1;2c"); // → CSI ? 1 ; 2 c (‘‘VT100 with Advanced Video Option’’)
Expand Down Expand Up @@ -1333,32 +1333,32 @@ struct VTAnsiContext
void ForwardIndex()
{
fprintf(stderr, "ANSI: ForwardIndex\n");
FlushBuffer();
FlushBuffer();
}

void ReverseIndex()
{
fprintf(stderr, "ANSI: ReverseIndex\n");
FlushBuffer();
HANDLE con_hnd = vt_shell->ConsoleHandle();
HANDLE con_hnd = vt_shell->ConsoleHandle();
CONSOLE_SCREEN_BUFFER_INFO info;
WINPORT(GetConsoleScreenBufferInfo)( con_hnd, &info );
SHORT scroll_top = 0, scroll_bottom = 0x7fff;
WINPORT(GetConsoleScrollRegion)(con_hnd, &scroll_top, &scroll_bottom);

if (scroll_top < info.srWindow.Top) scroll_top = info.srWindow.Top;
if (scroll_bottom < info.srWindow.Top) scroll_bottom = info.srWindow.Top;

if (scroll_top > info.srWindow.Bottom) scroll_top = info.srWindow.Bottom;

if (scroll_bottom > info.srWindow.Bottom) scroll_bottom = info.srWindow.Bottom;
if (info.dwCursorPosition.Y != scroll_top) {

if (info.dwCursorPosition.Y != scroll_top) {
info.dwCursorPosition.Y--;
WINPORT(SetConsoleCursorPosition)(con_hnd, info.dwCursorPosition);
return;
}

if (scroll_top>=scroll_bottom)
return;

Expand Down Expand Up @@ -1540,8 +1540,8 @@ struct VTAnsiContext
}

if (done) {
if (state == 6)
InterpretControlString();
if (state == 6)
InterpretControlString();
else
InterpretEscSeq();
state = 1;
Expand Down Expand Up @@ -1587,7 +1587,7 @@ struct VTAnsiContext
VTAnsiContext()
: alternative_screen_buffer(*this)
{
}
}
};


Expand All @@ -1598,9 +1598,9 @@ VTAnsi::VTAnsi(IVTShell *vtsh)
_ctx->ResetTerminal();
_ctx->saved_state.InitFromConsole(_ctx->vt_shell->ConsoleHandle());
_ctx->ansi_state.font_state.FromConsoleAttributes(_ctx->saved_state.csbi.wAttributes);

VTLog::Start();

// get_state();
}

Expand Down
Loading