Fixed text/bytestring handling in Main, as per @aavogt's PR

This commit is contained in:
Andrew Gibiansky 2014-03-09 13:21:26 -07:00
parent 0f6651e987
commit fb22bcf468

View File

@ -11,7 +11,7 @@ import Prelude (last, read)
import Control.Concurrent (threadDelay)
import Control.Concurrent.Chan
import Data.Aeson
import Data.String.Utils (strip)
import Data.Text (strip)
import System.Directory
import System.Exit (exitSuccess)
import Text.Printf
@ -19,6 +19,7 @@ import System.Posix.Signals
import qualified Data.Map as Map
-- IHaskell imports.
import IHaskell.Convert (convert)
import IHaskell.Eval.Completion (complete)
import IHaskell.Eval.Evaluate
import IHaskell.Display
@ -34,7 +35,6 @@ import qualified IPython.Stdin as Stdin
-- GHC API imports.
import GHC hiding (extensions, language)
import Outputable (showSDoc, ppr)
-- | Compute the GHC API version number using the dist/build/autogen/cabal_macros.h
ghcVersionInts :: [Int]
@ -62,6 +62,8 @@ ihaskell :: Args -> IO ()
ihaskell (Args (ShowHelp help) _) =
putStrLn $ pack help
ihaskell (Args ConvertLhs args) = convert args
ihaskell (Args Console flags) = showingHelp Console flags $ do
ipython <- chooseIPython flags
setupIPython ipython
@ -274,9 +276,9 @@ replyTo interface req@ExecuteRequest{ getCode = code } replyHeader state = do
header <- dupHeader replyHeader DisplayDataMessage
send $ PublishDisplayData header "haskell" $ map convertSvgToHtml outs
convertSvgToHtml (DisplayData MimeSvg svg) = html $ makeSvgImg $ base64 svg
convertSvgToHtml (DisplayData MimeSvg svg) = html $ makeSvgImg $ base64 $ encodeUtf8 svg
convertSvgToHtml x = x
makeSvgImg base64data = Chars.unpack $ "<img src=\"data:image/svg+xml;base64," ++ base64data ++ "\"/>"
makeSvgImg base64data = unpack $ "<img src=\"data:image/svg+xml;base64," ++ base64data ++ "\"/>"
publish :: EvaluationResult -> IO ()
publish result = do
@ -310,9 +312,9 @@ replyTo interface req@ExecuteRequest{ getCode = code } replyHeader state = do
let execCount = getExecutionCounter state
-- Let all frontends know the execution count and code that's about to run
inputHeader <- liftIO $ dupHeader replyHeader InputMessage
send $ PublishInput inputHeader (Chars.unpack code) execCount
send $ PublishInput inputHeader (unpack code) execCount
-- Run code and publish to the frontend as we go.
updatedState <- evaluate state (Chars.unpack code) publish
updatedState <- evaluate state (unpack code) publish
-- Notify the frontend that we're done computing.
idleHeader <- liftIO $ dupHeader replyHeader StatusMessage
@ -328,16 +330,16 @@ replyTo interface req@ExecuteRequest{ getCode = code } replyHeader state = do
replyTo _ req@CompleteRequest{} replyHeader state = do
let line = Chars.unpack $ getCodeLine req
(matchedText, completions) <- complete line (getCursorPos req)
let line = getCodeLine req
(matchedText, completions) <- complete (unpack line) (getCursorPos req)
let reply = CompleteReply replyHeader completions matchedText line True
let reply = CompleteReply replyHeader (map pack completions) (pack matchedText) line True
return (state, reply)
-- | Reply to the object_info_request message. Given an object name, return
-- | the associated type calculated by GHC.
replyTo _ ObjectInfoRequest{objectName = oname} replyHeader state = do
docs <- info oname
docs <- pack <$> info (unpack oname)
let reply = ObjectInfoReply {
header = replyHeader,
objectName = oname,