summaryrefslogtreecommitdiffstats
path: root/Main.hs
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2014-07-27 15:11:38 +0200
committertv <tv@shackspace.de>2014-07-27 15:11:38 +0200
commitc3e9446f79998b78cfe47aec26baa148403d8dfa (patch)
tree012a130a572379031abfdde08b9911ff4d119444 /Main.hs
parent7d4433f98c0156a374cef2de5b0bddf744925038 (diff)
add Buffer.{Class,Motion} modules
Diffstat (limited to 'Main.hs')
-rw-r--r--Main.hs32
1 files changed, 15 insertions, 17 deletions
diff --git a/Main.hs b/Main.hs
index ac0b236..484f72f 100644
--- a/Main.hs
+++ b/Main.hs
@@ -19,6 +19,8 @@ import Control.Monad.Error
import Control.Monad.Writer
import Control.Monad.State
+import Buffer
+
data VTState = VTState
{ buffer :: Buffer
@@ -28,10 +30,6 @@ data VTState = VTState
emptyState = VTState emptyBuffer (NormalMode nmap)
-type Buffer = (String, String)
-
-emptyBuffer = ("", "")
-
main :: IO ()
main = do
@@ -172,35 +170,40 @@ runExecCommand st (ExecM ex) =
+insertChar c (ls, rs) = (ls ++ [c], rs)
+
+
execCommand :: Command -> ExecM ()
execCommand GotoBOL =
- modifyBuffer $ \(lhs, rhs) -> ("", lhs ++ rhs)
+ modifyBuffer (move GotoFirstChar)
execCommand GotoEOL =
- modifyBuffer $ \(lhs, rhs) -> (lhs ++ rhs, "")
+ modifyBuffer (move GotoEndOfLine)
execCommand MoveCursorLeft = do
get >>= flip (when . null . fst . buffer)
(throwError $ OtherError "no char to move left")
- modifyBuffer $ \(lhs, rhs) -> (init lhs, last lhs : rhs)
+ modifyBuffer (move $ GotoLeft 1)
execCommand MoveCursorRight = do
get >>= flip (when . null . snd . buffer)
(throwError $ OtherError "no char to move right")
- modifyBuffer $ \(lhs, rhs) -> (lhs ++ [head rhs], tail rhs)
+ modifyBuffer (move $ GotoRight 1)
execCommand (InsertChar c) =
- modifyBuffer $ \(lhs, rhs) -> (lhs ++ [c], rhs)
+ modifyBuffer (insertChar c)
execCommand (InsertCharThenChangeMode c m) =
modify $ \ q -> q
- { buffer = (\(lhs, rhs) -> (lhs ++ [c], rhs)) $ buffer q
- , mode = m
+ { mode = m
+ , buffer = insertChar c (buffer q)
}
execCommand InsertNextCharVerbatim =
- modify $ \ q -> q { mode = VerbatimMode }
+ modify $ \ q -> q
+ { mode = VerbatimMode
+ }
execCommand ExecuteInputBuffer = do
b <- gets buffer
@@ -290,11 +293,6 @@ ringBell = putStr "\x07" -- BEL '\a'
moveCursorLeft 0 = return ()
moveCursorLeft i = putStr $ "\x1b[" ++ show i ++ "D"
-moveCursorRight 0 = return ()
-moveCursorRight i = putStr $ "\x1b[" ++ show i ++ "C"
-
-clearLineFromCursorRight = putStr "\x1b[0K"
-
-- TODO? charToCode c = "\\x" ++ showHex (ord c)
charToCode c = "\\x" ++ showIntAtBase 16 intToDigit (ord c) ""