mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
input: encoding should always write to the buf
This commit is contained in:
@ -11,7 +11,7 @@ const testing = std.testing;
|
|||||||
const key = @import("key.zig");
|
const key = @import("key.zig");
|
||||||
const function_keys = @import("function_keys.zig");
|
const function_keys = @import("function_keys.zig");
|
||||||
|
|
||||||
event: key.Event,
|
event: key.KeyEvent,
|
||||||
|
|
||||||
/// The state of various modes of a terminal that impact encoding.
|
/// The state of various modes of a terminal that impact encoding.
|
||||||
alt_esc_prefix: bool = false,
|
alt_esc_prefix: bool = false,
|
||||||
@ -46,7 +46,7 @@ pub fn legacy(
|
|||||||
self.cursor_key_application,
|
self.cursor_key_application,
|
||||||
self.keypad_key_application,
|
self.keypad_key_application,
|
||||||
self.modify_other_keys_state_2,
|
self.modify_other_keys_state_2,
|
||||||
)) |sequence| return sequence;
|
)) |sequence| return copyToBuf(buf, sequence);
|
||||||
|
|
||||||
// If we match a control sequence, we output that directly.
|
// If we match a control sequence, we output that directly.
|
||||||
if (ctrlSeq(self.event.key, binding_mods)) |char| {
|
if (ctrlSeq(self.event.key, binding_mods)) |char| {
|
||||||
@ -154,7 +154,15 @@ pub fn legacy(
|
|||||||
return try std.fmt.bufPrint(buf, "\x1B{s}", .{utf8});
|
return try std.fmt.bufPrint(buf, "\x1B{s}", .{utf8});
|
||||||
}
|
}
|
||||||
|
|
||||||
return utf8;
|
return try copyToBuf(buf, utf8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A helper to memcpy a src value to a buffer and return the result.
|
||||||
|
fn copyToBuf(buf: []u8, src: []const u8) ![]const u8 {
|
||||||
|
if (src.len > buf.len) return error.OutOfMemory;
|
||||||
|
const result = buf[0..src.len];
|
||||||
|
@memcpy(result, src);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determines whether the key should be encoded in the xterm
|
/// Determines whether the key should be encoded in the xterm
|
||||||
|
@ -9,7 +9,7 @@ const Allocator = std.mem.Allocator;
|
|||||||
/// as GLFW. In this case, the apprt should provide as much information
|
/// as GLFW. In this case, the apprt should provide as much information
|
||||||
/// as it can and it should be expected that the terminal behavior
|
/// as it can and it should be expected that the terminal behavior
|
||||||
/// will not be totally correct.
|
/// will not be totally correct.
|
||||||
pub const Event = struct {
|
pub const KeyEvent = struct {
|
||||||
/// The action: press, release, etc.
|
/// The action: press, release, etc.
|
||||||
action: Action = .press,
|
action: Action = .press,
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ pub const Event = struct {
|
|||||||
|
|
||||||
/// Returns the effective modifiers for this event. The effective
|
/// Returns the effective modifiers for this event. The effective
|
||||||
/// modifiers are the mods that should be considered for keybindings.
|
/// modifiers are the mods that should be considered for keybindings.
|
||||||
pub fn effectiveMods(self: Event) Mods {
|
pub fn effectiveMods(self: KeyEvent) Mods {
|
||||||
if (self.utf8.len == 0) return self.mods;
|
if (self.utf8.len == 0) return self.mods;
|
||||||
return self.mods.unset(self.consumed_mods);
|
return self.mods.unset(self.consumed_mods);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user