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-18 06:44:45 +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-18 06:44:45 +01:00
|
|
|
val {buffer, windowWidth, windowHeight, startLine, cursorIdx, ...} = app
|
2024-10-17 02:14:09 +01:00
|
|
|
|
|
|
|
|
(* move LineGap to cursorIdx, which is necessary for finding newCursorIdx *)
|
2024-10-17 02:57:26 +01:00
|
|
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
|
|
|
|
val cursorIdx = Cursor.viL (buffer, cursorIdx)
|
2024-10-17 02:14:09 +01:00
|
|
|
|
|
|
|
|
(* move LineGap to first line displayed on screen, and build new text *)
|
2024-10-17 02:57:26 +01:00
|
|
|
val buffer = LineGap.goToLine (startLine, buffer)
|
2024-10-17 02:14:09 +01:00
|
|
|
val drawMsg = TextBuilder.build
|
2024-10-17 02:57:26 +01:00
|
|
|
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
|
2024-10-17 02:14:09 +01:00
|
|
|
|
2024-10-20 21:30:06 +01:00
|
|
|
val newApp = AppWith.bufferAndCursorIdx (app, buffer, cursorIdx)
|
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-18 00:40:43 +01:00
|
|
|
fun moveLeft (app: app_type) =
|
|
|
|
|
let
|
2024-10-18 06:44:45 +01:00
|
|
|
val {buffer, windowWidth, windowHeight, startLine, cursorIdx, ...} = app
|
2024-10-18 00:40:43 +01:00
|
|
|
|
|
|
|
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
|
|
|
|
val cursorIdx = Cursor.viH (buffer, cursorIdx)
|
|
|
|
|
|
|
|
|
|
val buffer = LineGap.goToLine (startLine, buffer)
|
|
|
|
|
val drawMsg = TextBuilder.build
|
|
|
|
|
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
|
|
|
|
|
|
2024-10-20 21:30:06 +01:00
|
|
|
val newApp = AppWith.bufferAndCursorIdx (app, buffer, cursorIdx)
|
|
|
|
|
in
|
|
|
|
|
(newApp, drawMsg)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun moveDown (app: app_type) =
|
|
|
|
|
let
|
|
|
|
|
val {buffer, windowWidth, windowHeight, startLine, cursorIdx, ...} = app
|
|
|
|
|
|
|
|
|
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
|
|
|
|
val cursorIdx = Cursor.viJ (buffer, cursorIdx)
|
|
|
|
|
|
|
|
|
|
val buffer = LineGap.goToLine (startLine, buffer)
|
|
|
|
|
val drawMsg = TextBuilder.build
|
|
|
|
|
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
|
|
|
|
|
|
|
|
|
|
val newApp = AppWith.bufferAndCursorIdx (app, buffer, cursorIdx)
|
2024-10-18 00:40:43 +01:00
|
|
|
in
|
|
|
|
|
(newApp, drawMsg)
|
|
|
|
|
end
|
|
|
|
|
|
2024-10-21 01:34:54 +01:00
|
|
|
fun moveUp (app: app_type) =
|
|
|
|
|
let
|
|
|
|
|
val {buffer, windowWidth, windowHeight, startLine, cursorIdx, ...} = app
|
|
|
|
|
|
|
|
|
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
|
|
|
|
val cursorIdx = Cursor.viK (buffer, cursorIdx)
|
|
|
|
|
|
|
|
|
|
val buffer = LineGap.goToLine (startLine, buffer)
|
|
|
|
|
val drawMsg = TextBuilder.build
|
|
|
|
|
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
|
|
|
|
|
|
|
|
|
|
val newApp = AppWith.bufferAndCursorIdx (app, buffer, cursorIdx)
|
|
|
|
|
in
|
|
|
|
|
(newApp, drawMsg)
|
|
|
|
|
end
|
|
|
|
|
|
2024-10-21 03:04:47 +01:00
|
|
|
fun moveToLineStart (app: app_type) =
|
|
|
|
|
let
|
|
|
|
|
val {buffer, windowWidth, windowHeight, startLine, cursorIdx, ...} = app
|
|
|
|
|
|
|
|
|
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
|
|
|
|
val cursorIdx = Cursor.vi0 (buffer, cursorIdx)
|
|
|
|
|
|
|
|
|
|
val buffer = LineGap.goToLine (startLine, buffer)
|
|
|
|
|
val drawMsg = TextBuilder.build
|
|
|
|
|
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
|
|
|
|
|
|
|
|
|
|
val newApp = AppWith.bufferAndCursorIdx (app, buffer, cursorIdx)
|
|
|
|
|
in
|
|
|
|
|
(newApp, drawMsg)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun moveToLineEnd (app: app_type) =
|
|
|
|
|
let
|
|
|
|
|
val {buffer, windowWidth, windowHeight, startLine, cursorIdx, ...} = app
|
|
|
|
|
|
|
|
|
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
|
|
|
|
val cursorIdx = Cursor.viDlr (buffer, cursorIdx)
|
|
|
|
|
|
|
|
|
|
val buffer = LineGap.goToLine (startLine, buffer)
|
|
|
|
|
val drawMsg = TextBuilder.build
|
|
|
|
|
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
|
|
|
|
|
|
|
|
|
|
val newApp = AppWith.bufferAndCursorIdx (app, buffer, cursorIdx)
|
|
|
|
|
in
|
|
|
|
|
(newApp, drawMsg)
|
|
|
|
|
end
|
|
|
|
|
|
2024-10-17 02:14:09 +01:00
|
|
|
fun handleChr (app: app_type, chr) =
|
|
|
|
|
case chr of
|
2024-10-18 00:40:43 +01:00
|
|
|
#"h" => moveLeft app
|
2024-10-20 21:30:06 +01:00
|
|
|
| #"j" => moveDown app
|
2024-10-21 01:34:54 +01:00
|
|
|
| #"k" => moveUp app
|
2024-10-18 00:40:43 +01:00
|
|
|
| #"l" => moveRight app
|
2024-10-21 03:04:47 +01:00
|
|
|
| #"0" => moveToLineStart app
|
|
|
|
|
| #"$" => moveToLineEnd app
|
2024-10-17 02:14:09 +01:00
|
|
|
| _ => (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
|