}
//Readline functions
-void cleanReadLine(CleanString prompt, int history, CleanString *result, int *eof)
+void cleanReadLine(
+ CleanString prompt, int history, CleanString *result, int *eof)
{
char *cs_prompt = cleanStringToCString(prompt);
}
//Moving Around the History List
+int cleanHistorySetPos(int pos)
+{
+ return history_set_pos(pos);
+}
+
+void cleanPreviousHistory(
+ CleanString *line, CleanString *timestamp, int *null)
+{
+ *null = 0;
+ HIST_ENTRY *entry = previous_history();
+ char *cs_line = "";
+ char *cs_stamp = "";
+ if(entry == NULL){
+ *null = 1;
+ } else {
+ *null = 0;
+ cs_line = entry->line;
+ cs_stamp = entry->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 cleanNextHistory(CleanString *line, CleanString *timestamp, int *null)
+{
+ *null = 0;
+ HIST_ENTRY *entry = next_history();
+ char *cs_line = "";
+ char *cs_stamp = "";
+ if(entry == NULL){
+ *null = 1;
+ } else {
+ *null = 0;
+ cs_line = entry->line;
+ cs_stamp = entry->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);
+}
//Searching the History List
int cleanHistorySearch(CleanString s, int dir)
[history](http://cnswww.cns.cwru.edu/php/chet/readline/history.html) api
functions as close as possible
+*Please note that some functions will crash if `usingHistory` is not called*
+
###Changelog
- 0.3 (2016-01-26)
readLine :: !String !Bool !*env -> (!Maybe String, !*env)
//Initializing History and State Management
-//Note that this HAS to be executed when you want to add entries when the
-//history has not been used
-usingHistory :: !*env -> *env
+usingHistory :: !*env -> *env
historyGetHistoryState :: !*env -> (!HistoryState, !*env)
historySetHistoryState :: !HistoryState !*env -> *env
historyTotalBytes :: !*env -> (!Int, !*env)
//Moving Around the History List
-//TODO
+historySetPos :: !Int !*env -> (!Int, !*env)
+previousHistory :: !*env -> (!Maybe HistoryItem, !*env)
+nextHistory :: !*env -> (!Maybe HistoryItem, !*env)
//Searching the History List
-//Note that the return integers are just success flags. The actual found item
-//will be the current history position and the int is the offset of the search
-//within that item...
historySearch :: !String !Int !*env-> (!Int, !*env)
historySearchPrefix :: !String !Int !*env-> (!Int, !*env)
historySearchPos :: !String !Int !Int !*env-> (!Int, !*env)
}
//Moving Around the History List
+historySetPos :: !Int !*env -> (!Int, !*env)
+historySetPos i e = code {
+ ccall cleanHistorySetPos "I:I:A"
+ }
+
+previousHistory :: !*env -> (!Maybe HistoryItem, !*env)
+previousHistory e
+# (line, timestamp, null, e) = previousHistoryItem e
+= (if null Nothing (Just {HistoryItem | line=line, timestamp=timestamp}), e)
+ where
+ previousHistoryItem :: !*env -> (!String, !String, !Bool, !*env)
+ previousHistoryItem e = code {
+ ccall cleanPreviousHistory ":VSSI:A"
+ }
+
+nextHistory :: !*env -> (!Maybe HistoryItem, !*env)
+nextHistory e
+# (line, timestamp, null, e) = nextHistoryItem e
+= (if null Nothing (Just {HistoryItem | line=line, timestamp=timestamp}), e)
+ where
+ nextHistoryItem :: !*env -> (!String, !String, !Bool, !*env)
+ nextHistoryItem e = code {
+ ccall cleanNextHistory ":VSSI:A"
+ }
//Searching the History List
historySearch :: !String !Int !*env-> (!Int, !*env)
#! (i, w) = historyIsStifled w
#! w = unstifleHistory w
#! (i, w) = historyIsStifled w
+#! (i, w) = historySetPos 1 w
+#! (h, w) = previousHistory w
+#! (h, w) = nextHistory w
#! (oh, w) = historyGetHistoryState w
#! w = historySetHistoryState testHistory w
#! (h, w) = historyGetHistoryState w
#! w = clearHistory w
-= (
- toString h,
- w)
+= (toString h, w)