mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-01-02 03:22:37 +00:00
input: use std.Io.Writer for key encoder, new API, expose via libghostty
This modernizes `KeyEncoder` to a new `std.Io.Writer`-based API. Additionally, instead of a single struct, it is now an `encode` function that takes a series of more focused options. This is more idiomatic Zig while also making it easier to expose via libghostty-vt. libghostty-vt also gains access to key encoding APIs.
This commit is contained in:
8
src/input/config.zig
Normal file
8
src/input/config.zig
Normal file
@@ -0,0 +1,8 @@
|
||||
/// Determines the macOS option key behavior. See the config
|
||||
/// `macos-option-as-alt` for a lot more details.
|
||||
pub const OptionAsAlt = enum(c_int) {
|
||||
false,
|
||||
true,
|
||||
left,
|
||||
right,
|
||||
};
|
||||
@@ -293,6 +293,11 @@ fn pcStyle(comptime fmt: []const u8) []Entry {
|
||||
|
||||
test "keys" {
|
||||
const testing = std.testing;
|
||||
switch (@import("terminal_options").artifact) {
|
||||
.ghostty => {},
|
||||
// Don't want to bring in termio into libghostty-vt
|
||||
.lib => return error.SkipZigTest,
|
||||
}
|
||||
|
||||
// Force resolution for comptime evaluation.
|
||||
_ = keys;
|
||||
|
||||
@@ -2,7 +2,7 @@ const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const cimgui = @import("cimgui");
|
||||
const config = @import("../config.zig");
|
||||
const OptionAsAlt = @import("config.zig").OptionAsAlt;
|
||||
|
||||
/// A generic key input event. This is the information that is necessary
|
||||
/// regardless of apprt in order to generate the proper terminal
|
||||
@@ -146,7 +146,7 @@ pub const Mods = packed struct(Mods.Backing) {
|
||||
/// Return the mods to use for key translation. This handles settings
|
||||
/// like macos-option-as-alt. The translation mods should be used for
|
||||
/// translation but never sent back in for the key callback.
|
||||
pub fn translation(self: Mods, option_as_alt: config.OptionAsAlt) Mods {
|
||||
pub fn translation(self: Mods, option_as_alt: OptionAsAlt) Mods {
|
||||
var result = self;
|
||||
|
||||
// macos-option-as-alt for darwin
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const OptionAsAlt = @import("../config.zig").OptionAsAlt;
|
||||
const OptionAsAlt = @import("config.zig").OptionAsAlt;
|
||||
|
||||
/// Keyboard layouts.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user