X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=ReadLine.icl;h=632011755ef658e7ee6019e6bb79568b351560ec;hb=4930c9c0ddeaa5c9421d36396fd74d22db1385c6;hp=07b90acc85c9faedc4ee3f0a01c43fe7c9197ad2;hpb=b25f55e7fc44e6fedff55340f3d6e6cdfa413c54;p=CleanReadLine.git diff --git a/ReadLine.icl b/ReadLine.icl index 07b90ac..6320117 100644 --- a/ReadLine.icl +++ b/ReadLine.icl @@ -4,21 +4,37 @@ import StdEnv import code from "readLine.o" +instance toString HistoryItem where + toString {line,timestamp} = line +++ " (" +++ timestamp +++ ")" +instance toString HistoryState where + toString {entries,offset,flags} = "[" +++ toS entries +++ "]\n" +++ + "offset: " +++ toString offset +++ "\nflags: " +++ toString flags + where + toS :: [HistoryItem] -> String + toS [] = "--empty--" + toS [x] = toString x + toS [x:xs] = toString x +++ "," + //Readline -readLine :: !String !Bool !*env -> (!String, !*env) -readLine s h e = code { - ccall cleanReadLine "SI:S:A" - } +readLine :: !String !Bool !*env -> (!Maybe String, !*env) +readLine s h e +# (s, eof, e) = readLineEof s h e += (if eof Nothing (Just s), e) + where + readLineEof :: !String !Bool !*env -> (!String, !Bool, !*env) + readLineEof s h e = code { + ccall cleanReadLine "SI:VSI:A" + } setReadLineName :: !String !*env -> !*env setReadLineName s e = code { - ccall cleanSetReadLineName "S:V:A" + ccall cleanSetReadLineName "S:V:A" } //Initializing History and State Management usingHistory :: !*env -> !*env usingHistory e = code { - ccall cleanUsingHistory ":V:A" + ccall cleanUsingHistory ":V:A" } historyGetHistoryState :: !*env -> (!HistoryState, !*env) @@ -29,8 +45,8 @@ historyGetHistoryState e where getState :: !*env -> (!Int, !Int, !Int, !*env) getState e= code { - ccall cleanGetState ":VIII:A" - } + ccall cleanGetState ":VIII:A" + } getItems :: !Int !*env -> (![HistoryItem], !*env) getItems 0 e = ([], e) getItems i e @@ -40,8 +56,8 @@ historyGetHistoryState e getItem :: !Int !*env -> (!String, !String, !*env) getItem i e = code { - ccall cleanGetHistoryItem "I:VSS:A" - } + ccall cleanGetHistoryItem "I:VSS:A" + } historySetHistoryState :: !HistoryState !*env -> !*env @@ -73,57 +89,124 @@ historySetHistoryState {entries,offset,flags} e //History List Management addHistory :: !String !*env -> !*env addHistory s e = code { - ccall cleanAddHistory "S:V:A" + ccall cleanAddHistory "S:V:A" } +addHistoryTime :: !String !*env -> !*env +addHistoryTime s e = code { + ccall cleanAddHistoryTime "S:V:A" + } + +removeHistory :: !Int !*env -> (!HistoryItem, !*env) +removeHistory i e +# (line, timestamp, e) = removeHistoryItem i e += ({HistoryItem | line=line, timestamp=timestamp}, e) + where + removeHistoryItem :: !Int !*env -> (!String, !String, !*env) + removeHistoryItem i e = code { + ccall cleanRemoveHistory "I:VSS:A" + } + +replaceHistoryEntry :: !Int !String !*env -> (!HistoryItem, !*env) +replaceHistoryEntry i s e +# (line, timestamp, e) = replaceItem i s e += ({HistoryItem | line=line, timestamp=timestamp}, e) + where + replaceItem :: !Int !String !*env -> (!String, !String, !*env) + replaceItem i s e = code { + ccall cleanReplaceHistoryEntry "IS:VSS:A" + } + clearHistory :: !*env -> !*env clearHistory e = code { - ccall cleanClearHistory ":V:A" + ccall cleanClearHistory ":V:A" + } + +stifleHistory :: !Int !*env -> !*env +stifleHistory i e = code { + ccall cleanStifleHistory "I:V:A" + } + +unstifleHistory :: !*env -> !*env +unstifleHistory e = code { + ccall cleanUnstifleHistory ":V:A" + } + +historyIsStifled :: !*env -> (!Int, !*env) +historyIsStifled e = code { + ccall cleanHistoryIsStifled ":I:A" } //Information About the History List +historyList :: !*env -> (![HistoryItem], !*env) +historyList e +# ({entries,offset,flags}, e) = historyGetHistoryState e += (entries, e) + +whereHistory :: !*env -> (!Int, !*env) +whereHistory e +# ({entries,offset,flags}, e) = historyGetHistoryState e += (offset, e) + +currentHistory :: !*env -> (!Maybe HistoryItem, !*env) +currentHistory e +# ({entries,offset,flags}, e) = historyGetHistoryState e += (if (isEmpty entries) Nothing (Just (entries!!offset)), e) + +historyGet :: !Int !*env -> (!Maybe HistoryItem, !*env) +historyGet i e +# ({entries,offset,flags}, e) = historyGetHistoryState e += (if (isEmpty entries) Nothing (Just (entries!!i)), e) + +historyGetTime :: HistoryItem -> String +historyGetTime {line,timestamp} = timestamp + +historyTotalBytes :: !*env -> (!Int, !*env) +historyTotalBytes e = code { + ccall cleanHistoryTotalBytes ":I:A" + } //Moving Around the History List //Searching the History List historySearch :: !String !Int !*env-> (!Int, !*env) historySearch s i e = code { - ccall cleanHistorySearch "SI:I:A" + ccall cleanHistorySearch "SI:I:A" } historySearchPrefix :: !String !Int !*env-> (!Int, !*env) historySearchPrefix s i e = code { - ccall cleanHistorySearchPrefix "SI:I:A" + ccall cleanHistorySearchPrefix "SI:I:A" } historySearchPos :: !String !Int !Int !*env-> (!Int, !*env) historySearchPos s i1 i2 e = code { - ccall cleanHistorySearchPos "SI:I:A" + ccall cleanHistorySearchPos "SI:I:A" } //Managing the History File readHistory :: !String !*env -> (!Bool, !*env) readHistory s e = code { - ccall cleanReadHistory "S:I:A" + ccall cleanReadHistory "S:I:A" } readHistoryRange :: !String !Int !Int !*env -> (!Bool, !*env) readHistoryRange s i1 i2 e = code { - ccall cleanReadHistoryRange "SII:I:A" + ccall cleanReadHistoryRange "SII:I:A" } writeHistory :: !String !*env -> (!Bool, !*env) writeHistory s e = code { - ccall cleanWriteHistory "S:I:A" + ccall cleanWriteHistory "S:I:A" } appendHistory :: !Int !String !*env -> (!Bool, !*env) appendHistory i s e = code { - ccall cleanWriteHistory "IS:I:A" + ccall cleanWriteHistory "IS:I:A" } historyTruncateFile :: !String !Int !*env -> (!Bool, !*env) historyTruncateFile i s e = code { - ccall cleanWriteHistory "SI:I:A" + ccall cleanWriteHistory "SI:I:A" }