2024-10-06 09:32:56 +01:00
|
|
|
structure AppUpdate =
|
|
|
|
|
struct
|
|
|
|
|
open AppType
|
|
|
|
|
|
|
|
|
|
open MailboxType
|
|
|
|
|
open DrawMsg
|
|
|
|
|
open InputMsg
|
|
|
|
|
|
|
|
|
|
fun resizeText (app: app_type, newWidth, newHeight) =
|
|
|
|
|
let
|
2024-10-09 10:59:32 +01:00
|
|
|
val {buffer, windowWidth, windowHeight, startLine, cursorIdx} = app
|
2024-10-06 09:32:56 +01:00
|
|
|
|
2024-10-08 08:53:43 +01:00
|
|
|
val newBuffer = LineGap.goToLine (startLine, buffer)
|
2024-10-09 11:36:05 +01:00
|
|
|
val drawMsg = TextBuilder.build
|
2024-10-09 12:43:42 +01:00
|
|
|
(startLine, cursorIdx, newBuffer, newWidth, newHeight)
|
2024-10-08 08:53:43 +01:00
|
|
|
|
|
|
|
|
val newApp = AppWith.bufferAndSize (app, newBuffer, newWidth, newHeight)
|
2024-10-06 09:32:56 +01:00
|
|
|
in
|
2024-10-09 11:36:05 +01:00
|
|
|
(newApp, drawMsg)
|
2024-10-06 09:32:56 +01:00
|
|
|
end
|
|
|
|
|
|
2024-10-17 02:14:09 +01:00
|
|
|
fun moveRight (app: app_type) =
|
2024-10-17 01:38:31 +01:00
|
|
|
let
|
2024-10-17 02:14:09 +01:00
|
|
|
(* todo: proper implementation of moveRight
|
|
|
|
|
* currently, we also retrieve the newCursorIdx improperly.
|
|
|
|
|
* To do it properly, we have to look inside LineGap
|
|
|
|
|
* instead of just incrementing cursorIdx by 1.
|
|
|
|
|
* So:
|
|
|
|
|
* - Find newCursorIdx from LineGap
|
|
|
|
|
* *)
|
|
|
|
|
|
|
|
|
|
val {buffer, windowWidth, windowHeight, startLine, cursorIdx} = app
|
|
|
|
|
|
|
|
|
|
(* move LineGap to cursorIdx, which is necessary for finding newCursorIdx *)
|
|
|
|
|
val newBuffer = LineGap.goToIdx (cursorIdx, buffer)
|
|
|
|
|
(* todo: call to retrieve newCursorIdx should be below *)
|
|
|
|
|
val newCursorIdx = cursorIdx + 1
|
|
|
|
|
|
|
|
|
|
(* move LineGap to first line displayed on screen, and build new text *)
|
|
|
|
|
val newBuffer = LineGap.goToLine (startLine, newBuffer)
|
|
|
|
|
val drawMsg = TextBuilder.build
|
|
|
|
|
(startLine, cursorIdx, newBuffer, windowWidth, windowHeight)
|
|
|
|
|
|
|
|
|
|
val newApp = AppWith.bufferAndCursorIdx (app, newBuffer, newCursorIdx)
|
2024-10-17 01:38:31 +01:00
|
|
|
in
|
2024-10-17 02:14:09 +01:00
|
|
|
(newApp, drawMsg)
|
2024-10-17 01:38:31 +01:00
|
|
|
end
|
|
|
|
|
|
2024-10-17 02:14:09 +01:00
|
|
|
fun handleChr (app: app_type, chr) =
|
|
|
|
|
case chr of
|
|
|
|
|
#"l" => moveRight app
|
|
|
|
|
| _ => (app, [])
|
|
|
|
|
|
2024-10-06 09:32:56 +01:00
|
|
|
fun update (app, msg) =
|
2024-10-17 01:38:31 +01:00
|
|
|
case msg of
|
|
|
|
|
RESIZE_EVENT (width, height) => resizeText (app, width, height)
|
|
|
|
|
| CHAR_EVENT chr => handleChr (app, chr)
|
2024-10-06 09:32:56 +01:00
|
|
|
end
|