From 9c2fc736b9ccd7b7eea11e7f544ed540d2d2a6c2 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 00:25:48 -0300 Subject: Term: input through the interface: Term.key writes a key's bytes as its program's keyboard protocol and modes ask, Term.mouse and Term.wheel a mouse event's and a wheel turn's, Term.paste a paste as xterm makes one, Term.modes is the plain record of the modes the core decides by (mouse, all motion, the wheel, focus, bracketed paste, the alternate screen) and Term.promptMoves how far a click on the prompt line moves the shell's cursor; the mouse's records (MouseMods, MouseButton, MouseAction) are the interface's; keys.forwardKey (the bytes queued, an error reported) and keys.enterTty (raw mode, the cursor handed to the shell) are the core's, in keys.zig, pardes.keys for the tests; bracketedPaste, reportsMouse, reportsFocus, ownsWheel, tracksAllMotion and onAlternateScreen go into the record; the tests that called them follow; nothing else changes --- src/Term.zig | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/Term.zig') diff --git a/src/Term.zig b/src/Term.zig index 41452757..504aef7a 100644 --- a/src/Term.zig +++ b/src/Term.zig @@ -77,3 +77,47 @@ pub const Grid = struct { /// memory for its pin). Taped: a screen-state replica, which feeds /// nothing, is told its authority's. pub const Told = struct { rows: []const i32, erased: []const bool, cleared: bool, alive: bool, failed: bool }; + +// ---- input ---- + +/// One key for its program, as the program's keyboard protocol and modes +/// ask for it, written out. +pub const key = terminal.key; +/// One mouse event for its program, as the mode and format it set ask for +/// it; empty when the program does not hear of it. +pub const mouse = terminal.mouse; +/// A wheel turn for its program; null when the wheel is not the program's. +pub const wheel = terminal.wheel; +/// A paste as xterm makes one: three parts, the text between the brackets +/// when the program set 2004. +pub const paste = terminal.paste; +/// The modes its program set that the core decides by (`Modes`). +pub const modes = terminal.modes; +/// How far left or right a click on the prompt line moves the shell's +/// cursor, at the prompt the cursor is at. +pub const promptMoves = terminal.promptMoves; + +/// The key a frontend read (Event.zig). +pub const Key = @import("Event.zig").Key; +pub const MouseMods = struct { shift: bool = false, alt: bool = false, ctrl: bool = false }; +pub const MouseButton = enum { left, middle, right, wheel_up, wheel_down, wheel_left, wheel_right }; +pub const MouseAction = enum { press, release, motion }; +/// Cursor-key presses: so many left, so many right. +pub const Moves = struct { left: usize = 0, right: usize = 0 }; + +/// The modes a program set that the core decides by. +pub const Modes = struct { + /// It tracks the mouse itself (1000, 1002, 1003). + mouse: bool = false, + /// ...every move of it (1003). + all_motion: bool = false, + /// A wheel over it is its own: it tracks the mouse, or it is on the + /// alternate screen with alternate scroll (1007). + wheel: bool = false, + /// It wants to hear focus in and out (1004). + focus: bool = false, + /// It wants its pastes bracketed (2004). + bracketed_paste: bool = false, + /// It has the alternate screen (1049). + alternate: bool = false, +}; -- cgit v1.3