module System.Console.Isocline(
readline,
readlineEx,
setHistory,
historyClear,
historyRemoveLast,
historyAdd,
CompletionEnv,
completeFileName,
completeWord,
completeQuotedWord,
completeQuotedWordEx,
Completion(..),
completion,
isPrefix,
completionsFor,
wordCompleter,
highlightFmt,
Style, Fmt,
style,
plain,
pre,
putFmt,
putFmtLn,
styleDef,
styleOpen,
styleClose,
withStyle,
setPromptMarker,
enableAutoTab,
enableColor,
enableBeep,
enableMultiline,
enableHistoryDuplicates,
enableCompletionPreview,
enableMultilineIndent,
enableHighlight,
enableInlineHelp,
enableHint,
setHintDelay,
enableBraceMatching,
enableBraceInsertion,
setMatchingBraces,
setInsertionBraces,
setDefaultCompleter,
addCompletion,
addCompletionPrim,
addCompletions,
completeWordPrim,
completeQuotedWordPrim,
completeQuotedWordPrimEx,
readlineMaybe,
readlineExMaybe,
readlinePrim,
readlinePrimMaybe,
getPromptMarker,
getContinuationPromptMarker,
stopCompleting,
hasCompletions,
asyncStop,
HighlightEnv,
setDefaultHighlighter,
setDefaultFmtHighlighter,
termInit,
termDone,
withTerm,
termFlush,
termWrite,
termWriteLn,
termColor,
termBgColor,
termColorAnsi,
termBgColorAnsi,
termUnderline,
termReverse,
termReset
) where
import Data.List( intersperse, isPrefixOf )
import Control.Monad( when, foldM )
import Control.Exception( bracket )
import Foreign.C.String( CString, peekCString, peekCStringLen, withCString, castCharToCChar )
import Foreign.Ptr
import Foreign.C.Types
import qualified Data.ByteString as B ( useAsCString, packCString )
import qualified Data.Text as T ( pack, unpack )
import Data.Text.Encoding as TE ( decodeUtf8With, encodeUtf8)
import Data.Text.Encoding.Error ( lenientDecode )
data IcCompletionEnv
newtype CompletionEnv = CompletionEnv (Ptr IcCompletionEnv)
type CCompleterFun = Ptr IcCompletionEnv -> CString -> IO ()
type CompleterFun = CompletionEnv -> String -> IO ()
data IcHighlightEnv
newtype HighlightEnv = HighlightEnv (Ptr IcHighlightEnv)
type CHighlightFun = Ptr IcHighlightEnv -> CString -> Ptr () -> IO ()
type HighlightFun = HighlightEnv -> String -> IO ()
foreign import ccall ic_free :: (Ptr a) -> IO ()
foreign import ccall ic_malloc :: CSize -> IO (Ptr a)
foreign import ccall ic_strdup :: CString -> IO CString
foreign import ccall ic_readline :: CString -> IO CString
foreign import ccall ic_readline_ex :: CString -> FunPtr CCompleterFun -> (Ptr ()) -> FunPtr CHighlightFun -> (Ptr ()) -> IO CString
foreign import ccall ic_async_stop :: IO CCBool
unmaybe :: IO (Maybe String) -> IO String
unmaybe :: IO (Maybe String) -> IO String
unmaybe IO (Maybe String)
action
= do Maybe String
mb <- IO (Maybe String)
action
case Maybe String
mb of
Maybe String
Nothing -> String -> IO String
forall (m :: * -> *) a. Monad m => a -> m a
return String
""
Just String
s -> String -> IO String
forall (m :: * -> *) a. Monad m => a -> m a
return String
s
readline :: String -> IO String
readline :: String -> IO String
readline String
prompt
= IO (Maybe String) -> IO String
unmaybe (IO (Maybe String) -> IO String) -> IO (Maybe String) -> IO String
forall a b. (a -> b) -> a -> b
$ String -> IO (Maybe String)
readlineMaybe String
prompt
readlineMaybe:: String -> IO (Maybe String)
readlineMaybe :: String -> IO (Maybe String)
readlineMaybe String
prompt
= String -> (CString -> IO (Maybe String)) -> IO (Maybe String)
forall a. String -> (CString -> IO a) -> IO a
withUTF8String String
prompt ((CString -> IO (Maybe String)) -> IO (Maybe String))
-> (CString -> IO (Maybe String)) -> IO (Maybe String)
forall a b. (a -> b) -> a -> b
$ \CString
cprompt ->
do CString
cres <- CString -> IO CString
ic_readline CString
cprompt
Maybe String
res <- CString -> IO (Maybe String)
peekUTF8StringMaybe CString
cres
CString -> IO ()
forall a. Ptr a -> IO ()
ic_free CString
cres
Maybe String -> IO (Maybe String)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe String
res
readlineEx :: String -> Maybe (CompletionEnv -> String -> IO ()) -> Maybe (String -> Fmt) -> IO String
readlineEx :: String
-> Maybe (CompletionEnv -> String -> IO ())
-> Maybe (String -> String)
-> IO String
readlineEx String
prompt Maybe (CompletionEnv -> String -> IO ())
completer Maybe (String -> String)
highlighter
= IO (Maybe String) -> IO String
unmaybe (IO (Maybe String) -> IO String) -> IO (Maybe String) -> IO String
forall a b. (a -> b) -> a -> b
$ String
-> Maybe (CompletionEnv -> String -> IO ())
-> Maybe (String -> String)
-> IO (Maybe String)
readlineExMaybe String
prompt Maybe (CompletionEnv -> String -> IO ())
completer Maybe (String -> String)
highlighter
readlineExMaybe :: String -> Maybe (CompletionEnv -> String -> IO ()) -> Maybe (String -> Fmt) -> IO (Maybe String)
readlineExMaybe :: String
-> Maybe (CompletionEnv -> String -> IO ())
-> Maybe (String -> String)
-> IO (Maybe String)
readlineExMaybe String
prompt Maybe (CompletionEnv -> String -> IO ())
completer Maybe (String -> String)
mbhighlighter
= String
-> Maybe (CompletionEnv -> String -> IO ())
-> Maybe (HighlightEnv -> String -> IO ())
-> IO (Maybe String)
readlinePrimMaybe String
prompt Maybe (CompletionEnv -> String -> IO ())
completer (case Maybe (String -> String)
mbhighlighter of
Maybe (String -> String)
Nothing -> Maybe (HighlightEnv -> String -> IO ())
forall a. Maybe a
Nothing
Just String -> String
hl -> (HighlightEnv -> String -> IO ())
-> Maybe (HighlightEnv -> String -> IO ())
forall a. a -> Maybe a
Just ((String -> String) -> HighlightEnv -> String -> IO ()
highlightFmt String -> String
hl))
readlinePrim :: String -> Maybe (CompletionEnv -> String -> IO ()) -> Maybe (HighlightEnv -> String -> IO ()) -> IO String
readlinePrim :: String
-> Maybe (CompletionEnv -> String -> IO ())
-> Maybe (HighlightEnv -> String -> IO ())
-> IO String
readlinePrim String
prompt Maybe (CompletionEnv -> String -> IO ())
completer Maybe (HighlightEnv -> String -> IO ())
highlighter
= IO (Maybe String) -> IO String
unmaybe (IO (Maybe String) -> IO String) -> IO (Maybe String) -> IO String
forall a b. (a -> b) -> a -> b
$ String
-> Maybe (CompletionEnv -> String -> IO ())
-> Maybe (HighlightEnv -> String -> IO ())
-> IO (Maybe String)
readlinePrimMaybe String
prompt Maybe (CompletionEnv -> String -> IO ())
completer Maybe (HighlightEnv -> String -> IO ())
highlighter
readlinePrimMaybe :: String -> Maybe (CompletionEnv -> String -> IO ()) -> Maybe (HighlightEnv -> String -> IO ()) -> IO (Maybe String)
readlinePrimMaybe :: String
-> Maybe (CompletionEnv -> String -> IO ())
-> Maybe (HighlightEnv -> String -> IO ())
-> IO (Maybe String)
readlinePrimMaybe String
prompt Maybe (CompletionEnv -> String -> IO ())
completer Maybe (HighlightEnv -> String -> IO ())
highlighter
= String -> (CString -> IO (Maybe String)) -> IO (Maybe String)
forall a. String -> (CString -> IO a) -> IO a
withUTF8String String
prompt ((CString -> IO (Maybe String)) -> IO (Maybe String))
-> (CString -> IO (Maybe String)) -> IO (Maybe String)
forall a b. (a -> b) -> a -> b
$ \CString
cprompt ->
do FunPtr CCompleterFun
ccompleter <- Maybe (CompletionEnv -> String -> IO ())
-> IO (FunPtr CCompleterFun)
makeCCompleter Maybe (CompletionEnv -> String -> IO ())
completer
FunPtr CHighlightFun
chighlighter <- Maybe (HighlightEnv -> String -> IO ())
-> IO (FunPtr CHighlightFun)
makeCHighlighter Maybe (HighlightEnv -> String -> IO ())
highlighter
CString
cres <- CString
-> FunPtr CCompleterFun
-> Ptr ()
-> FunPtr CHighlightFun
-> Ptr ()
-> IO CString
ic_readline_ex CString
cprompt FunPtr CCompleterFun
ccompleter Ptr ()
forall a. Ptr a
nullPtr FunPtr CHighlightFun
chighlighter Ptr ()
forall a. Ptr a
nullPtr
Maybe String
res <- CString -> IO (Maybe String)
peekUTF8StringMaybe CString
cres
CString -> IO ()
forall a. Ptr a -> IO ()
ic_free CString
cres
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (FunPtr CCompleterFun
ccompleter FunPtr CCompleterFun -> FunPtr CCompleterFun -> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr CCompleterFun
forall a. FunPtr a
nullFunPtr) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ FunPtr CCompleterFun -> IO ()
forall a. FunPtr a -> IO ()
freeHaskellFunPtr FunPtr CCompleterFun
ccompleter
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (FunPtr CHighlightFun
chighlighter FunPtr CHighlightFun -> FunPtr CHighlightFun -> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr CHighlightFun
forall a. FunPtr a
nullFunPtr) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ FunPtr CHighlightFun -> IO ()
forall a. FunPtr a -> IO ()
freeHaskellFunPtr FunPtr CHighlightFun
chighlighter
Maybe String -> IO (Maybe String)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe String
res
asyncStop :: IO Bool
asyncStop :: IO Bool
asyncStop
= IO CCBool -> IO Bool
uncbool (IO CCBool -> IO Bool) -> IO CCBool -> IO Bool
forall a b. (a -> b) -> a -> b
$ IO CCBool
ic_async_stop
foreign import ccall ic_set_history :: CString -> CInt -> IO ()
foreign import ccall ic_history_remove_last :: IO ()
foreign import ccall ic_history_clear :: IO ()
foreign import ccall ic_history_add :: CString -> IO ()
setHistory :: FilePath -> Int -> IO ()
setHistory :: String -> Int -> IO ()
setHistory String
fname Int
maxEntries
= String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
fname ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cfname ->
do CString -> CCBool -> IO ()
ic_set_history CString
cfname (Int -> CCBool
forall a. Enum a => Int -> a
toEnum Int
maxEntries)
historyRemoveLast :: IO ()
historyRemoveLast :: IO ()
historyRemoveLast
= IO ()
ic_history_remove_last
historyClear :: IO ()
historyClear :: IO ()
historyClear
= IO ()
ic_history_clear
historyAdd :: String -> IO ()
historyAdd :: String -> IO ()
historyAdd String
entry
= String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
entry ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
centry ->
do CString -> IO ()
ic_history_add CString
centry
type CCBool = CInt
type CCharClassFun = CString -> CLong -> IO CCBool
type CharClassFun = Char -> Bool
foreign import ccall ic_set_default_completer :: FunPtr CCompleterFun -> IO ()
foreign import ccall "wrapper" ic_make_completer :: CCompleterFun -> IO (FunPtr CCompleterFun)
foreign import ccall "wrapper" ic_make_charclassfun :: CCharClassFun -> IO (FunPtr CCharClassFun)
foreign import ccall ic_add_completion_ex :: Ptr IcCompletionEnv -> CString -> CString -> CString -> IO CCBool
foreign import ccall ic_add_completion_prim :: Ptr IcCompletionEnv -> CString -> CString -> CString -> CInt -> CInt -> IO CCBool
foreign import ccall ic_complete_filename :: Ptr IcCompletionEnv -> CString -> CChar -> CString -> CString -> IO ()
foreign import ccall ic_complete_word :: Ptr IcCompletionEnv -> CString -> FunPtr CCompleterFun -> FunPtr CCharClassFun -> IO ()
foreign import ccall ic_complete_qword :: Ptr IcCompletionEnv -> CString -> FunPtr CCompleterFun -> FunPtr CCharClassFun -> IO ()
foreign import ccall ic_complete_qword_ex :: Ptr IcCompletionEnv -> CString -> FunPtr CCompleterFun -> FunPtr CCharClassFun -> CChar -> CString -> IO ()
foreign import ccall ic_has_completions :: Ptr IcCompletionEnv -> IO CCBool
foreign import ccall ic_stop_completing :: Ptr IcCompletionEnv -> IO CCBool
data Completion = Completion {
Completion -> String
replacement :: String,
Completion -> String
display :: String,
Completion -> String
help :: String
} deriving (Completion -> Completion -> Bool
(Completion -> Completion -> Bool)
-> (Completion -> Completion -> Bool) -> Eq Completion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Completion -> Completion -> Bool
$c/= :: Completion -> Completion -> Bool
== :: Completion -> Completion -> Bool
$c== :: Completion -> Completion -> Bool
Eq, Int -> Completion -> String -> String
[Completion] -> String -> String
Completion -> String
(Int -> Completion -> String -> String)
-> (Completion -> String)
-> ([Completion] -> String -> String)
-> Show Completion
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [Completion] -> String -> String
$cshowList :: [Completion] -> String -> String
show :: Completion -> String
$cshow :: Completion -> String
showsPrec :: Int -> Completion -> String -> String
$cshowsPrec :: Int -> Completion -> String -> String
Show)
completion :: String -> Completion
completion :: String -> Completion
completion String
replacement
= String -> String -> String -> Completion
Completion String
replacement String
"" String
""
completionFull :: String -> String -> String -> Completion
completionFull :: String -> String -> String -> Completion
completionFull String
replacement String
display String
help
= String -> String -> String -> Completion
Completion String
replacement String
display String
help
isPrefix :: String -> Completion -> Bool
isPrefix :: String -> Completion -> Bool
isPrefix String
input Completion
compl
= String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf String
input (Completion -> String
replacement Completion
compl)
completionsFor :: String -> [String] -> [Completion]
completionsFor :: String -> [String] -> [Completion]
completionsFor String
input [String]
rs
= (String -> Completion) -> [String] -> [Completion]
forall a b. (a -> b) -> [a] -> [b]
map String -> Completion
completion ((String -> Bool) -> [String] -> [String]
forall a. (a -> Bool) -> [a] -> [a]
filter (String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf String
input) [String]
rs)
wordCompleter :: [String] -> (CompletionEnv -> String -> IO ())
wordCompleter :: [String] -> CompletionEnv -> String -> IO ()
wordCompleter [String]
completions
= (\CompletionEnv
cenv String
input -> CompletionEnv
-> String
-> Maybe (Char -> Bool)
-> (String -> [Completion])
-> IO ()
completeWord CompletionEnv
cenv String
input Maybe (Char -> Bool)
forall a. Maybe a
Nothing (\String
input -> String -> [String] -> [Completion]
completionsFor String
input [String]
completions))
setDefaultCompleter :: (CompletionEnv -> String -> IO ()) -> IO ()
setDefaultCompleter :: (CompletionEnv -> String -> IO ()) -> IO ()
setDefaultCompleter CompletionEnv -> String -> IO ()
completer
= do FunPtr CCompleterFun
ccompleter <- Maybe (CompletionEnv -> String -> IO ())
-> IO (FunPtr CCompleterFun)
makeCCompleter ((CompletionEnv -> String -> IO ())
-> Maybe (CompletionEnv -> String -> IO ())
forall a. a -> Maybe a
Just CompletionEnv -> String -> IO ()
completer)
FunPtr CCompleterFun -> IO ()
ic_set_default_completer FunPtr CCompleterFun
ccompleter
withCCompleter :: Maybe CompleterFun -> (FunPtr CCompleterFun -> IO a) -> IO a
withCCompleter :: Maybe (CompletionEnv -> String -> IO ())
-> (FunPtr CCompleterFun -> IO a) -> IO a
withCCompleter Maybe (CompletionEnv -> String -> IO ())
completer FunPtr CCompleterFun -> IO a
action
= IO (FunPtr CCompleterFun)
-> (FunPtr CCompleterFun -> IO ())
-> (FunPtr CCompleterFun -> IO a)
-> IO a
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Maybe (CompletionEnv -> String -> IO ())
-> IO (FunPtr CCompleterFun)
makeCCompleter Maybe (CompletionEnv -> String -> IO ())
completer) (\FunPtr CCompleterFun
cfun -> Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (FunPtr CCompleterFun
forall a. FunPtr a
nullFunPtr FunPtr CCompleterFun -> FunPtr CCompleterFun -> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr CCompleterFun
cfun) (FunPtr CCompleterFun -> IO ()
forall a. FunPtr a -> IO ()
freeHaskellFunPtr FunPtr CCompleterFun
cfun)) FunPtr CCompleterFun -> IO a
action
makeCCompleter :: Maybe CompleterFun -> IO (FunPtr CCompleterFun)
makeCCompleter :: Maybe (CompletionEnv -> String -> IO ())
-> IO (FunPtr CCompleterFun)
makeCCompleter Maybe (CompletionEnv -> String -> IO ())
Nothing = FunPtr CCompleterFun -> IO (FunPtr CCompleterFun)
forall (m :: * -> *) a. Monad m => a -> m a
return FunPtr CCompleterFun
forall a. FunPtr a
nullFunPtr
makeCCompleter (Just CompletionEnv -> String -> IO ()
completer)
= CCompleterFun -> IO (FunPtr CCompleterFun)
ic_make_completer CCompleterFun
wrapper
where
wrapper :: Ptr IcCompletionEnv -> CString -> IO ()
wrapper :: CCompleterFun
wrapper Ptr IcCompletionEnv
rpcomp CString
cprefx
= do String
prefx <- CString -> IO String
peekUTF8String0 CString
cprefx
CompletionEnv -> String -> IO ()
completer (Ptr IcCompletionEnv -> CompletionEnv
CompletionEnv Ptr IcCompletionEnv
rpcomp) String
prefx
addCompletion :: CompletionEnv -> Completion -> IO Bool
addCompletion :: CompletionEnv -> Completion -> IO Bool
addCompletion (CompletionEnv Ptr IcCompletionEnv
rpc) (Completion String
replacement String
display String
help)
= String -> (CString -> IO Bool) -> IO Bool
forall a. String -> (CString -> IO a) -> IO a
withUTF8String String
replacement ((CString -> IO Bool) -> IO Bool)
-> (CString -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \CString
crepl ->
String -> (CString -> IO Bool) -> IO Bool
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
display ((CString -> IO Bool) -> IO Bool)
-> (CString -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \CString
cdisplay ->
String -> (CString -> IO Bool) -> IO Bool
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
help ((CString -> IO Bool) -> IO Bool)
-> (CString -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \CString
chelp ->
do CCBool
cbool <- Ptr IcCompletionEnv -> CString -> CString -> CString -> IO CCBool
ic_add_completion_ex Ptr IcCompletionEnv
rpc CString
crepl CString
cdisplay CString
chelp
Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (CCBool -> Int
forall a. Enum a => a -> Int
fromEnum CCBool
cbool Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
0)
addCompletionPrim :: CompletionEnv -> Completion -> Int -> Int -> IO Bool
addCompletionPrim :: CompletionEnv -> Completion -> Int -> Int -> IO Bool
addCompletionPrim (CompletionEnv Ptr IcCompletionEnv
rpc) (Completion String
replacement String
display String
help) Int
deleteBefore Int
deleteAfter
= String -> (CString -> IO Bool) -> IO Bool
forall a. String -> (CString -> IO a) -> IO a
withUTF8String String
replacement ((CString -> IO Bool) -> IO Bool)
-> (CString -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \CString
crepl ->
String -> (CString -> IO Bool) -> IO Bool
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
display ((CString -> IO Bool) -> IO Bool)
-> (CString -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \CString
cdisplay ->
String -> (CString -> IO Bool) -> IO Bool
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
help ((CString -> IO Bool) -> IO Bool)
-> (CString -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \CString
chelp ->
do CCBool
cbool <- Ptr IcCompletionEnv
-> CString -> CString -> CString -> CCBool -> CCBool -> IO CCBool
ic_add_completion_prim Ptr IcCompletionEnv
rpc CString
crepl CString
cdisplay CString
chelp (Int -> CCBool
forall a. Enum a => Int -> a
toEnum Int
deleteBefore) (Int -> CCBool
forall a. Enum a => Int -> a
toEnum Int
deleteAfter)
Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (CCBool -> Int
forall a. Enum a => a -> Int
fromEnum CCBool
cbool Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
0)
addCompletions :: CompletionEnv -> [Completion] -> IO Bool
addCompletions :: CompletionEnv -> [Completion] -> IO Bool
addCompletions CompletionEnv
compl [] = Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
addCompletions CompletionEnv
compl (Completion
c:[Completion]
cs)
= do Bool
continue <- CompletionEnv -> Completion -> IO Bool
addCompletion CompletionEnv
compl Completion
c
if (Bool
continue)
then CompletionEnv -> [Completion] -> IO Bool
addCompletions CompletionEnv
compl [Completion]
cs
else Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
completeFileName :: CompletionEnv -> String -> Maybe Char -> [FilePath] -> [String] -> IO ()
completeFileName :: CompletionEnv
-> String -> Maybe Char -> [String] -> [String] -> IO ()
completeFileName (CompletionEnv Ptr IcCompletionEnv
rpc) String
prefx Maybe Char
dirSep [String]
roots [String]
extensions
= String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String String
prefx ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cprefx ->
String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 ([String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (String -> [String] -> [String]
forall a. a -> [a] -> [a]
intersperse String
";" [String]
roots)) ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
croots ->
String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 ([String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (String -> [String] -> [String]
forall a. a -> [a] -> [a]
intersperse String
";" [String]
extensions)) ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cextensions ->
do let cdirSep :: CChar
cdirSep = case Maybe Char
dirSep of
Maybe Char
Nothing -> Int -> CChar
forall a. Enum a => Int -> a
toEnum Int
0
Just Char
c -> Char -> CChar
castCharToCChar Char
c
Ptr IcCompletionEnv
-> CString -> CChar -> CString -> CString -> IO ()
ic_complete_filename Ptr IcCompletionEnv
rpc CString
cprefx CChar
cdirSep CString
croots CString
cextensions
completeWord :: CompletionEnv -> String -> Maybe (Char -> Bool) -> (String -> [Completion]) -> IO ()
completeWord :: CompletionEnv
-> String
-> Maybe (Char -> Bool)
-> (String -> [Completion])
-> IO ()
completeWord CompletionEnv
cenv String
input Maybe (Char -> Bool)
isWordChar String -> [Completion]
completer
= CompletionEnv
-> String
-> Maybe (Char -> Bool)
-> (CompletionEnv -> String -> IO ())
-> IO ()
completeWordPrim CompletionEnv
cenv String
input Maybe (Char -> Bool)
isWordChar CompletionEnv -> String -> IO ()
cenvCompleter
where
cenvCompleter :: CompletionEnv -> String -> IO ()
cenvCompleter CompletionEnv
cenv String
input
= do CompletionEnv -> [Completion] -> IO Bool
addCompletions CompletionEnv
cenv (String -> [Completion]
completer String
input)
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
completeQuotedWord :: CompletionEnv -> String -> Maybe (Char -> Bool) -> (String -> [Completion]) -> IO ()
completeQuotedWord :: CompletionEnv
-> String
-> Maybe (Char -> Bool)
-> (String -> [Completion])
-> IO ()
completeQuotedWord CompletionEnv
cenv String
input Maybe (Char -> Bool)
isWordChar String -> [Completion]
completer
= CompletionEnv
-> String
-> Maybe (Char -> Bool)
-> (CompletionEnv -> String -> IO ())
-> IO ()
completeWordPrim CompletionEnv
cenv String
input Maybe (Char -> Bool)
isWordChar CompletionEnv -> String -> IO ()
cenvCompleter
where
cenvCompleter :: CompletionEnv -> String -> IO ()
cenvCompleter CompletionEnv
cenv String
input
= do CompletionEnv -> [Completion] -> IO Bool
addCompletions CompletionEnv
cenv (String -> [Completion]
completer String
input)
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
completeQuotedWordEx :: CompletionEnv -> String -> Maybe (Char -> Bool) -> Maybe Char -> String -> (String -> [Completion]) -> IO ()
completeQuotedWordEx :: CompletionEnv
-> String
-> Maybe (Char -> Bool)
-> Maybe Char
-> String
-> (String -> [Completion])
-> IO ()
completeQuotedWordEx CompletionEnv
cenv String
input Maybe (Char -> Bool)
isWordChar Maybe Char
escapeChar String
quoteChars String -> [Completion]
completer
= CompletionEnv
-> String
-> Maybe (Char -> Bool)
-> Maybe Char
-> String
-> (CompletionEnv -> String -> IO ())
-> IO ()
completeQuotedWordPrimEx CompletionEnv
cenv String
input Maybe (Char -> Bool)
isWordChar Maybe Char
escapeChar String
quoteChars CompletionEnv -> String -> IO ()
cenvCompleter
where
cenvCompleter :: CompletionEnv -> String -> IO ()
cenvCompleter CompletionEnv
cenv String
input
= do CompletionEnv -> [Completion] -> IO Bool
addCompletions CompletionEnv
cenv (String -> [Completion]
completer String
input)
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
completeWordPrim :: CompletionEnv -> String -> Maybe (Char -> Bool) -> (CompletionEnv -> String -> IO ()) -> IO ()
completeWordPrim :: CompletionEnv
-> String
-> Maybe (Char -> Bool)
-> (CompletionEnv -> String -> IO ())
-> IO ()
completeWordPrim (CompletionEnv Ptr IcCompletionEnv
rpc) String
prefx Maybe (Char -> Bool)
isWordChar CompletionEnv -> String -> IO ()
completer
= String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String String
prefx ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cprefx ->
Maybe (Char -> Bool) -> (FunPtr CCharClassFun -> IO ()) -> IO ()
forall a.
Maybe (Char -> Bool) -> (FunPtr CCharClassFun -> IO a) -> IO a
withCharClassFun Maybe (Char -> Bool)
isWordChar ((FunPtr CCharClassFun -> IO ()) -> IO ())
-> (FunPtr CCharClassFun -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \FunPtr CCharClassFun
cisWordChar ->
Maybe (CompletionEnv -> String -> IO ())
-> (FunPtr CCompleterFun -> IO ()) -> IO ()
forall a.
Maybe (CompletionEnv -> String -> IO ())
-> (FunPtr CCompleterFun -> IO a) -> IO a
withCCompleter ((CompletionEnv -> String -> IO ())
-> Maybe (CompletionEnv -> String -> IO ())
forall a. a -> Maybe a
Just CompletionEnv -> String -> IO ()
completer) ((FunPtr CCompleterFun -> IO ()) -> IO ())
-> (FunPtr CCompleterFun -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \FunPtr CCompleterFun
ccompleter ->
do Ptr IcCompletionEnv
-> CString -> FunPtr CCompleterFun -> FunPtr CCharClassFun -> IO ()
ic_complete_word Ptr IcCompletionEnv
rpc CString
cprefx FunPtr CCompleterFun
ccompleter FunPtr CCharClassFun
cisWordChar
completeQuotedWordPrim :: CompletionEnv -> String -> Maybe (Char -> Bool) -> (CompletionEnv -> String -> IO ()) -> IO ()
completeQuotedWordPrim :: CompletionEnv
-> String
-> Maybe (Char -> Bool)
-> (CompletionEnv -> String -> IO ())
-> IO ()
completeQuotedWordPrim (CompletionEnv Ptr IcCompletionEnv
rpc) String
prefx Maybe (Char -> Bool)
isWordChar CompletionEnv -> String -> IO ()
completer
= String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String String
prefx ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cprefx ->
Maybe (Char -> Bool) -> (FunPtr CCharClassFun -> IO ()) -> IO ()
forall a.
Maybe (Char -> Bool) -> (FunPtr CCharClassFun -> IO a) -> IO a
withCharClassFun Maybe (Char -> Bool)
isWordChar ((FunPtr CCharClassFun -> IO ()) -> IO ())
-> (FunPtr CCharClassFun -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \FunPtr CCharClassFun
cisWordChar ->
Maybe (CompletionEnv -> String -> IO ())
-> (FunPtr CCompleterFun -> IO ()) -> IO ()
forall a.
Maybe (CompletionEnv -> String -> IO ())
-> (FunPtr CCompleterFun -> IO a) -> IO a
withCCompleter ((CompletionEnv -> String -> IO ())
-> Maybe (CompletionEnv -> String -> IO ())
forall a. a -> Maybe a
Just CompletionEnv -> String -> IO ()
completer) ((FunPtr CCompleterFun -> IO ()) -> IO ())
-> (FunPtr CCompleterFun -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \FunPtr CCompleterFun
ccompleter ->
do Ptr IcCompletionEnv
-> CString -> FunPtr CCompleterFun -> FunPtr CCharClassFun -> IO ()
ic_complete_qword Ptr IcCompletionEnv
rpc CString
cprefx FunPtr CCompleterFun
ccompleter FunPtr CCharClassFun
cisWordChar
completeQuotedWordPrimEx :: CompletionEnv -> String -> Maybe (Char -> Bool) -> Maybe Char -> String -> (CompletionEnv -> String -> IO ()) -> IO ()
completeQuotedWordPrimEx :: CompletionEnv
-> String
-> Maybe (Char -> Bool)
-> Maybe Char
-> String
-> (CompletionEnv -> String -> IO ())
-> IO ()
completeQuotedWordPrimEx (CompletionEnv Ptr IcCompletionEnv
rpc) String
prefx Maybe (Char -> Bool)
isWordChar Maybe Char
escapeChar String
quoteChars CompletionEnv -> String -> IO ()
completer
= String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String String
prefx ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cprefx ->
String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
quoteChars ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cquoteChars ->
Maybe (Char -> Bool) -> (FunPtr CCharClassFun -> IO ()) -> IO ()
forall a.
Maybe (Char -> Bool) -> (FunPtr CCharClassFun -> IO a) -> IO a
withCharClassFun Maybe (Char -> Bool)
isWordChar ((FunPtr CCharClassFun -> IO ()) -> IO ())
-> (FunPtr CCharClassFun -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \FunPtr CCharClassFun
cisWordChar ->
Maybe (CompletionEnv -> String -> IO ())
-> (FunPtr CCompleterFun -> IO ()) -> IO ()
forall a.
Maybe (CompletionEnv -> String -> IO ())
-> (FunPtr CCompleterFun -> IO a) -> IO a
withCCompleter ((CompletionEnv -> String -> IO ())
-> Maybe (CompletionEnv -> String -> IO ())
forall a. a -> Maybe a
Just CompletionEnv -> String -> IO ()
completer) ((FunPtr CCompleterFun -> IO ()) -> IO ())
-> (FunPtr CCompleterFun -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \FunPtr CCompleterFun
ccompleter ->
do let cescapeChar :: CChar
cescapeChar = case Maybe Char
escapeChar of
Maybe Char
Nothing -> Int -> CChar
forall a. Enum a => Int -> a
toEnum Int
0
Just Char
c -> Char -> CChar
castCharToCChar Char
c
Ptr IcCompletionEnv
-> CString
-> FunPtr CCompleterFun
-> FunPtr CCharClassFun
-> CChar
-> CString
-> IO ()
ic_complete_qword_ex Ptr IcCompletionEnv
rpc CString
cprefx FunPtr CCompleterFun
ccompleter FunPtr CCharClassFun
cisWordChar CChar
cescapeChar CString
cquoteChars
withCharClassFun :: Maybe (Char -> Bool) -> (FunPtr CCharClassFun -> IO a) -> IO a
withCharClassFun :: Maybe (Char -> Bool) -> (FunPtr CCharClassFun -> IO a) -> IO a
withCharClassFun Maybe (Char -> Bool)
isInClass FunPtr CCharClassFun -> IO a
action
= IO (FunPtr CCharClassFun)
-> (FunPtr CCharClassFun -> IO ())
-> (FunPtr CCharClassFun -> IO a)
-> IO a
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Maybe (Char -> Bool) -> IO (FunPtr CCharClassFun)
makeCharClassFun Maybe (Char -> Bool)
isInClass) (\FunPtr CCharClassFun
cfun -> Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (FunPtr CCharClassFun
forall a. FunPtr a
nullFunPtr FunPtr CCharClassFun -> FunPtr CCharClassFun -> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr CCharClassFun
cfun) (FunPtr CCharClassFun -> IO ()
forall a. FunPtr a -> IO ()
freeHaskellFunPtr FunPtr CCharClassFun
cfun)) FunPtr CCharClassFun -> IO a
action
makeCharClassFun :: Maybe (Char -> Bool) -> IO (FunPtr CCharClassFun)
makeCharClassFun :: Maybe (Char -> Bool) -> IO (FunPtr CCharClassFun)
makeCharClassFun Maybe (Char -> Bool)
Nothing = FunPtr CCharClassFun -> IO (FunPtr CCharClassFun)
forall (m :: * -> *) a. Monad m => a -> m a
return FunPtr CCharClassFun
forall a. FunPtr a
nullFunPtr
makeCharClassFun (Just Char -> Bool
isInClass)
= let charClassFun :: CString -> CLong -> IO CCBool
charClassFun :: CCharClassFun
charClassFun CString
cstr CLong
clen
= let len :: Int
len = (CLong -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CLong
clen :: Int)
in if (Int
len Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0) then CCBool -> IO CCBool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> CCBool
cbool Bool
False)
else do String
s <- CStringLen -> IO String
peekCStringLen (CString
cstr,Int
len)
CCBool -> IO CCBool
forall (m :: * -> *) a. Monad m => a -> m a
return (if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
s then (Bool -> CCBool
cbool Bool
False) else Bool -> CCBool
cbool (Char -> Bool
isInClass (String -> Char
forall a. [a] -> a
head String
s)))
in do CCharClassFun -> IO (FunPtr CCharClassFun)
ic_make_charclassfun CCharClassFun
charClassFun
stopCompleting :: CompletionEnv -> IO Bool
stopCompleting :: CompletionEnv -> IO Bool
stopCompleting (CompletionEnv Ptr IcCompletionEnv
rpc)
= IO CCBool -> IO Bool
uncbool (IO CCBool -> IO Bool) -> IO CCBool -> IO Bool
forall a b. (a -> b) -> a -> b
$ Ptr IcCompletionEnv -> IO CCBool
ic_stop_completing Ptr IcCompletionEnv
rpc
hasCompletions :: CompletionEnv -> IO Bool
hasCompletions :: CompletionEnv -> IO Bool
hasCompletions (CompletionEnv Ptr IcCompletionEnv
rpc)
= IO CCBool -> IO Bool
uncbool (IO CCBool -> IO Bool) -> IO CCBool -> IO Bool
forall a b. (a -> b) -> a -> b
$ Ptr IcCompletionEnv -> IO CCBool
ic_has_completions Ptr IcCompletionEnv
rpc
foreign import ccall ic_set_default_highlighter :: FunPtr CHighlightFun -> Ptr () -> IO ()
foreign import ccall "wrapper" ic_make_highlight_fun:: CHighlightFun -> IO (FunPtr CHighlightFun)
foreign import ccall ic_highlight :: Ptr IcHighlightEnv -> CLong -> CLong -> CString -> IO ()
foreign import ccall ic_highlight_formatted :: Ptr IcHighlightEnv -> CString -> CString -> IO ()
setDefaultHighlighter :: (HighlightEnv -> String -> IO ()) -> IO ()
setDefaultHighlighter :: (HighlightEnv -> String -> IO ()) -> IO ()
setDefaultHighlighter HighlightEnv -> String -> IO ()
highlighter
= do FunPtr CHighlightFun
chighlighter <- Maybe (HighlightEnv -> String -> IO ())
-> IO (FunPtr CHighlightFun)
makeCHighlighter ((HighlightEnv -> String -> IO ())
-> Maybe (HighlightEnv -> String -> IO ())
forall a. a -> Maybe a
Just HighlightEnv -> String -> IO ()
highlighter)
FunPtr CHighlightFun -> Ptr () -> IO ()
ic_set_default_highlighter FunPtr CHighlightFun
chighlighter Ptr ()
forall a. Ptr a
nullPtr
makeCHighlighter :: Maybe (HighlightEnv -> String -> IO ()) -> IO (FunPtr CHighlightFun)
makeCHighlighter :: Maybe (HighlightEnv -> String -> IO ())
-> IO (FunPtr CHighlightFun)
makeCHighlighter Maybe (HighlightEnv -> String -> IO ())
Nothing = FunPtr CHighlightFun -> IO (FunPtr CHighlightFun)
forall (m :: * -> *) a. Monad m => a -> m a
return FunPtr CHighlightFun
forall a. FunPtr a
nullFunPtr
makeCHighlighter (Just HighlightEnv -> String -> IO ()
highlighter)
= CHighlightFun -> IO (FunPtr CHighlightFun)
ic_make_highlight_fun CHighlightFun
wrapper
where
wrapper :: Ptr IcHighlightEnv -> CString -> Ptr () -> IO ()
wrapper :: CHighlightFun
wrapper Ptr IcHighlightEnv
henv CString
cinput Ptr ()
carg
= do String
input <- CString -> IO String
peekUTF8String0 CString
cinput
HighlightEnv -> String -> IO ()
highlighter (Ptr IcHighlightEnv -> HighlightEnv
HighlightEnv Ptr IcHighlightEnv
henv) String
input
highlight :: HighlightEnv -> Int -> Int -> String -> IO ()
highlight :: HighlightEnv -> Int -> Int -> String -> IO ()
highlight (HighlightEnv Ptr IcHighlightEnv
henv) Int
pos Int
len String
style
= String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
style ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cstyle ->
do Ptr IcHighlightEnv -> CLong -> CLong -> CString -> IO ()
ic_highlight Ptr IcHighlightEnv
henv (Int -> CLong
clong (-Int
pos)) (Int -> CLong
clong (-Int
len)) CString
cstyle
type Style = String
type Fmt = String
highlightFmt :: (String -> Fmt) -> (HighlightEnv -> String -> IO ())
highlightFmt :: (String -> String) -> HighlightEnv -> String -> IO ()
highlightFmt String -> String
highlight (HighlightEnv Ptr IcHighlightEnv
henv) String
input
= String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
input ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cinput ->
String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 (String -> String
highlight String
input) ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cfmt ->
do Ptr IcHighlightEnv -> CString -> CString -> IO ()
ic_highlight_formatted Ptr IcHighlightEnv
henv CString
cinput CString
cfmt
style :: Style -> Fmt -> Fmt
style :: String -> String -> String
style String
st String
s
= if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
st then String
s else (String
"[" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
st String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"]" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
s String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"[/]")
plain :: String -> Fmt
plain :: String -> String
plain String
s
= if ((Char -> Bool) -> String -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (\Char
c -> (Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'[' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
']')) String
s) then String
"[!pre]" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
s String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"[/pre]" else String
s
pre :: Style -> String -> Fmt
pre :: String -> String -> String
pre String
st String
s
= String -> String -> String
style String
st (String -> String
plain String
s)
setDefaultFmtHighlighter :: (String -> Fmt) -> IO ()
setDefaultFmtHighlighter :: (String -> String) -> IO ()
setDefaultFmtHighlighter String -> String
highlight
= (HighlightEnv -> String -> IO ()) -> IO ()
setDefaultHighlighter ((String -> String) -> HighlightEnv -> String -> IO ()
highlightFmt String -> String
highlight)
foreign import ccall ic_print :: CString -> IO ()
foreign import ccall ic_println :: CString -> IO ()
foreign import ccall ic_style_def :: CString -> CString -> IO ()
foreign import ccall ic_style_open :: CString -> IO ()
foreign import ccall ic_style_close :: IO ()
putFmt :: Fmt -> IO ()
putFmt :: String -> IO ()
putFmt String
s
= String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
s ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cs ->
do CString -> IO ()
ic_print CString
cs
putFmtLn :: Fmt -> IO ()
putFmtLn :: String -> IO ()
putFmtLn String
s
= String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
s ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cs ->
do CString -> IO ()
ic_println CString
cs
styleDef :: String -> Style -> IO ()
styleDef :: String -> String -> IO ()
styleDef String
name String
style
= String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
name ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cname ->
String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
style ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cstyle ->
do CString -> CString -> IO ()
ic_style_def CString
cname CString
cstyle
styleOpen :: Style -> IO ()
styleOpen :: String -> IO ()
styleOpen String
style
= String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
style ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cstyle ->
do CString -> IO ()
ic_style_open CString
cstyle
styleClose :: IO ()
styleClose :: IO ()
styleClose
= IO ()
ic_style_close
withStyle :: Style -> IO a -> IO a
withStyle :: String -> IO a -> IO a
withStyle String
style IO a
action
= IO () -> (() -> IO ()) -> (() -> IO a) -> IO a
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (String -> IO ()
styleOpen String
style) (\() -> IO ()
styleClose) (\() -> IO a
action)
foreign import ccall ic_term_init :: IO ()
foreign import ccall ic_term_done :: IO ()
foreign import ccall ic_term_flush :: IO ()
foreign import ccall ic_term_write :: CString -> IO ()
foreign import ccall ic_term_writeln :: CString -> IO ()
foreign import ccall ic_term_underline :: CCBool -> IO ()
foreign import ccall ic_term_reverse :: CCBool -> IO ()
foreign import ccall ic_term_color_ansi :: CCBool -> CInt -> IO ()
foreign import ccall ic_term_color_rgb :: CCBool -> CInt -> IO ()
foreign import ccall ic_term_style :: CString -> IO ()
foreign import ccall ic_term_reset :: IO ()
termInit :: IO ()
termInit :: IO ()
termInit
= IO ()
ic_term_init
termDone :: IO ()
termDone :: IO ()
termDone
= IO ()
ic_term_done
withTerm :: IO a -> IO a
withTerm :: IO a -> IO a
withTerm IO a
action
= IO () -> (() -> IO ()) -> (() -> IO a) -> IO a
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket IO ()
termInit (\() -> IO ()
termDone) (\() -> IO a
action)
termFlush :: IO ()
termFlush :: IO ()
termFlush
= IO ()
ic_term_flush
termWrite :: String -> IO ()
termWrite :: String -> IO ()
termWrite String
s
= String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
s ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cs -> CString -> IO ()
ic_term_write CString
cs
termWriteLn :: String -> IO ()
termWriteLn :: String -> IO ()
termWriteLn String
s
= String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
s ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cs -> CString -> IO ()
ic_term_writeln CString
cs
termColor :: Int -> IO ()
termColor :: Int -> IO ()
termColor Int
color
= CCBool -> CCBool -> IO ()
ic_term_color_rgb (Bool -> CCBool
cbool Bool
True) (Int -> CCBool
forall a. Enum a => Int -> a
toEnum Int
color)
termBgColor :: Int -> IO ()
termBgColor :: Int -> IO ()
termBgColor Int
color
= CCBool -> CCBool -> IO ()
ic_term_color_rgb (Bool -> CCBool
cbool Bool
False) (Int -> CCBool
forall a. Enum a => Int -> a
toEnum Int
color)
termColorAnsi :: Int -> IO ()
termColorAnsi :: Int -> IO ()
termColorAnsi Int
color
= CCBool -> CCBool -> IO ()
ic_term_color_ansi (Bool -> CCBool
cbool Bool
True) (Int -> CCBool
forall a. Enum a => Int -> a
toEnum Int
color)
termBgColorAnsi :: Int -> IO ()
termBgColorAnsi :: Int -> IO ()
termBgColorAnsi Int
color
= CCBool -> CCBool -> IO ()
ic_term_color_ansi (Bool -> CCBool
cbool Bool
False) (Int -> CCBool
forall a. Enum a => Int -> a
toEnum Int
color)
termStyle :: Style -> IO ()
termStyle :: String -> IO ()
termStyle String
style
= String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
style ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cstyle ->
do CString -> IO ()
ic_term_style CString
cstyle
termUnderline :: Bool -> IO ()
termUnderline :: Bool -> IO ()
termUnderline Bool
enable
= CCBool -> IO ()
ic_term_underline (Bool -> CCBool
cbool Bool
enable)
termReverse :: Bool -> IO ()
termReverse :: Bool -> IO ()
termReverse Bool
enable
= CCBool -> IO ()
ic_term_reverse (Bool -> CCBool
cbool Bool
enable)
termReset :: IO ()
termReset :: IO ()
termReset
= IO ()
ic_term_reset
foreign import ccall ic_set_prompt_marker :: CString -> CString -> IO ()
foreign import ccall ic_get_prompt_marker :: IO CString
foreign import ccall ic_get_continuation_prompt_marker :: IO CString
foreign import ccall ic_enable_multiline :: CCBool -> IO CCBool
foreign import ccall ic_enable_beep :: CCBool -> IO CCBool
foreign import ccall ic_enable_color :: CCBool -> IO CCBool
foreign import ccall ic_enable_auto_tab :: CCBool -> IO CCBool
foreign import ccall ic_enable_inline_help:: CCBool -> IO CCBool
foreign import ccall ic_enable_hint :: CCBool -> IO CCBool
foreign import ccall ic_set_hint_delay :: CLong -> IO CLong
foreign import ccall ic_enable_highlight :: CCBool -> IO CCBool
foreign import ccall ic_enable_history_duplicates :: CCBool -> IO CCBool
foreign import ccall ic_enable_completion_preview :: CCBool -> IO CCBool
foreign import ccall ic_enable_multiline_indent :: CCBool -> IO CCBool
foreign import ccall ic_enable_brace_matching :: CCBool -> IO CCBool
foreign import ccall ic_enable_brace_insertion :: CCBool -> IO CCBool
foreign import ccall ic_set_matching_braces :: CString -> IO ()
foreign import ccall ic_set_insertion_braces :: CString -> IO ()
cbool :: Bool -> CCBool
cbool :: Bool -> CCBool
cbool Bool
True = Int -> CCBool
forall a. Enum a => Int -> a
toEnum Int
1
cbool Bool
False = Int -> CCBool
forall a. Enum a => Int -> a
toEnum Int
0
uncbool :: IO CCBool -> IO Bool
uncbool :: IO CCBool -> IO Bool
uncbool IO CCBool
action
= do CCBool
i <- IO CCBool
action
Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (CCBool
i CCBool -> CCBool -> Bool
forall a. Eq a => a -> a -> Bool
/= Int -> CCBool
forall a. Enum a => Int -> a
toEnum Int
0)
clong :: Int -> CLong
clong :: Int -> CLong
clong Int
l = Int -> CLong
forall a. Enum a => Int -> a
toEnum Int
l
setPromptMarker :: String -> String -> IO ()
setPromptMarker :: String -> String -> IO ()
setPromptMarker String
marker String
multiline_marker
= String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
marker ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cmarker ->
String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
multiline_marker ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cmultiline_marker ->
do CString -> CString -> IO ()
ic_set_prompt_marker CString
cmarker CString
cmultiline_marker
getPromptMarker :: IO String
getPromptMarker :: IO String
getPromptMarker
= do CString
cstr <- IO CString
ic_get_prompt_marker
if (CString
forall a. Ptr a
nullPtr CString -> CString -> Bool
forall a. Eq a => a -> a -> Bool
== CString
cstr)
then String -> IO String
forall (m :: * -> *) a. Monad m => a -> m a
return String
""
else do CString
cstr2 <- CString -> IO CString
ic_strdup CString
cstr
CString -> IO String
peekUTF8String0 CString
cstr2
getContinuationPromptMarker :: IO String
getContinuationPromptMarker :: IO String
getContinuationPromptMarker
= do CString
cstr <- IO CString
ic_get_continuation_prompt_marker
if (CString
forall a. Ptr a
nullPtr CString -> CString -> Bool
forall a. Eq a => a -> a -> Bool
== CString
cstr)
then String -> IO String
forall (m :: * -> *) a. Monad m => a -> m a
return String
""
else do CString
cstr2 <- CString -> IO CString
ic_strdup CString
cstr
CString -> IO String
peekUTF8String0 CString
cstr2
enableMultiline :: Bool -> IO Bool
enableMultiline :: Bool -> IO Bool
enableMultiline Bool
enable
= do IO CCBool -> IO Bool
uncbool (IO CCBool -> IO Bool) -> IO CCBool -> IO Bool
forall a b. (a -> b) -> a -> b
$ CCBool -> IO CCBool
ic_enable_multiline (Bool -> CCBool
cbool Bool
enable)
enableBeep :: Bool -> IO Bool
enableBeep :: Bool -> IO Bool
enableBeep Bool
enable
= do IO CCBool -> IO Bool
uncbool (IO CCBool -> IO Bool) -> IO CCBool -> IO Bool
forall a b. (a -> b) -> a -> b
$ CCBool -> IO CCBool
ic_enable_beep (Bool -> CCBool
cbool Bool
enable)
enableColor :: Bool -> IO Bool
enableColor :: Bool -> IO Bool
enableColor Bool
enable
= do IO CCBool -> IO Bool
uncbool (IO CCBool -> IO Bool) -> IO CCBool -> IO Bool
forall a b. (a -> b) -> a -> b
$ CCBool -> IO CCBool
ic_enable_color (Bool -> CCBool
cbool Bool
enable)
enableHistoryDuplicates :: Bool -> IO Bool
enableHistoryDuplicates :: Bool -> IO Bool
enableHistoryDuplicates Bool
enable
= do IO CCBool -> IO Bool
uncbool (IO CCBool -> IO Bool) -> IO CCBool -> IO Bool
forall a b. (a -> b) -> a -> b
$ CCBool -> IO CCBool
ic_enable_history_duplicates (Bool -> CCBool
cbool Bool
enable)
enableAutoTab :: Bool -> IO Bool
enableAutoTab :: Bool -> IO Bool
enableAutoTab Bool
enable
= do IO CCBool -> IO Bool
uncbool (IO CCBool -> IO Bool) -> IO CCBool -> IO Bool
forall a b. (a -> b) -> a -> b
$ CCBool -> IO CCBool
ic_enable_auto_tab (Bool -> CCBool
cbool Bool
enable)
enableInlineHelp :: Bool -> IO Bool
enableInlineHelp :: Bool -> IO Bool
enableInlineHelp Bool
enable
= do IO CCBool -> IO Bool
uncbool (IO CCBool -> IO Bool) -> IO CCBool -> IO Bool
forall a b. (a -> b) -> a -> b
$ CCBool -> IO CCBool
ic_enable_inline_help (Bool -> CCBool
cbool Bool
enable)
enableCompletionPreview :: Bool -> IO Bool
enableCompletionPreview :: Bool -> IO Bool
enableCompletionPreview Bool
enable
= do IO CCBool -> IO Bool
uncbool (IO CCBool -> IO Bool) -> IO CCBool -> IO Bool
forall a b. (a -> b) -> a -> b
$ CCBool -> IO CCBool
ic_enable_completion_preview (Bool -> CCBool
cbool Bool
enable)
enableBraceMatching :: Bool -> IO Bool
enableBraceMatching :: Bool -> IO Bool
enableBraceMatching Bool
enable
= do IO CCBool -> IO Bool
uncbool (IO CCBool -> IO Bool) -> IO CCBool -> IO Bool
forall a b. (a -> b) -> a -> b
$ CCBool -> IO CCBool
ic_enable_brace_matching (Bool -> CCBool
cbool Bool
enable)
enableBraceInsertion :: Bool -> IO Bool
enableBraceInsertion :: Bool -> IO Bool
enableBraceInsertion Bool
enable
= do IO CCBool -> IO Bool
uncbool (IO CCBool -> IO Bool) -> IO CCBool -> IO Bool
forall a b. (a -> b) -> a -> b
$ CCBool -> IO CCBool
ic_enable_brace_insertion (Bool -> CCBool
cbool Bool
enable)
setMatchingBraces :: String -> IO ()
setMatchingBraces :: String -> IO ()
setMatchingBraces String
bracePairs
= String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
bracePairs ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cbracePairs ->
do CString -> IO ()
ic_set_matching_braces CString
cbracePairs
setInsertionBraces :: String -> IO ()
setInsertionBraces :: String -> IO ()
setInsertionBraces String
bracePairs
= String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withUTF8String0 String
bracePairs ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
cbracePairs ->
do CString -> IO ()
ic_set_insertion_braces CString
cbracePairs
enableMultilineIndent :: Bool -> IO Bool
enableMultilineIndent :: Bool -> IO Bool
enableMultilineIndent Bool
enable
= do IO CCBool -> IO Bool
uncbool (IO CCBool -> IO Bool) -> IO CCBool -> IO Bool
forall a b. (a -> b) -> a -> b
$ CCBool -> IO CCBool
ic_enable_multiline_indent (Bool -> CCBool
cbool Bool
enable)
enableHint :: Bool -> IO Bool
enableHint :: Bool -> IO Bool
enableHint Bool
enable
= do IO CCBool -> IO Bool
uncbool (IO CCBool -> IO Bool) -> IO CCBool -> IO Bool
forall a b. (a -> b) -> a -> b
$ CCBool -> IO CCBool
ic_enable_hint (Bool -> CCBool
cbool Bool
enable)
enableHighlight :: Bool -> IO Bool
enableHighlight :: Bool -> IO Bool
enableHighlight Bool
enable
= do IO CCBool -> IO Bool
uncbool (IO CCBool -> IO Bool) -> IO CCBool -> IO Bool
forall a b. (a -> b) -> a -> b
$ CCBool -> IO CCBool
ic_enable_highlight (Bool -> CCBool
cbool Bool
enable)
setHintDelay :: Int -> IO Int
setHintDelay :: Int -> IO Int
setHintDelay Int
ms
= do CLong
cl <- CLong -> IO CLong
ic_set_hint_delay (Int -> CLong
forall a. Enum a => Int -> a
toEnum Int
ms)
Int -> IO Int
forall (m :: * -> *) a. Monad m => a -> m a
return (CLong -> Int
forall a. Enum a => a -> Int
fromEnum CLong
cl)
withUTF8String0 :: String -> (CString -> IO a) -> IO a
withUTF8String0 :: String -> (CString -> IO a) -> IO a
withUTF8String0 String
s CString -> IO a
action
= if (String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
s) then CString -> IO a
action CString
forall a. Ptr a
nullPtr else String -> (CString -> IO a) -> IO a
forall a. String -> (CString -> IO a) -> IO a
withUTF8String String
s CString -> IO a
action
peekUTF8String0 :: CString -> IO String
peekUTF8String0 :: CString -> IO String
peekUTF8String0 CString
cstr
= if (CString
forall a. Ptr a
nullPtr CString -> CString -> Bool
forall a. Eq a => a -> a -> Bool
== CString
cstr) then String -> IO String
forall (m :: * -> *) a. Monad m => a -> m a
return String
"" else CString -> IO String
peekUTF8String CString
cstr
peekUTF8StringMaybe :: CString -> IO (Maybe String)
peekUTF8StringMaybe :: CString -> IO (Maybe String)
peekUTF8StringMaybe CString
cstr
= if (CString
forall a. Ptr a
nullPtr CString -> CString -> Bool
forall a. Eq a => a -> a -> Bool
== CString
cstr) then Maybe String -> IO (Maybe String)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe String
forall a. Maybe a
Nothing
else do String
s <- CString -> IO String
peekUTF8String CString
cstr
Maybe String -> IO (Maybe String)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Maybe String
forall a. a -> Maybe a
Just String
s)
peekUTF8String :: CString -> IO String
peekUTF8String :: CString -> IO String
peekUTF8String CString
cstr
= do ByteString
bstr <- CString -> IO ByteString
B.packCString CString
cstr
String -> IO String
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> String
T.unpack (OnDecodeError -> ByteString -> Text
TE.decodeUtf8With OnDecodeError
lenientDecode ByteString
bstr))
withUTF8String :: String -> (CString -> IO a) -> IO a
withUTF8String :: String -> (CString -> IO a) -> IO a
withUTF8String String
str CString -> IO a
action
= do let bstr :: ByteString
bstr = Text -> ByteString
TE.encodeUtf8 (String -> Text
T.pack String
str)
ByteString -> (CString -> IO a) -> IO a
forall a. ByteString -> (CString -> IO a) -> IO a
B.useAsCString ByteString
bstr CString -> IO a
action