Commit fb22bcf4 authored by Andrew Gibiansky's avatar Andrew Gibiansky

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

parent 0f6651e9
...@@ -11,7 +11,7 @@ import Prelude (last, read) ...@@ -11,7 +11,7 @@ import Prelude (last, read)
import Control.Concurrent (threadDelay) import Control.Concurrent (threadDelay)
import Control.Concurrent.Chan import Control.Concurrent.Chan
import Data.Aeson import Data.Aeson
import Data.String.Utils (strip) import Data.Text (strip)
import System.Directory import System.Directory
import System.Exit (exitSuccess) import System.Exit (exitSuccess)
import Text.Printf import Text.Printf
...@@ -19,6 +19,7 @@ import System.Posix.Signals ...@@ -19,6 +19,7 @@ import System.Posix.Signals
import qualified Data.Map as Map import qualified Data.Map as Map
-- IHaskell imports. -- IHaskell imports.
import IHaskell.Convert (convert)
import IHaskell.Eval.Completion (complete) import IHaskell.Eval.Completion (complete)
import IHaskell.Eval.Evaluate import IHaskell.Eval.Evaluate
import IHaskell.Display import IHaskell.Display
...@@ -34,7 +35,6 @@ import qualified IPython.Stdin as Stdin ...@@ -34,7 +35,6 @@ import qualified IPython.Stdin as Stdin
-- GHC API imports. -- GHC API imports.
import GHC hiding (extensions, language) import GHC hiding (extensions, language)
import Outputable (showSDoc, ppr)
-- | Compute the GHC API version number using the dist/build/autogen/cabal_macros.h -- | Compute the GHC API version number using the dist/build/autogen/cabal_macros.h
ghcVersionInts :: [Int] ghcVersionInts :: [Int]
...@@ -62,6 +62,8 @@ ihaskell :: Args -> IO () ...@@ -62,6 +62,8 @@ ihaskell :: Args -> IO ()
ihaskell (Args (ShowHelp help) _) = ihaskell (Args (ShowHelp help) _) =
putStrLn $ pack help putStrLn $ pack help
ihaskell (Args ConvertLhs args) = convert args
ihaskell (Args Console flags) = showingHelp Console flags $ do ihaskell (Args Console flags) = showingHelp Console flags $ do
ipython <- chooseIPython flags ipython <- chooseIPython flags
setupIPython ipython setupIPython ipython
...@@ -274,9 +276,9 @@ replyTo interface req@ExecuteRequest{ getCode = code } replyHeader state = do ...@@ -274,9 +276,9 @@ replyTo interface req@ExecuteRequest{ getCode = code } replyHeader state = do
header <- dupHeader replyHeader DisplayDataMessage header <- dupHeader replyHeader DisplayDataMessage
send $ PublishDisplayData header "haskell" $ map convertSvgToHtml outs 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 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 :: EvaluationResult -> IO ()
publish result = do publish result = do
...@@ -310,9 +312,9 @@ replyTo interface req@ExecuteRequest{ getCode = code } replyHeader state = do ...@@ -310,9 +312,9 @@ replyTo interface req@ExecuteRequest{ getCode = code } replyHeader state = do
let execCount = getExecutionCounter state let execCount = getExecutionCounter state
-- Let all frontends know the execution count and code that's about to run -- Let all frontends know the execution count and code that's about to run
inputHeader <- liftIO $ dupHeader replyHeader InputMessage 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. -- 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. -- Notify the frontend that we're done computing.
idleHeader <- liftIO $ dupHeader replyHeader StatusMessage idleHeader <- liftIO $ dupHeader replyHeader StatusMessage
...@@ -328,16 +330,16 @@ replyTo interface req@ExecuteRequest{ getCode = code } replyHeader state = do ...@@ -328,16 +330,16 @@ replyTo interface req@ExecuteRequest{ getCode = code } replyHeader state = do
replyTo _ req@CompleteRequest{} replyHeader state = do replyTo _ req@CompleteRequest{} replyHeader state = do
let line = Chars.unpack $ getCodeLine req let line = getCodeLine req
(matchedText, completions) <- complete line (getCursorPos 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) return (state, reply)
-- | Reply to the object_info_request message. Given an object name, return -- | Reply to the object_info_request message. Given an object name, return
-- | the associated type calculated by GHC. -- | the associated type calculated by GHC.
replyTo _ ObjectInfoRequest{objectName = oname} replyHeader state = do replyTo _ ObjectInfoRequest{objectName = oname} replyHeader state = do
docs <- info oname docs <- pack <$> info (unpack oname)
let reply = ObjectInfoReply { let reply = ObjectInfoReply {
header = replyHeader, header = replyHeader,
objectName = oname, objectName = oname,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment