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 = signature APP_TYPE =
struct sig
datatype mode =
NORMAL_MODE of string
type app_type = 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 , windowWidth: int
, windowHeight: int , windowHeight: int
(* line to start drawing from *) (* line to start drawing from *)
@@ -11,7 +34,8 @@ struct
} }
fun init (buffer, windowWidth, windowHeight) : app_type = fun init (buffer, windowWidth, windowHeight) : app_type =
{ buffer = buffer { mode = NORMAL_MODE ""
, buffer = buffer
, windowWidth = windowWidth , windowWidth = windowWidth
, windowHeight = windowHeight , windowHeight = windowHeight
, startLine = 0 , startLine = 0

View File

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

BIN
shf

Binary file not shown.