From 6744136708730e4b094a34a43a79019a017c04fc Mon Sep 17 00:00:00 2001 From: adamrk Date: Sun, 28 May 2017 23:44:26 -0400 Subject: [PATCH] add printCompletions to print below the input line --- src/BC/Prompt.hs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/BC/Prompt.hs b/src/BC/Prompt.hs index c15b166..54023d9 100644 --- a/src/BC/Prompt.hs +++ b/src/BC/Prompt.hs @@ -50,11 +50,13 @@ output state out = let res = parse out in if length res == 1 && isErr (head res) then do + cleanPrompt print (head res) return state else let (ret, newstate) = eval state res - in do putStrLn $ returnStr ++ show ret + in do cleanPrompt + putStrLn $ returnStr ++ show ret return newstate @@ -76,6 +78,17 @@ printStatus state str = truncLen s = if length s > 20 then take 20 s ++ "..." else s +printCompletions :: State -> String -> IO () +printCompletions state str = + let completions = "" -- TODO: get possible completions + toPrint = "\n\x1b[32m" -- color to green + ++ replicate (length promptStr) ' ' + ++ completions + ++ "\x1b[0m\r\x1b[A" -- color to white, move to prev line + in do putStr toPrint + putStr $ concat $ replicate (length promptStr + length str) "\x1b[C" + + cleanPrompt :: IO () cleanPrompt = putStr "\x1b[2K\r" @@ -135,6 +148,9 @@ readline state = read' "" 0 '\x1b' -> do (pos, nacc, newpstate) <- readSpecialKey pos acc pstate read' nacc (clamp pos 0 (length acc)) newpstate + '\t' -> do + printCompletions state acc + read' acc pos pstate c -> if isPrint c then do