From 55351487a9112ae4b6afda41d15297e1151ab023 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 19 Apr 2022 20:26:06 -0700 Subject: [PATCH] accept enter to make a newline --- src/Window.zig | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Window.zig b/src/Window.zig index bed111279..7d2c9b274 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -106,6 +106,7 @@ pub fn create(alloc: Allocator) !*Window { window.setUserPointer(self); window.setSizeCallback(sizeCallback); window.setCharCallback(charCallback); + window.setKeyCallback(keyCallback); return self; } @@ -174,3 +175,21 @@ fn charCallback(window: glfw.Window, codepoint: u21) void { // Update the cells for drawing win.grid.updateCells(win.terminal) catch unreachable; } + +fn keyCallback( + window: glfw.Window, + key: glfw.Key, + scancode: i32, + action: glfw.Action, + mods: glfw.Mods, +) void { + _ = scancode; + _ = mods; + + //log.info("KEY {} {}", .{ key, action }); + if (key == .enter and (action == .press or action == .repeat)) { + const win = window.getUserPointer(Window) orelse return; + win.terminal.append(win.alloc, "\r\n> ") catch unreachable; + win.grid.updateCells(win.terminal) catch unreachable; + } +}