add mode type to app type (equivalent of vi's normal mode, visual mode, insert mode, etc.)

This commit is contained in:
2024-10-26 04:46:05 +01:00
parent 17a69720fd
commit defb17af20
3 changed files with 42 additions and 9 deletions

View File

@@ -1,7 +1,30 @@
structure AppType =
struct
signature APP_TYPE =
sig
datatype mode =
NORMAL_MODE of string
type app_type =
{ buffer: LineGap.t
{ mode: mode
, buffer: LineGap.t
, windowWidth: int
, windowHeight: int
(* line to start drawing from *)
, startLine: int
(* absolute index of movable cursor *)
, cursorIdx: int
}
val init: LineGap.t * int * int -> app_type
end
structure AppType :> APP_TYPE =
struct
datatype mode =
NORMAL_MODE of string
type app_type =
{ mode: mode
, buffer: LineGap.t
, windowWidth: int
, windowHeight: int
(* line to start drawing from *)
@@ -11,7 +34,8 @@ struct
}
fun init (buffer, windowWidth, windowHeight) : app_type =
{ buffer = buffer
{ mode = NORMAL_MODE ""
, buffer = buffer
, windowWidth = windowWidth
, windowHeight = windowHeight
, startLine = 0

View File

@@ -4,10 +4,17 @@ struct
fun bufferAndSize (app: app_type, newBuffer, newWidth, newHeight) =
let
val {buffer = _, windowWidth = _, windowHeight = _, startLine, cursorIdx} =
app
val
{ mode
, buffer = _
, windowWidth = _
, windowHeight = _
, startLine
, cursorIdx
} = app
in
{ buffer = newBuffer
{ mode = mode
, buffer = newBuffer
, windowWidth = newWidth
, windowHeight = newHeight
, startLine = startLine
@@ -17,10 +24,12 @@ struct
fun bufferAndCursorIdx (app: app_type, newBuffer, newCursorIdx) =
let
val {buffer = _, cursorIdx = _, windowWidth, windowHeight, startLine} =
val
{mode, buffer = _, cursorIdx = _, windowWidth, windowHeight, startLine} =
app
in
{ buffer = newBuffer
{ mode = mode
, buffer = newBuffer
, cursorIdx = newCursorIdx
, windowWidth = windowWidth
, windowHeight = windowHeight

BIN
shf

Binary file not shown.