From 5eb94f5ccbd091b2707c0959de6562ef9315d970 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Thu, 22 Jan 2026 00:57:21 +0000 Subject: [PATCH] remove shell/shell.sml and merge its contents into shell/glfw-loop.sml, because shell.sml used to set up and initialise GLFW before calling the main loop. We may want to add additional back-ends later instead, so it's better to keep names specific to the windowing library or platform. --- shell/glfw-loop.sml | 94 ++++++++++++++++++++++++++++++++++++++++++++ shell/shell.sml | 96 --------------------------------------------- shf.mlb | 1 - 3 files changed, 94 insertions(+), 97 deletions(-) delete mode 100644 shell/shell.sml diff --git a/shell/glfw-loop.sml b/shell/glfw-loop.sml index cf0f70f..504ed9f 100644 --- a/shell/glfw-loop.sml +++ b/shell/glfw-loop.sml @@ -90,4 +90,98 @@ struct in helpLoop (app, drawState, window, gamepad) end + + open InputMsg + + fun frameBufferSizeCallback (width, height) = + InputMailbox.append (RESIZE_EVENT (width, height)) + + fun charCallback word = + let + val word = Word32.toInt word + val chr = Char.chr word + in + InputMailbox.append (CHAR_EVENT chr) + end + + fun keyCallback (key, scancode, action, mods) = + let + open Input + in + if key = KEY_ESC andalso action = PRESS andalso mods = 0 then + InputMailbox.append (InputMsg.KEY_ESC) + else if key = KEY_ENTER andalso action = PRESS andalso mods = 0 then + InputMailbox.append (InputMsg.KEY_ENTER) + else if key = KEY_BACKSPACE andalso action <> RELEASE andalso mods = 0 then + InputMailbox.append (InputMsg.KEY_BACKSPACE) + else if key = KEY_ARROW_LEFT andalso action <> RELEASE andalso mods = 0 then + InputMailbox.append (InputMsg.ARROW_LEFT) + else if key = KEY_ARROW_RIGHT andalso action <> RELEASE andalso mods = 0 then + InputMailbox.append (InputMsg.ARROW_RIGHT) + else if key = KEY_ARROW_UP andalso action <> RELEASE andalso mods = 0 then + InputMailbox.append (InputMsg.ARROW_UP) + else if key = KEY_ARROW_DOWN andalso action <> RELEASE andalso mods = 0 then + InputMailbox.append (InputMsg.ARROW_DOWN) + else + () + end + + fun registerCallbacks window = + let + val () = Input.exportFramebufferSizeCallback frameBufferSizeCallback + val () = Input.setFramebufferSizeCallback window + + val () = Input.exportCharCallback charCallback + val () = Input.setCharCallback window + + val () = Input.exportKeyCallback keyCallback + val () = Input.setKeyCallback window + in + () + end + + local + fun loop (io, acc, lastCharWasNewline) = + case TextIO.inputLine io of + SOME str => + let + val endsWithNewline = + String.size str > 0 + andalso String.sub (str, String.size str - 1) = #"\n" + in + loop (io, LineGap.append (str, acc), endsWithNewline) + end + | NONE => + if lastCharWasNewline then + LineGap.goToStart acc + else + let val acc = LineGap.append ("\n", acc) + in LineGap.goToStart acc + end + in + fun ioToLineGap (io, acc) = loop (io, acc, false) + end + + fun main () = + let + (* Set up GLFW. *) + val _ = Glfw.init () + val _ = Glfw.windowHint (Glfw.CONTEXT_VERSION_MAJOR (), 3) + val _ = Glfw.windowHint (Glfw.DEPRECATED (), Glfw.FALSE ()) + val window = Glfw.createWindow (1920, 1080, "shf") + val _ = Glfw.makeContextCurrent window + val _ = Gles3.loadGlad () + + (* load file intol gap buffer and create initial app *) + val io = TextIO.openIn "temp.txt" + val lineGap = ioToLineGap (io, LineGap.empty) + val _ = TextIO.closeIn io + val app = AppType.init (lineGap, 1920, 1080, Time.now ()) + + val () = registerCallbacks window + in + loop (app, window) + end end + +val _ = GlfwLoop.main () diff --git a/shell/shell.sml b/shell/shell.sml deleted file mode 100644 index 06bfafe..0000000 --- a/shell/shell.sml +++ /dev/null @@ -1,96 +0,0 @@ -structure Shell = -struct - open InputMsg - - fun frameBufferSizeCallback (width, height) = - InputMailbox.append (RESIZE_EVENT (width, height)) - - fun charCallback word = - let - val word = Word32.toInt word - val chr = Char.chr word - in - InputMailbox.append (CHAR_EVENT chr) - end - - fun keyCallback (key, scancode, action, mods) = - let - open Input - in - if key = KEY_ESC andalso action = PRESS andalso mods = 0 then - InputMailbox.append (InputMsg.KEY_ESC) - else if key = KEY_ENTER andalso action = PRESS andalso mods = 0 then - InputMailbox.append (InputMsg.KEY_ENTER) - else if key = KEY_BACKSPACE andalso action <> RELEASE andalso mods = 0 then - InputMailbox.append (InputMsg.KEY_BACKSPACE) - else if key = KEY_ARROW_LEFT andalso action <> RELEASE andalso mods = 0 then - InputMailbox.append (InputMsg.ARROW_LEFT) - else if key = KEY_ARROW_RIGHT andalso action <> RELEASE andalso mods = 0 then - InputMailbox.append (InputMsg.ARROW_RIGHT) - else if key = KEY_ARROW_UP andalso action <> RELEASE andalso mods = 0 then - InputMailbox.append (InputMsg.ARROW_UP) - else if key = KEY_ARROW_DOWN andalso action <> RELEASE andalso mods = 0 then - InputMailbox.append (InputMsg.ARROW_DOWN) - else - () - end - - fun registerCallbacks window = - let - val () = Input.exportFramebufferSizeCallback frameBufferSizeCallback - val () = Input.setFramebufferSizeCallback window - - val () = Input.exportCharCallback charCallback - val () = Input.setCharCallback window - - val () = Input.exportKeyCallback keyCallback - val () = Input.setKeyCallback window - in - () - end - - local - fun loop (io, acc, lastCharWasNewline) = - case TextIO.inputLine io of - SOME str => - let - val endsWithNewline = - String.size str > 0 - andalso String.sub (str, String.size str - 1) = #"\n" - in - loop (io, LineGap.append (str, acc), endsWithNewline) - end - | NONE => - if lastCharWasNewline then - LineGap.goToStart acc - else - let val acc = LineGap.append ("\n", acc) - in LineGap.goToStart acc - end - in - fun ioToLineGap (io, acc) = loop (io, acc, false) - end - - fun main () = - let - (* Set up GLFW. *) - val _ = Glfw.init () - val _ = Glfw.windowHint (Glfw.CONTEXT_VERSION_MAJOR (), 3) - val _ = Glfw.windowHint (Glfw.DEPRECATED (), Glfw.FALSE ()) - val window = Glfw.createWindow (1920, 1080, "shf") - val _ = Glfw.makeContextCurrent window - val _ = Gles3.loadGlad () - - (* load file intol gap buffer and create initial app *) - val io = TextIO.openIn "temp.txt" - val lineGap = ioToLineGap (io, LineGap.empty) - val _ = TextIO.closeIn io - val app = AppType.init (lineGap, 1920, 1080, Time.now ()) - - val () = registerCallbacks window - in - GlfwLoop.loop (app, window) - end -end - -val () = Shell.main () diff --git a/shf.mlb b/shf.mlb index ac17b87..047ba05 100644 --- a/shf.mlb +++ b/shf.mlb @@ -86,4 +86,3 @@ shell/glfw-gamepad.sml shell/gl-shaders.sml shell/gl-draw.sml shell/glfw-loop.sml -shell/shell.sml