From 542da2229cad047f1ad7df66a1751cb8bfa5ba57 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sun, 31 Aug 2025 02:41:37 +0100 Subject: [PATCH] a little additional scaffolding for normal mode --- fcore/app-type.sml | 4 +++- fcore/app-update.sml | 5 +++-- fcore/normal-mode/normal-mode.sml | 12 +++++++++++ fcore/normal-mode/normal-search-mode.sml | 27 ++++++++++++++++++++++-- ffi/glfw-input.c | 1 + ffi/glfw-input.sml | 3 +++ message-types/input-msg.sml | 1 + shell/shell.sml | 2 ++ 8 files changed, 50 insertions(+), 5 deletions(-) diff --git a/fcore/app-type.sml b/fcore/app-type.sml index 24fbd70..b6cc065 100644 --- a/fcore/app-type.sml +++ b/fcore/app-type.sml @@ -1,6 +1,8 @@ structure AppType = struct - datatype mode = NORMAL_MODE of string | NORMAL_SEARCH_MODE of string + datatype mode = + NORMAL_MODE of string + | NORMAL_SEARCH_MODE of {searchString: string, tempSearchList: int vector} type app_type = { mode: mode diff --git a/fcore/app-update.sml b/fcore/app-update.sml index b9a5c4f..bfedb0a 100644 --- a/fcore/app-update.sml +++ b/fcore/app-update.sml @@ -4,6 +4,7 @@ struct fun update (app: app_type, msg, time) = case #mode app of - NORMAL_MODE str => NormalMode.update (app, str, msg, time) - | NORMAL_SEARCH_MODE str => NormalSearchMode.update (app, str, msg, time) + NORMAL_MODE modeData => NormalMode.update (app, modeData, msg, time) + | NORMAL_SEARCH_MODE modeData => + NormalSearchMode.update (app, modeData, msg, time) end diff --git a/fcore/normal-mode/normal-mode.sml b/fcore/normal-mode/normal-mode.sml index b40e1ea..dfa714a 100644 --- a/fcore/normal-mode/normal-mode.sml +++ b/fcore/normal-mode/normal-mode.sml @@ -5,6 +5,16 @@ struct open AppType open InputMsg + (* todo: create draw msg showing search bar *) + fun switchToNormalSearchMode (app: app_type) = + let + val mode = + NORMAL_SEARCH_MODE + {searchString = "", tempSearchList = Vector.fromList []} + in + AppWith.mode (app, mode, []) + end + fun getNumLength (pos, str) = if pos = String.size str then pos @@ -82,6 +92,7 @@ struct else NormalMove.moveToLine (app, count - 1) | #"%" => NormalMove.moveToMatchingPair app | #"x" => NormalDelete.removeChr (app, count, time) + | #"/" => switchToNormalSearchMode app (* multi-char commands which can be appended *) | #"t" => appendChr (app, chr, str) | #"T" => appendChr (app, chr, str) @@ -258,4 +269,5 @@ struct | KEY_ESC => Finish.clearMode app | RESIZE_EVENT (width, height) => Finish.resizeText (app, width, height) | WITH_SEARCH_LIST searchList => Finish.withSearchList (app, searchList) + | KEY_ENTER => app end diff --git a/fcore/normal-mode/normal-search-mode.sml b/fcore/normal-mode/normal-search-mode.sml index ba8e116..215dadc 100644 --- a/fcore/normal-mode/normal-search-mode.sml +++ b/fcore/normal-mode/normal-search-mode.sml @@ -3,10 +3,33 @@ struct open AppType open InputMsg - fun update (app, searchString, msg, time) = + (* todo: redraw based on results of tempSearchList *) + fun parseChr (app: app_type, searchString, chr) = + let + val c = String.implode [chr] + val searchString = searchString ^ c + + val {buffer, cursorIdx, ...} = app + val buffer = LineGap.goToIdx (cursorIdx - 1111, buffer) + val tempSearchList = + SearchList.buildRange (buffer, searchString, cursorIdx + 1111) + + val mode = + NORMAL_SEARCH_MODE + {searchString = searchString, tempSearchList = tempSearchList} + in + AppWith.mode (app, mode, []) + end + + (* todo: switch to normal mode, save tempSearchList and searchString, + * and redraw *) + fun finishSearch (app: app_type, searchString, tempSearchList) = app + + fun update (app, {searchString, tempSearchList}, msg, time) = case msg of - CHAR_EVENT chrCmd => app + CHAR_EVENT chr => parseChr (app, searchString, chr) | KEY_ESC => Finish.clearMode app + | KEY_ENTER => finishSearch (app, searchString, tempSearchList) | RESIZE_EVENT (width, height) => app | WITH_SEARCH_LIST searchList => app end diff --git a/ffi/glfw-input.c b/ffi/glfw-input.c index 5d5f7dc..57a49dd 100644 --- a/ffi/glfw-input.c +++ b/ffi/glfw-input.c @@ -7,6 +7,7 @@ int PRESS = GLFW_PRESS; int REPEAT = GLFW_REPEAT; int RELEASE = GLFW_RELEASE; int KEY_ESC = GLFW_KEY_ESCAPE; +int KEY_ENTER = GLFW_KEY_ENTER; void framebufferSizeCallback(GLFWwindow* window, int width, int height) { glViewport(0, 0, width, height); diff --git a/ffi/glfw-input.sml b/ffi/glfw-input.sml index cf437dd..91ad2ec 100644 --- a/ffi/glfw-input.sml +++ b/ffi/glfw-input.sml @@ -33,4 +33,7 @@ struct val (KEY_ESC, _) = _symbol "KEY_ESC" public : ( unit -> int ) * ( int -> unit ); val KEY_ESC = KEY_ESC () + val (KEY_ENTER, _) = + _symbol "KEY_ENTER" public : ( unit -> int ) * ( int -> unit ); + val KEY_ENTER = KEY_ENTER () end diff --git a/message-types/input-msg.sml b/message-types/input-msg.sml index 1bfe038..661da51 100644 --- a/message-types/input-msg.sml +++ b/message-types/input-msg.sml @@ -3,6 +3,7 @@ struct datatype t = CHAR_EVENT of char | KEY_ESC + | KEY_ENTER | RESIZE_EVENT of int * int | WITH_SEARCH_LIST of int vector end diff --git a/shell/shell.sml b/shell/shell.sml index 0d6d1d1..fb90a9e 100644 --- a/shell/shell.sml +++ b/shell/shell.sml @@ -25,6 +25,8 @@ struct in if key = KEY_ESC andalso action = PRESS andalso mods = 0 then Mailbox.send (inputMailbox, InputMsg.KEY_ESC) + else if key = KEY_ENTER andalso action = PRESS andalso mods = 0 then + Mailbox.send (inputMailbox, InputMsg.KEY_ENTER) else () end