╭ input.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 const xit = @import("xit"); 2 const xitui = xit.xitui; 3 const Key = xitui.input.Key; 4 5 /// the vertical direction of a navigation key press, including mouse scroll 6 pub const Direction = enum { up, down, none }; 7 8 pub fn vertDirection(key: Key) Direction { 9 return switch (key) { 10 .arrow_up => .up, 11 .arrow_down => .down, 12 .mouse => |mouse| if (mouse.action == .scroll) 13 (if (mouse.action.scroll == .up) .up else .down) 14 else 15 .none, 16 else => .none, 17 }; 18 } 19 20 /// how many rows a navigation key press moves the selection (negative is up), 21 /// or null if the key doesn't move the selection. `count` is the row count, 22 /// so home/end jump past either end and get clamped by the caller. 23 pub fn rowDelta(key: Key, count: isize) ?isize { 24 switch (key) { 25 .arrow_up => return -1, 26 .arrow_down => return 1, 27 .page_up => return -10, 28 .page_down => return 10, 29 .home => return -count, 30 .end => return count, 31 .mouse => |mouse| switch (mouse.action) { 32 .scroll => |dir| return if (dir == .up) -1 else 1, 33 else => {}, 34 }, 35 else => {}, 36 } 37 return null; 38 } 39