setting history now works
[CleanReadLine.git] / ReadLine.icl
1 implementation module ReadLine
2
3 import StdEnv
4
5 import code from "readLine.o"
6
7 //Readline
8 readLine :: !String !Bool !*env -> (!String, !*env)
9 readLine s h e = code {
10 ccall cleanReadLine "SI:S:A"
11 }
12
13 setReadLineName :: !String !*env -> !*env
14 setReadLineName s e = code {
15 ccall cleanSetReadLineName "S:V:A"
16 }
17
18 //Initializing History and State Management
19 usingHistory :: !*env -> !*env
20 usingHistory e = code {
21 ccall cleanUsingHistory ":V:A"
22 }
23
24 historyGetHistoryState :: !*env -> (!HistoryState, !*env)
25 historyGetHistoryState e
26 # (offset, num, flags, e) = getState e
27 # (entries, e) = getItems num e
28 = ({HistoryState | entries=entries, offset=offset, flags=flags}, e)
29 where
30 getState :: !*env -> (!Int, !Int, !Int, !*env)
31 getState e= code {
32 ccall cleanGetState ":VIII:A"
33 }
34 getItems :: !Int !*env -> (![HistoryItem], !*env)
35 getItems 0 e = ([], e)
36 getItems i e
37 # (line, timestamp, e) = getItem (i-1) e
38 # (rest, e) = getItems (i-1) e
39 = ([{line=line,timestamp=timestamp}:rest], e)
40
41 getItem :: !Int !*env -> (!String, !String, !*env)
42 getItem i e = code {
43 ccall cleanGetHistoryItem "I:VSS:A"
44 }
45
46
47 historySetHistoryState :: !HistoryState !*env -> !*env
48 historySetHistoryState {entries,offset,flags} e
49 # e = initNewHistoryState offset flags (length entries) e
50 # e = setItems entries 0 e
51 = commit e
52 where
53 initNewHistoryState :: !Int !Int !Int !*env -> !*env
54 initNewHistoryState o f l e = code {
55 ccall cleanInitNewHistoryState "III:V:A"
56 }
57 setItems :: ![HistoryItem] !Int !*env -> !*env
58 setItems [] _ e = e
59 setItems [x:xs] i e
60 # e = setItem i x.line x.timestamp e
61 = setItems xs (i+1) e
62
63 setItem :: !Int !String !String !*env -> !*env
64 setItem i l t e = code {
65 ccall cleanSetNewHistoryEntry "ISS:V:A"
66 }
67
68 commit :: !*env -> !*env
69 commit e = code {
70 ccall cleanCommitSetHistory ":V:A"
71 }
72
73 //History List Management
74 addHistory :: !String !*env -> !*env
75 addHistory s e = code {
76 ccall cleanAddHistory "S:V:A"
77 }
78
79 clearHistory :: !*env -> !*env
80 clearHistory e = code {
81 ccall cleanClearHistory ":V:A"
82 }
83
84 //Information About the History List
85
86 //Moving Around the History List
87
88 //Searching the History List
89 historySearch :: !String !Int !*env-> (!Int, !*env)
90 historySearch s i e = code {
91 ccall cleanHistorySearch "SI:I:A"
92 }
93
94 historySearchPrefix :: !String !Int !*env-> (!Int, !*env)
95 historySearchPrefix s i e = code {
96 ccall cleanHistorySearchPrefix "SI:I:A"
97 }
98
99 historySearchPos :: !String !Int !Int !*env-> (!Int, !*env)
100 historySearchPos s i1 i2 e = code {
101 ccall cleanHistorySearchPos "SI:I:A"
102 }
103
104
105 //Managing the History File
106 readHistory :: !String !*env -> (!Bool, !*env)
107 readHistory s e = code {
108 ccall cleanReadHistory "S:I:A"
109 }
110
111 readHistoryRange :: !String !Int !Int !*env -> (!Bool, !*env)
112 readHistoryRange s i1 i2 e = code {
113 ccall cleanReadHistoryRange "SII:I:A"
114 }
115
116 writeHistory :: !String !*env -> (!Bool, !*env)
117 writeHistory s e = code {
118 ccall cleanWriteHistory "S:I:A"
119 }
120
121 appendHistory :: !Int !String !*env -> (!Bool, !*env)
122 appendHistory i s e = code {
123 ccall cleanWriteHistory "IS:I:A"
124 }
125
126 historyTruncateFile :: !String !Int !*env -> (!Bool, !*env)
127 historyTruncateFile i s e = code {
128 ccall cleanWriteHistory "SI:I:A"
129 }