move msgs into AppType.app_type, and refactor AppUpdate.update function to have type (app_type -> app_type) instead of pervious case which was (app_type -> app_type * MailboxType.t list). Reason: no need to allocate/return tuple when can store messages in type directly; previous msg list will be reset after each app update. All tests after refactor are passing.
This commit is contained in:
@@ -13,6 +13,10 @@ sig
|
||||
, startLine: int
|
||||
(* absolute index of movable cursor *)
|
||||
, cursorIdx: int
|
||||
(* msgs to send after an update.
|
||||
* The list of messages is reset on each invocation of AppUpdate.update. *)
|
||||
, msgs: MailboxType.t list
|
||||
|
||||
}
|
||||
|
||||
val init: LineGap.t * int * int -> app_type
|
||||
@@ -33,6 +37,9 @@ struct
|
||||
, startLine: int
|
||||
(* absolute index of movable cursor *)
|
||||
, cursorIdx: int
|
||||
(* msgs to send after an update.
|
||||
* The list of messages is reset on each invocation of AppUpdate.update. *)
|
||||
, msgs: MailboxType.t list
|
||||
}
|
||||
|
||||
fun init (buffer, windowWidth, windowHeight) : app_type =
|
||||
@@ -44,5 +51,6 @@ struct
|
||||
, windowHeight = windowHeight
|
||||
, startLine = 0
|
||||
, cursorIdx = 0
|
||||
, msgs = []
|
||||
}
|
||||
end
|
||||
|
||||
@@ -7,12 +7,7 @@ struct
|
||||
open InputMsg
|
||||
|
||||
fun clearMode app =
|
||||
let
|
||||
val mode = NORMAL_MODE ""
|
||||
val newApp = AppWith.mode (app, mode)
|
||||
in
|
||||
(newApp, [])
|
||||
end
|
||||
AppWith.mode (app, NORMAL_MODE "", [])
|
||||
|
||||
fun resizeText (app: app_type, newWidth, newHeight) =
|
||||
let
|
||||
@@ -40,11 +35,9 @@ struct
|
||||
, searchList
|
||||
, searchString
|
||||
)
|
||||
|
||||
val newApp =
|
||||
AppWith.bufferAndSize (app, newBuffer, newWidth, newHeight, searchList)
|
||||
in
|
||||
(newApp, drawMsg)
|
||||
AppWith.bufferAndSize
|
||||
(app, newBuffer, newWidth, newHeight, searchList, drawMsg)
|
||||
end
|
||||
|
||||
fun buildTextAndClear (app: app_type, buffer, cursorIdx, searchList) =
|
||||
@@ -75,10 +68,9 @@ struct
|
||||
)
|
||||
|
||||
val mode = NORMAL_MODE ""
|
||||
val newApp = AppWith.bufferAndCursorIdx
|
||||
(app, buffer, cursorIdx, mode, startLine, searchList)
|
||||
in
|
||||
(newApp, drawMsg)
|
||||
AppWith.bufferAndCursorIdx
|
||||
(app, buffer, cursorIdx, mode, startLine, searchList, drawMsg)
|
||||
end
|
||||
|
||||
(* Difference between this and buildTextAndClear is that
|
||||
@@ -114,10 +106,9 @@ struct
|
||||
)
|
||||
|
||||
val mode = NORMAL_MODE ""
|
||||
val newApp = AppWith.bufferAndCursorIdx
|
||||
(app, buffer, cursorIdx, mode, startLine, searchList)
|
||||
in
|
||||
(newApp, drawMsg)
|
||||
AppWith.bufferAndCursorIdx
|
||||
(app, buffer, cursorIdx, mode, startLine, searchList, drawMsg)
|
||||
end
|
||||
|
||||
fun centreToCursor (app: app_type) =
|
||||
@@ -141,9 +132,6 @@ struct
|
||||
val lineIdx = TextBuilder.getLineAbsIdx (startLine, buffer)
|
||||
val searchList = SearchList.goToNum (lineIdx, searchList)
|
||||
|
||||
val newApp = AppWith.bufferAndCursorIdx
|
||||
(app, buffer, cursorIdx, NORMAL_MODE "", startLine, searchList)
|
||||
|
||||
val drawMsg = TextBuilder.build
|
||||
( startLine
|
||||
, cursorIdx
|
||||
@@ -154,7 +142,8 @@ struct
|
||||
, searchString
|
||||
)
|
||||
in
|
||||
(newApp, drawMsg)
|
||||
AppWith.bufferAndCursorIdx
|
||||
(app, buffer, cursorIdx, NORMAL_MODE "", startLine, searchList, drawMsg)
|
||||
end
|
||||
|
||||
(* movement functions *)
|
||||
@@ -180,10 +169,9 @@ struct
|
||||
)
|
||||
|
||||
val mode = NORMAL_MODE ""
|
||||
val newApp = AppWith.bufferAndCursorIdx
|
||||
(app, buffer, cursorIdx, mode, startLine, searchList)
|
||||
in
|
||||
(newApp, drawMsg)
|
||||
AppWith.bufferAndCursorIdx
|
||||
(app, buffer, cursorIdx, mode, startLine, searchList, drawMsg)
|
||||
end
|
||||
|
||||
fun moveToEnd (app: app_type) =
|
||||
@@ -222,10 +210,9 @@ struct
|
||||
)
|
||||
|
||||
val mode = NORMAL_MODE ""
|
||||
val newApp = AppWith.bufferAndCursorIdx
|
||||
(app, buffer, bufferIdx, mode, bufferLine, searchList)
|
||||
in
|
||||
(newApp, drawMsg)
|
||||
AppWith.bufferAndCursorIdx
|
||||
(app, buffer, bufferIdx, mode, bufferLine, searchList, drawMsg)
|
||||
end
|
||||
|
||||
fun moveToLine (app: app_type, reqLine) =
|
||||
@@ -255,9 +242,6 @@ struct
|
||||
val lineIdx = TextBuilder.getLineAbsIdx (startLine, buffer)
|
||||
val searchList = SearchList.goToNum (lineIdx, searchList)
|
||||
|
||||
val newApp = AppWith.bufferAndCursorIdx
|
||||
(app, buffer, cursorIdx, NORMAL_MODE "", startLine, searchList)
|
||||
|
||||
val drawMsg = TextBuilder.build
|
||||
( startLine
|
||||
, cursorIdx
|
||||
@@ -267,8 +251,11 @@ struct
|
||||
, searchList
|
||||
, searchString
|
||||
)
|
||||
|
||||
val mode = NORMAL_MODE ""
|
||||
in
|
||||
(newApp, drawMsg)
|
||||
AppWith.bufferAndCursorIdx
|
||||
(app, buffer, cursorIdx, mode, startLine, searchList, drawMsg)
|
||||
end
|
||||
|
||||
fun helpMove (app: app_type, buffer, cursorIdx, count, fMove) =
|
||||
@@ -324,9 +311,6 @@ struct
|
||||
then
|
||||
(* if visible, just need to redraw; no need to get line *)
|
||||
let
|
||||
val newApp = AppWith.bufferAndCursorIdx
|
||||
(app, buffer, cursorIdx, NORMAL_MODE "", startLine, searchList)
|
||||
|
||||
val drawMsg = TextBuilder.build
|
||||
( startLine
|
||||
, cursorIdx
|
||||
@@ -337,7 +321,15 @@ struct
|
||||
, searchString
|
||||
)
|
||||
in
|
||||
(newApp, drawMsg)
|
||||
AppWith.bufferAndCursorIdx
|
||||
( app
|
||||
, buffer
|
||||
, cursorIdx
|
||||
, NORMAL_MODE ""
|
||||
, startLine
|
||||
, searchList
|
||||
, drawMsg
|
||||
)
|
||||
end
|
||||
else
|
||||
(* not visible, so need to get startLine where cursor is visible *)
|
||||
@@ -350,9 +342,6 @@ struct
|
||||
val lineIdx = TextBuilder.getLineAbsIdx (startLine, buffer)
|
||||
val searchList = SearchList.goToNum (lineIdx, searchList)
|
||||
|
||||
val newApp = AppWith.bufferAndCursorIdx
|
||||
(app, buffer, cursorIdx, NORMAL_MODE "", startLine, searchList)
|
||||
|
||||
val drawMsg = TextBuilder.build
|
||||
( startLine
|
||||
, cursorIdx
|
||||
@@ -363,7 +352,15 @@ struct
|
||||
, searchString
|
||||
)
|
||||
in
|
||||
(newApp, drawMsg)
|
||||
AppWith.bufferAndCursorIdx
|
||||
( app
|
||||
, buffer
|
||||
, cursorIdx
|
||||
, NORMAL_MODE ""
|
||||
, startLine
|
||||
, searchList
|
||||
, drawMsg
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -735,10 +732,9 @@ struct
|
||||
)
|
||||
|
||||
val mode = NORMAL_MODE ""
|
||||
val newApp = AppWith.bufferAndCursorIdx
|
||||
(app, buffer, cursorIdx, mode, startLine, searchList)
|
||||
in
|
||||
(newApp, drawMsg)
|
||||
AppWith.bufferAndCursorIdx
|
||||
(app, buffer, cursorIdx, mode, startLine, searchList, drawMsg)
|
||||
end
|
||||
|
||||
(* command-parsing functions *)
|
||||
@@ -755,9 +751,8 @@ struct
|
||||
let
|
||||
val str = str ^ Char.toString chr
|
||||
val mode = NORMAL_MODE str
|
||||
val newApp = AppWith.mode (app, mode)
|
||||
in
|
||||
(newApp, [])
|
||||
AppWith.mode (app, mode, [])
|
||||
end
|
||||
|
||||
fun handleChr (app: app_type, count, chr, str) =
|
||||
@@ -791,9 +786,8 @@ struct
|
||||
val chr = Char.toString chr
|
||||
val str = str ^ chr
|
||||
val mode = NORMAL_MODE str
|
||||
val newApp = AppWith.mode (app, mode)
|
||||
in
|
||||
(newApp, [])
|
||||
AppWith.mode (app, mode, [])
|
||||
end
|
||||
else
|
||||
move (app, 1, Cursor.vi0)
|
||||
@@ -826,9 +820,8 @@ struct
|
||||
let
|
||||
val str = if Char.isDigit chr then str ^ Char.toString chr else ""
|
||||
val mode = NORMAL_MODE str
|
||||
val newApp = AppWith.mode (app, mode)
|
||||
in
|
||||
(newApp, [])
|
||||
AppWith.mode (app, mode, [])
|
||||
end
|
||||
|
||||
fun parseDelete (strPos, str, count, app, newCmd) =
|
||||
|
||||
@@ -2,32 +2,8 @@ structure AppWith =
|
||||
struct
|
||||
open AppType
|
||||
|
||||
fun startLine (app: app_type, startLine, newBuffer) =
|
||||
let
|
||||
val
|
||||
{ startLine = _
|
||||
, buffer = _
|
||||
, searchList
|
||||
, searchString
|
||||
, mode
|
||||
, windowWidth
|
||||
, windowHeight
|
||||
, cursorIdx
|
||||
} = app
|
||||
in
|
||||
{ startLine = startLine
|
||||
, buffer = newBuffer
|
||||
, searchList = searchList
|
||||
, searchString = searchString
|
||||
, mode = mode
|
||||
, windowWidth = windowWidth
|
||||
, windowHeight = windowHeight
|
||||
, cursorIdx = cursorIdx
|
||||
}
|
||||
end
|
||||
|
||||
fun bufferAndSize
|
||||
(app: app_type, newBuffer, newWidth, newHeight, newSearchList) =
|
||||
(app: app_type, newBuffer, newWidth, newHeight, newSearchList, newMsgs) =
|
||||
let
|
||||
val
|
||||
{ mode
|
||||
@@ -35,6 +11,7 @@ struct
|
||||
, windowWidth = _
|
||||
, windowHeight = _
|
||||
, searchList = _
|
||||
, msgs = _
|
||||
, searchString
|
||||
, startLine
|
||||
, cursorIdx
|
||||
@@ -45,6 +22,7 @@ struct
|
||||
, windowWidth = newWidth
|
||||
, windowHeight = newHeight
|
||||
, searchList = newSearchList
|
||||
, msgs = newMsgs
|
||||
, searchString = searchString
|
||||
, startLine = startLine
|
||||
, cursorIdx = cursorIdx
|
||||
@@ -58,6 +36,7 @@ struct
|
||||
, newMode
|
||||
, newStartLine
|
||||
, newSearchList
|
||||
, newMsgs
|
||||
) =
|
||||
let
|
||||
val
|
||||
@@ -66,6 +45,7 @@ struct
|
||||
, cursorIdx = _
|
||||
, startLine = _
|
||||
, searchList = _
|
||||
, msgs = _
|
||||
, searchString
|
||||
, windowWidth
|
||||
, windowHeight
|
||||
@@ -76,16 +56,18 @@ struct
|
||||
, cursorIdx = newCursorIdx
|
||||
, startLine = newStartLine
|
||||
, searchList = newSearchList
|
||||
, msgs = newMsgs
|
||||
, searchString = searchString
|
||||
, windowWidth = windowWidth
|
||||
, windowHeight = windowHeight
|
||||
}
|
||||
end
|
||||
|
||||
fun mode (app: app_type, newMode) =
|
||||
fun mode (app: app_type, newMode, newMsgs) =
|
||||
let
|
||||
val
|
||||
{ mode = _
|
||||
, msgs = _
|
||||
, buffer
|
||||
, searchList
|
||||
, searchString
|
||||
@@ -96,6 +78,7 @@ struct
|
||||
} = app
|
||||
in
|
||||
{ mode = newMode
|
||||
, msgs = newMsgs
|
||||
, buffer = buffer
|
||||
, searchList = searchList
|
||||
, searchString = searchString
|
||||
@@ -112,6 +95,7 @@ struct
|
||||
{ searchList = _
|
||||
, buffer = _
|
||||
, searchString = _
|
||||
, msgs
|
||||
, mode
|
||||
, cursorIdx
|
||||
, windowWidth
|
||||
@@ -122,6 +106,7 @@ struct
|
||||
{ searchList = newSearchList
|
||||
, buffer = newBuffer
|
||||
, searchString = newSearchString
|
||||
, msgs = msgs
|
||||
, mode = mode
|
||||
, cursorIdx = cursorIdx
|
||||
, windowWidth = windowWidth
|
||||
|
||||
@@ -73,6 +73,7 @@ struct
|
||||
val buffer = LineGap.goToIdx (origIdx, buffer)
|
||||
val searchList = SearchList.goToNum (origIdx, searchList)
|
||||
in
|
||||
(* todo: probably change return type to (buffer * searchList) later *)
|
||||
AppWith.searchList (app, searchList, buffer, searchString)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user