2024-09-30 13:43:43 +01:00
|
|
|
structure Shell =
|
|
|
|
|
struct
|
2024-10-06 10:23:07 +01:00
|
|
|
open InputMsg
|
|
|
|
|
|
2024-12-17 10:55:58 +00:00
|
|
|
fun frameBufferSizeCallback (width, height) =
|
2025-09-10 01:41:59 +01:00
|
|
|
InputMailbox.append (RESIZE_EVENT (width, height))
|
2024-10-06 10:23:07 +01:00
|
|
|
|
2024-12-17 10:55:58 +00:00
|
|
|
fun charCallback word =
|
2024-10-17 01:20:48 +01:00
|
|
|
let
|
|
|
|
|
val word = Word32.toInt word
|
|
|
|
|
val chr = Char.chr word
|
|
|
|
|
in
|
2025-09-10 01:41:59 +01:00
|
|
|
InputMailbox.append (CHAR_EVENT chr)
|
2024-10-17 01:20:48 +01:00
|
|
|
end
|
|
|
|
|
|
2024-12-17 10:55:58 +00:00
|
|
|
fun keyCallback (key, scancode, action, mods) =
|
2024-11-08 09:46:01 +00:00
|
|
|
let
|
|
|
|
|
open Input
|
|
|
|
|
in
|
|
|
|
|
if key = KEY_ESC andalso action = PRESS andalso mods = 0 then
|
2025-09-10 01:41:59 +01:00
|
|
|
InputMailbox.append (InputMsg.KEY_ESC)
|
2025-08-31 02:41:37 +01:00
|
|
|
else if key = KEY_ENTER andalso action = PRESS andalso mods = 0 then
|
2025-09-10 01:41:59 +01:00
|
|
|
InputMailbox.append (InputMsg.KEY_ENTER)
|
2025-09-01 02:52:05 +01:00
|
|
|
else if key = KEY_BACKSPACE andalso action <> RELEASE andalso mods = 0 then
|
2025-09-10 01:41:59 +01:00
|
|
|
InputMailbox.append (InputMsg.KEY_BACKSPACE)
|
2025-09-01 11:23:45 +01:00
|
|
|
else if key = KEY_ARROW_LEFT andalso action <> RELEASE andalso mods = 0 then
|
2025-09-10 01:41:59 +01:00
|
|
|
InputMailbox.append (InputMsg.ARROW_LEFT)
|
2025-09-01 11:23:45 +01:00
|
|
|
else if key = KEY_ARROW_RIGHT andalso action <> RELEASE andalso mods = 0 then
|
2025-09-10 01:41:59 +01:00
|
|
|
InputMailbox.append (InputMsg.ARROW_RIGHT)
|
2025-09-01 11:23:45 +01:00
|
|
|
else if key = KEY_ARROW_UP andalso action <> RELEASE andalso mods = 0 then
|
2025-09-10 01:41:59 +01:00
|
|
|
InputMailbox.append (InputMsg.ARROW_UP)
|
2025-09-01 11:23:45 +01:00
|
|
|
else if key = KEY_ARROW_DOWN andalso action <> RELEASE andalso mods = 0 then
|
2025-09-10 01:41:59 +01:00
|
|
|
InputMailbox.append (InputMsg.ARROW_DOWN)
|
2024-11-08 09:46:01 +00:00
|
|
|
else
|
|
|
|
|
()
|
|
|
|
|
end
|
|
|
|
|
|
2024-12-17 10:55:58 +00:00
|
|
|
fun registerCallbacks window =
|
2024-10-06 10:23:07 +01:00
|
|
|
let
|
2024-12-17 10:55:58 +00:00
|
|
|
val () = Input.exportFramebufferSizeCallback frameBufferSizeCallback
|
2024-10-06 10:23:07 +01:00
|
|
|
val () = Input.setFramebufferSizeCallback window
|
2024-10-17 01:20:48 +01:00
|
|
|
|
|
|
|
|
val () = Input.exportCharCallback charCallback
|
|
|
|
|
val () = Input.setCharCallback window
|
2024-11-08 09:46:01 +00:00
|
|
|
|
|
|
|
|
val () = Input.exportKeyCallback keyCallback
|
|
|
|
|
val () = Input.setKeyCallback window
|
2024-10-06 10:23:07 +01:00
|
|
|
in
|
|
|
|
|
()
|
|
|
|
|
end
|
2024-09-30 13:43:43 +01:00
|
|
|
|
2025-09-16 04:35:49 +01:00
|
|
|
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
|
2024-10-05 02:03:17 +01:00
|
|
|
|
2024-09-30 13:43:43 +01:00
|
|
|
fun main () =
|
|
|
|
|
let
|
|
|
|
|
(* Set up GLFW. *)
|
|
|
|
|
val _ = Glfw.init ()
|
|
|
|
|
val _ = Glfw.windowHint (Glfw.CONTEXT_VERSION_MAJOR (), 3)
|
|
|
|
|
val _ = Glfw.windowHint (Glfw.DEPRECATED (), Glfw.FALSE ())
|
2024-10-05 02:03:17 +01:00
|
|
|
val window = Glfw.createWindow (1920, 1080, "shf")
|
2024-09-30 13:43:43 +01:00
|
|
|
val _ = Glfw.makeContextCurrent window
|
|
|
|
|
val _ = Gles3.loadGlad ()
|
2024-10-04 23:23:25 +01:00
|
|
|
|
2024-10-06 10:23:07 +01:00
|
|
|
(* load file intol gap buffer and create initial app *)
|
2024-10-17 02:57:26 +01:00
|
|
|
val io = TextIO.openIn "temp.txt"
|
2024-10-05 12:56:23 +01:00
|
|
|
val lineGap = ioToLineGap (io, LineGap.empty)
|
2024-10-05 02:03:17 +01:00
|
|
|
val _ = TextIO.closeIn io
|
2025-08-20 12:17:07 +01:00
|
|
|
val app = AppType.init (lineGap, 1920, 1080, Time.now ())
|
2024-10-06 10:23:07 +01:00
|
|
|
|
2024-12-17 10:55:58 +00:00
|
|
|
val () = registerCallbacks window
|
2024-10-05 02:03:17 +01:00
|
|
|
|
2025-09-10 01:41:59 +01:00
|
|
|
val _ = CML.spawn (fn () => GlDraw.loop (app, window))
|
|
|
|
|
val _ = CML.spawn SearchThread.loop
|
2024-09-30 13:43:43 +01:00
|
|
|
in
|
2024-10-04 23:23:25 +01:00
|
|
|
()
|
2024-09-30 13:43:43 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2025-09-10 01:52:16 +01:00
|
|
|
val _ = RunCML.doit (Shell.main, SOME (Time.fromMicroseconds 555))
|