using_history();
}
+void cleanGetState(int *offset, int *num, int *flags){
+ *offset = history_get_history_state()->offset;
+ *num = history_get_history_state()->length;
+ *flags = history_get_history_state()->flags;
+}
+
+void cleanGetHistoryItem(int num, CleanString *line, CleanString *timestamp){
+ ;
+ char *cs_line = history_get_history_state()->entries[num]->line;
+ char *cs_stamp = history_get_history_state()->entries[num]->timestamp;
+
+ CleanStringVariable(cleanLine, strlen(cs_line));
+ *line = (CleanString) cleanLine;
+ memcpy(CleanStringCharacters(cleanLine), cs_line, strlen(cs_line));
+ CleanStringLength(cleanLine) = strlen(cs_line);
+
+ CleanStringVariable(cleanTimestamp, strlen(cs_stamp));
+ *timestamp = (CleanString) cleanTimestamp;
+ memcpy(CleanStringCharacters(cleanTimestamp), cs_stamp, strlen(cs_stamp));
+ CleanStringLength(cleanTimestamp) = strlen(cs_stamp);
+}
+
void cleanAddHistory(CleanString entry){
char *cs_entry = cleanStringToCString(entry);
add_history(cs_entry);
definition module ReadLine
+:: HistoryItem = {line :: String, timestamp :: String}
+
+:: HistoryState = {entries :: [HistoryItem], offset :: Int, flags :: Int}
+
//Readline
readLine :: !String !Bool !*env -> (!String, !*env)
setReadLineName :: !String !*env -> !*env
//Note that this HAS to be executed when you want to add entries when the
//history has not been used
usingHistory :: !*env -> !*env
+historyGetHistoryState :: !*env -> (!HistoryState, !*env)
+historySetHistoryState :: !HistoryState !*env -> !*env
//History List Management
addHistory :: !String !*env -> !*env
ccall cleanUsingHistory "-"
}
+historyGetHistoryState :: !*env -> (!HistoryState, !*env)
+historyGetHistoryState e
+# (offset, num, flags, e) = getState e
+# (entries, e) = getItems num e
+= ({HistoryState | entries=entries, offset=offset, flags=flags}, e)
+ where
+ getState :: !*env -> (!Int, !Int, !Int, !*env)
+ getState e= code inline {
+ ccall cleanGetState "-III"
+ }
+ getItems :: !Int !*env -> (![HistoryItem], !*env)
+ getItems 0 e = ([], e)
+ getItems i e
+ # (line, timestamp, e) = getItem (i-1) e
+ # (rest, e) = getItems (i-1) e
+ = ([{line=line,timestamp=timestamp}:rest], e)
+
+ getItem :: !Int !*env -> (!String, !String, !*env)
+ getItem i e = code inline {
+ ccall cleanGetHistoryItem "I-SS"
+ }
+
+
+historySetHistoryState :: !HistoryState !*env -> !*env
+historySetHistoryState hs e = abort "Not Implemented"
+
//History List Management
addHistory :: !String !*env -> !*env
addHistory s e = code inline {
import StdEnv
import ReadLine
-Start :: *World -> (Int, String, *World)
+Start :: *World -> (Int, String, HistoryState, *World)
Start w
# (f, w) = stdio w
#! w = setReadLineName "Test program" w
#! (s, w) = readLine "uparrow should word with history: " False w
#! (_, w) = writeHistory "readline.history" w
#! (i, w) = historySearch "testentry" -1 w
-//#! w = clearHistory w
-= (i, s, w)
+#! (h, w) = historyGetHistoryState w
+#! w = clearHistory w
+= (i, s, h, w)