Merge pull request #477 from mitchellh/notcurses-input

notcurses-input bugs
This commit is contained in:
Mitchell Hashimoto
2023-09-17 10:08:17 -07:00
committed by GitHub
2 changed files with 27 additions and 13 deletions

View File

@ -1283,8 +1283,11 @@ fn mouseReport(
mods: input.Mods,
pos: apprt.CursorPos,
) !void {
// TODO: posToViewport currently clamps to the surface boundary,
// do we want to not report mouse events at all outside the surface?
// The maximum pos values so we can determine if we're outside the window.
// If we're outside the window, we do not report mouse events.
const max_x: f32 = @floatFromInt(self.screen_size.width);
const max_y: f32 = @floatFromInt(self.screen_size.height);
if (pos.x < 0 or pos.y < 0 or pos.x > max_x or pos.y > max_y) return;
// Depending on the event, we may do nothing at all.
switch (self.io.terminal.flags.mouse_event) {
@ -1444,6 +1447,9 @@ fn mouseReport(
},
.sgr_pixels => {
assert(pos.x >= 0);
assert(pos.y >= 0);
// Final character to send in the CSI
const final: u8 = if (action == .release) 'm' else 'M';
@ -1452,8 +1458,8 @@ fn mouseReport(
var data: termio.Message.WriteReq.Small.Array = undefined;
const resp = try std.fmt.bufPrint(&data, "\x1B[<{d};{d};{d}{c}", .{
button_code,
pos.x,
pos.y,
@as(u32, @intFromFloat(@round(pos.x))),
@as(u32, @intFromFloat(@round(pos.y))),
final,
});

View File

@ -300,16 +300,24 @@ pub fn Stream(comptime Handler: type) type {
) else log.warn("unimplemented CSI callback: {}", .{action}),
// Scroll Up (SD)
'S' => if (@hasDecl(T, "scrollUp")) try self.handler.scrollUp(
switch (action.params.len) {
0 => 1,
1 => action.params[0],
else => {
log.warn("invalid scroll up command: {}", .{action});
return;
'S' => switch (action.intermediates.len) {
0 => if (@hasDecl(T, "scrollUp")) try self.handler.scrollUp(
switch (action.params.len) {
0 => 1,
1 => action.params[0],
else => {
log.warn("invalid scroll up command: {}", .{action});
return;
},
},
},
) else log.warn("unimplemented CSI callback: {}", .{action}),
) else log.warn("unimplemented CSI callback: {}", .{action}),
else => log.warn(
"ignoring unimplemented CSI S with intermediates: {s}",
.{action.intermediates},
),
},
// Scroll Down (SD)
'T' => if (@hasDecl(T, "scrollDown")) try self.handler.scrollDown(