9b90806093
- Wheel buttons were encoded as 68/69 (64 + 4/5, i.e. Shift + wheel down/ wheel right); they are 64 up and 65 down. - Wheel, click and drag positions use the view's own screen cell: the wheel used the window position, and clicks used the buffer row (counting scrollback) instead of the screen row. Default encoding sent the row one too high. - A new TerminalMouseListener reports mouse presses, releases, drags (1002) and motion (1003, also without a button) from pointer events, with Ctrl/Alt modifiers. Before, a drag became a text selection and motion was never sent. Holding Shift at the press leaves the pointer to selection while the program owns the mouse. - The middle button's press and release were reported as the right button. SGR releases name the released button. - With mouse tracking on, the wheel is reported on the main screen too. - TerminalController reports every pointer input kind by default; the program's mouse mode decides what is sent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
106 lines
3.0 KiB
Dart
106 lines
3.0 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:xterm/xterm.dart';
|
|
|
|
import 'xterm_fixture.dart';
|
|
|
|
void main() {
|
|
const down = TerminalMouseButtonState.down;
|
|
const up = TerminalMouseButtonState.up;
|
|
const at = CellOffset(4, 2); // column 5, row 3 one-based
|
|
|
|
String report(
|
|
String modes,
|
|
TerminalMouseButton button,
|
|
TerminalMouseButtonState state, {
|
|
bool motion = false,
|
|
bool ctrl = false,
|
|
}) {
|
|
final t = FixtureTerminal()..feed(modes);
|
|
t.terminal.mouseInput(button, state, at, motion: motion, ctrl: ctrl);
|
|
return t.takeReplies();
|
|
}
|
|
|
|
test('SGR wheel is 64 up and 65 down', () {
|
|
const sgr = '\x1b[?1000h\x1b[?1006h';
|
|
expect(report(sgr, TerminalMouseButton.wheelUp, down), '\x1b[<64;5;3M');
|
|
expect(report(sgr, TerminalMouseButton.wheelDown, down), '\x1b[<65;5;3M');
|
|
expect(report(sgr, TerminalMouseButton.wheelUp, up), '');
|
|
});
|
|
|
|
test('default encoding: 32 + code, 32 + column, 32 + row', () {
|
|
const normal = '\x1b[?1000h';
|
|
expect(
|
|
report(normal, TerminalMouseButton.left, down),
|
|
'\x1b[M\x20\x25\x23',
|
|
);
|
|
expect(report(normal, TerminalMouseButton.left, up), '\x1b[M\x23\x25\x23');
|
|
expect(
|
|
report(normal, TerminalMouseButton.wheelDown, down),
|
|
'\x1b[M\x61\x25\x23',
|
|
);
|
|
});
|
|
|
|
test('SGR reports which button was released', () {
|
|
const sgr = '\x1b[?1000h\x1b[?1006h';
|
|
expect(report(sgr, TerminalMouseButton.middle, down), '\x1b[<1;5;3M');
|
|
expect(report(sgr, TerminalMouseButton.middle, up), '\x1b[<1;5;3m');
|
|
expect(report(sgr, TerminalMouseButton.right, up), '\x1b[<2;5;3m');
|
|
});
|
|
|
|
test('modifiers add 4/8/16', () {
|
|
const sgr = '\x1b[?1000h\x1b[?1006h';
|
|
expect(
|
|
report(sgr, TerminalMouseButton.left, down, ctrl: true),
|
|
'\x1b[<16;5;3M',
|
|
);
|
|
});
|
|
|
|
group('motion', () {
|
|
test('1000 reports no motion', () {
|
|
expect(
|
|
report(
|
|
'\x1b[?1000h\x1b[?1006h',
|
|
TerminalMouseButton.left,
|
|
down,
|
|
motion: true,
|
|
),
|
|
'',
|
|
);
|
|
});
|
|
|
|
test('1002 reports drags with the button held, plus 32', () {
|
|
const drag = '\x1b[?1002h\x1b[?1006h';
|
|
expect(
|
|
report(drag, TerminalMouseButton.left, down, motion: true),
|
|
'\x1b[<32;5;3M',
|
|
);
|
|
expect(report(drag, TerminalMouseButton.none, down, motion: true), '');
|
|
});
|
|
|
|
test('1003 reports motion without a button as 35', () {
|
|
expect(
|
|
report(
|
|
'\x1b[?1003h\x1b[?1006h',
|
|
TerminalMouseButton.none,
|
|
down,
|
|
motion: true,
|
|
),
|
|
'\x1b[<35;5;3M',
|
|
);
|
|
expect(
|
|
report('\x1b[?1003h', TerminalMouseButton.none, down, motion: true),
|
|
'\x1b[M\x43\x25\x23',
|
|
);
|
|
});
|
|
});
|
|
|
|
test('X10 mode (9) reports presses only', () {
|
|
expect(
|
|
report('\x1b[?9h', TerminalMouseButton.left, down),
|
|
'\x1b[M\x20\x25\x23',
|
|
);
|
|
expect(report('\x1b[?9h', TerminalMouseButton.left, up), '');
|
|
expect(report('\x1b[?9h', TerminalMouseButton.wheelUp, down), '');
|
|
});
|
|
}
|