Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 72 lines (64 sloc) 2.488 kb
13104d3a »
2009-08-14 first commit
1
2 import EditBuffer
3 import Rendering
4 import Input
5 import Char
34679785 »
2009-08-15 Added moveToLine
6 import Control.Exception
13104d3a »
2009-08-14 first commit
7
8 data EditMode = Command | Insert deriving (Eq,Show)
9
10 vih :: IO ()
11 vih =
12 do initInput
13 mainLoop Command emptyBuffer
14
15 mainLoop :: EditMode -> EditBuffer -> IO ()
91a14d40 »
2009-08-15 Added autoscrolling via frame function on EditBuffer
16 mainLoop mode previousBuffer =
13104d3a »
2009-08-14 first commit
17 do cls
91a14d40 »
2009-08-15 Added autoscrolling via frame function on EditBuffer
18 buffer <- return (frame previousBuffer)
19 render buffer
13104d3a »
2009-08-14 first commit
20 -- writeAt commandHome (showRepresentation buffer)
21 ch <- getInputChar
22 if mode == Insert
23 then
24 case ch of
25 '\ESC' -> mainLoop Command (enterCommandMode buffer)
c3676ba6 »
2009-08-15 Added `replace char' support with 'r'
26 _ -> if isInputChar ch
27 then mainLoop mode (insertChar ch buffer)
28 else mainLoop mode buffer
13104d3a »
2009-08-14 first commit
29 else
30 case ch of
31 ':' -> handleCommandLine buffer
32 'i' -> mainLoop Insert buffer
33 'h' -> mainLoop mode (moveLeft buffer)
34 'j' -> mainLoop mode (moveDown buffer)
35 'k' -> mainLoop mode (moveUp buffer)
36 'l' -> mainLoop mode (moveRight buffer)
37 'd' -> do nextCh <- getInputChar
38 if nextCh == 'd'
39 then mainLoop mode (deleteLine buffer)
40 else mainLoop mode buffer
41 'g' -> do nextCh <- getInputChar
42 if nextCh == 'g'
43 then mainLoop mode (moveToHome buffer)
44 else mainLoop mode buffer
45 'G' -> mainLoop mode (moveToEnd buffer)
46 '0' -> mainLoop mode (moveToLineStart buffer)
47 '$' -> mainLoop mode (moveToLineEnd buffer)
48 'o' -> mainLoop Insert (insertLineAfter buffer)
c3676ba6 »
2009-08-15 Added `replace char' support with 'r'
49 'r' -> do nextCh <- getInputChar
50 if isInputChar nextCh
51 then mainLoop mode (replaceChar nextCh buffer)
52 else mainLoop mode buffer
d31b8ba4 »
2009-08-15 Added support for `word forward' with 'w'. Works only on alnums curre…
53 'w' -> mainLoop mode (wordForward buffer)
13104d3a »
2009-08-14 first commit
54 'x' -> mainLoop mode (deleteChar buffer)
55 _ -> mainLoop mode buffer
56
57
34679785 »
2009-08-15 Added moveToLine
58 -- aborts when line command is not parseable. Fix with exception catch
13104d3a »
2009-08-14 first commit
59 handleCommandLine :: EditBuffer -> IO ()
60 handleCommandLine buffer =
61 do goto commandHome
62 putStr ":"
63 command <- getLine
64 if head command == 'q'
65 then return ()
34679785 »
2009-08-15 Added moveToLine
66 else if isDigit (head command)
67 then mainLoop Command (moveToLine (read command :: Int) buffer)
68 else mainLoop Command buffer
c3676ba6 »
2009-08-15 Added `replace char' support with 'r'
69
70
71 isInputChar :: Char -> Bool
72 isInputChar ch = (not (isControl ch)) || (ch == '\n')
73
Something went wrong with that request. Please try again.