Files
sml-projects/shell/shell.sml

93 lines
2.7 KiB
Standard ML
Raw Normal View History

2024-09-30 13:43:43 +01:00
structure Shell =
struct
open CML
open InputMsg
(* create mailboxes for CML communication *)
val inputMailbox = Mailbox.mailbox ()
val drawMailbox = Mailbox.mailbox ()
val searchMailbox = Mailbox.mailbox ()
fun frameBufferSizeCallback (width, height) =
Mailbox.send (inputMailbox, RESIZE_EVENT (width, height))
fun charCallback word =
2024-10-17 01:20:48 +01:00
let
val word = Word32.toInt word
val chr = Char.chr word
in
Mailbox.send (inputMailbox, CHAR_EVENT chr)
2024-10-17 01:20:48 +01:00
end
fun keyCallback (key, scancode, action, mods) =
let
open Input
in
if key = KEY_ESC andalso action = PRESS andalso mods = 0 then
Mailbox.send (inputMailbox, InputMsg.KEY_ESC)
else
()
end
fun registerCallbacks window =
let
val () = Input.exportFramebufferSizeCallback frameBufferSizeCallback
val () = Input.setFramebufferSizeCallback window
2024-10-17 01:20:48 +01:00
val () = Input.exportCharCallback charCallback
val () = Input.setCharCallback window
val () = Input.exportKeyCallback keyCallback
val () = Input.setKeyCallback window
in
()
end
2024-09-30 13:43:43 +01:00
2024-10-05 12:56:23 +01:00
fun ioToLineGap (io, acc) =
2024-10-05 02:03:17 +01:00
case TextIO.inputLine io of
2024-10-05 12:56:23 +01:00
SOME str => ioToLineGap (io, LineGap.append (str, acc))
| NONE => LineGap.goToStart acc
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 ())
val _ = Glfw.windowHint (Glfw.SAMPLES (), 4)
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
(* load file intol gap buffer and create initial app *)
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
val app = AppType.init (lineGap, 1920, 1080, Time.now ())
(* todo: remove temp line below which tests search list *)
2025-08-06 00:16:50 +01:00
val app =
let
val buffer = #buffer app
val buffer = LineGap.goToEnd buffer
2025-08-06 00:16:50 +01:00
val searchString = "val "
val searchList = SearchList.build (buffer, searchString)
2025-08-06 00:16:50 +01:00
val buffer = LineGap.goToStart buffer
in
AppWith.searchList (app, searchList, buffer, searchString)
end
val () = registerCallbacks window
2024-10-05 02:03:17 +01:00
val _ = CML.spawn (fn () => GlDraw.loop (drawMailbox, window))
val _ = CML.spawn (fn () =>
UpdateThread.loop (app, inputMailbox, drawMailbox, searchMailbox))
val _ = CML.spawn (fn () =>
SearchThread.loop (searchMailbox, inputMailbox))
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
val _ = RunCML.doit (Shell.main, NONE)