From 627894eacfba83bc820d5605b2a33d59c7c7e969 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 29 Jul 2014 08:49:42 +0200 Subject: rewrite (concat $ map f xs) to (xs >>= f) --- src/Main.hs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/Main.hs') diff --git a/src/Main.hs b/src/Main.hs index f170492..6cac6fc 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -81,7 +81,7 @@ uiThread cf putState getState = forever $ do --t1 <- getCurrentTime --putStrLn $ "====> \ESC[32;1m" ++ show s ++ "\ESC[m in " ++ -- (show $ diffUTCTime t1 t0) - -- ++ ": \"\ESC[35m" ++ (concat $ map (colorize . toChar) s) + -- ++ ": \"\ESC[35m" ++ (s >>= colorize . toChar) -- ++ "\ESC[m\"" --case res of -- Left msg -> putStrLn $ " error: " ++ msg @@ -158,14 +158,13 @@ prettyError e = rec e color cc s = "\x1b[" ++ cc ++ "m" ++ s ++ "\x1b[m" rec (UnhandledInputError s) = - color "31" $ "unhandled input: <" ++ (pp "31;1" s) ++ "\x1b[;31m>" + color "31" $ "unhandled input: <" ++ (s >>= pp "31;1") ++ "\x1b[;31m>" rec (OtherError s) = color "31" $ "error: " ++ s -- TODO cc is ColorCode - pp cc = concat . map (pp1 cc) - pp1 cc c + pp cc c | isPrint c = [c] | otherwise = specialChar cc $ case c of @@ -242,7 +241,7 @@ execCommand ExecuteInputBuffer = do tell [ show s ] '!' : cmdline -> do --tell [ "spawn: " ++ cmdline ] - -- "input: <" ++ (concat $ map (reform 32) $ showBuffer b) ++ ">" ] + -- "input: <" ++ (showBuffer b >>= reform 32) ++ ">" ] -- TODO register process i <- state $ \ q -> let i = processCount q + 1 @@ -253,7 +252,7 @@ execCommand ExecuteInputBuffer = do "" -> do liftIO ringBell s -> do - tell [ "input: <" ++ (concat $ map (reform 32) s) ++ ">" ] + tell [ "input: <" ++ (s >>= reform 32) ++ ">" ] modifyBuffer (const emptyBuffer) @@ -333,11 +332,9 @@ renderInputLine m (lhs, rhs) = do InsertMode -> "> " VerbatimMode -> "\x1b[34;1m^\x1b[m " - putStr $ promptString ++ pp lhs ++ pp rhs - moveCursorLeft (length $ ppVis rhs) + putStr $ promptString ++ (lhs >>= reform') ++ (rhs >>= reform') + moveCursorLeft (length $ rhs >>= reformVis) where - pp = concat . map reform' - -- TODO unify reform and reform' reform' c = if isPrint c @@ -349,7 +346,6 @@ renderInputLine m (lhs, rhs) = do _ -> charToCode c ) ++ "\x1b[m" - ppVis = concat . map reformVis reformVis c = if isPrint c then [c] -- cgit v1.2.3