Add 'dotscape/' from commit 'f306501a68a51b634e895c5fdac70788ae899d75'
git-subtree-dir: dotscape git-subtree-mainline:6b91d64fc3git-subtree-split:f306501a68
This commit is contained in:
54
dotscape/imperative-shell/file-thread.sml
Normal file
54
dotscape/imperative-shell/file-thread.sml
Normal file
@@ -0,0 +1,54 @@
|
||||
signature FILE_THREAD =
|
||||
sig
|
||||
val run: FileMessage.t Mailbox.mbox * InputMessage.t Mailbox.mbox -> unit
|
||||
end
|
||||
|
||||
structure FileThread :> FILE_THREAD =
|
||||
struct
|
||||
open FileMessage
|
||||
open InputMessage
|
||||
|
||||
fun loadIO (io, str) =
|
||||
case TextIO.inputLine io of
|
||||
SOME line => loadIO (io, str ^ line)
|
||||
| NONE => str
|
||||
|
||||
fun loadSquares (path, inputMailbox) =
|
||||
let
|
||||
val io = TextIO.openIn path
|
||||
val str = loadIO (io, "")
|
||||
val () = TextIO.closeIn io
|
||||
in
|
||||
case Parser.parse str of
|
||||
SOME (canvasWidth, canvasHeight, tree) =>
|
||||
Mailbox.send
|
||||
( inputMailbox
|
||||
, USE_LAYERS
|
||||
{ tree = tree
|
||||
, canvasWidth = canvasWidth
|
||||
, canvasHeight = canvasHeight
|
||||
}
|
||||
)
|
||||
| NONE => ()
|
||||
end
|
||||
|
||||
fun saveString (filename, toSaveString) =
|
||||
let
|
||||
val io = TextIO.openOut filename
|
||||
val () = TextIO.output (io, toSaveString)
|
||||
in
|
||||
TextIO.closeOut io
|
||||
end
|
||||
|
||||
fun run (fileMailbox, inputMailbox) =
|
||||
let
|
||||
val _ =
|
||||
case Mailbox.recv fileMailbox of
|
||||
SAVE_SQUARES {filepath, output} => saveString (filepath, output)
|
||||
| EXPORT_SQUARES {filepath, output} => saveString (filepath, output)
|
||||
| EXPORT_COLLISIONS {filepath, output} => saveString (filepath, output)
|
||||
| LOAD_SQUARES {filepath} => loadSquares (filepath, inputMailbox)
|
||||
in
|
||||
run (fileMailbox, inputMailbox)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user