on master help sign in
Add "elm repl --no-colors" flag
commit19d5a769b30ec0b2fc4475985abb4cd94cd1d6c3 authorEvan Czaplicki <evancz@users.noreply.github.com> dateTue 8 May 2018, 23:38 (8 years ago) parentd2dacad
4 files changed+35−33
builder/src/Elm/Project.hs+3−3 builder/src/Generate/Output.hs+4−3 ui/terminal/src/Main.hs+1 ui/terminal/src/Repl.hs+27−27
builder/src/Elm/Project.hs+3−3
@@ -71,15 +71,15 @@ compile mode target maybeOutput docs summary@(Summary.Summary root project _ _ _
7171-- COMPILE FOR REPL
7272
7373
74−compileForRepl :: L.Localizer -> BS.ByteString -> Maybe N.Name -> Task.Task (Maybe FilePath)
75−compileForRepl localizer source maybeName =
74+compileForRepl :: Bool -> L.Localizer -> BS.ByteString -> Maybe N.Name -> Task.Task (Maybe FilePath)
75+compileForRepl noColors localizer source maybeName =
7676 do summary@(Summary.Summary root project _ _ _) <- getRoot
7777 graph <- Crawl.crawlFromSource summary source
7878 (dirty, ifaces) <- Plan.plan Nothing summary graph
7979 answers <- Compile.compile project Nothing ifaces dirty
8080 results <- Artifacts.write root answers
8181 let (Compiler.Artifacts elmi _ _) = results ! N.replModule
82− traverse (Output.generateReplFile localizer summary graph elmi) maybeName
82+ traverse (Output.generateReplFile noColors localizer summary graph elmi) maybeName
8383
8484
8585
builder/src/Generate/Output.hs+4−3
@@ -145,18 +145,19 @@ generateMonolith mode maybeOutput (Summary.Summary _ project _ _ _) graph rootNa
145145
146146
147147generateReplFile
148− :: L.Localizer
148+ :: Bool
149+ -> L.Localizer
149150 -> Summary.Summary
150151 -> Crawl.Result
151152 -> I.Interface
152153 -> N.Name
153154 -> Task.Task FilePath
154−generateReplFile localizer summary@(Summary.Summary _ project _ _ _) graph iface name =
155+generateReplFile noColors localizer summary@(Summary.Summary _ project _ _ _) graph iface name =
155156 do
156157 objectGraph <- organize summary graph
157158
158159 let home = Module.Canonical (Project.getName project) N.replModule
159− let builder = Obj.generateForRepl True localizer objectGraph iface home name
160+ let builder = Obj.generateForRepl (not noColors) localizer objectGraph iface home name
160161
161162 liftIO $ IO.writeBuilder (Paths.temp "js") $
162163 replRecovery <> "(function(){\n'use strict';" <> Functions.functions <> builder <> "}());"
ui/terminal/src/Main.hs+1
@@ -93,6 +93,7 @@ repl =
9393 replFlags =
9494 flags Repl.Flags
9595 |-- flag "interpreter" interpreter "Path to a alternate JS interpreter, like node or nodejs."
96+ |-- onOff "no-colors" "Turn off the colors in the REPL. This can help if you are having trouble reading the values. Some terminals use a custom color scheme that diverges significantly from the standard ANSI colors, so another path may be to pick a more standard color scheme."
9697 in
9798 Interface "repl" (Common summary) details example noArgs replFlags Repl.run
9899
ui/terminal/src/Repl.hs+27−27
@@ -44,22 +44,23 @@ import qualified Reporting.Render.Type.Localizer as L
4444data Flags =
4545 Flags
4646 { _interpreter :: Maybe FilePath
47+ , _noColors :: Bool
4748 }
4849
4950
5051run :: () -> Flags -> IO ()
51−run () (Flags maybeAlternateInterpreter) =
52+run () (Flags maybeAlternateInterpreter noColors) =
5253 do interpreter <- getInterpreter maybeAlternateInterpreter
5354 _ <- Project.getRootWithReplFallback
5455 printWelcomeMessage
5556 settings <- initSettings
5657 let manager = Repl.runInputT settings (Repl.withInterrupt loop)
57− (exitCode,_,_) <- RWS.runRWST manager interpreter initialState
58+ (exitCode,_,_) <- RWS.runRWST manager (interpreter, noColors) initialState
5859 Exit.exitWith exitCode
5960
6061
6162type Runner =
62− RWS.RWST FilePath () State IO
63+ RWS.RWST (FilePath, Bool) () State IO
6364
6465
6566
@@ -155,7 +156,8 @@ data Output = None | Def N.Name | Expr Text.Text
155156
156157interpret :: Output -> State -> Runner (Maybe a)
157158interpret def state =
158− do result <- liftIO $ Task.try Repl.reporter $ compile def state
159+ do noColors <- RWS.asks snd
160+ result <- liftIO $ Task.try Repl.reporter $ compile noColors def state
159161
160162 case result of
161163 Nothing ->
@@ -170,7 +172,7 @@ interpret def state =
170172
171173interpretHelp :: FilePath -> Runner ()
172174interpretHelp path =
173− do interpreter <- RWS.ask
175+ do interpreter <- RWS.asks fst
174176 let proc = (Proc.proc interpreter [path]) { Proc.std_in = Proc.CreatePipe }
175177 liftIO $ Proc.withCreateProcess proc $ \_ _ _ handle ->
176178 do _ <- Proc.waitForProcess handle
@@ -231,8 +233,8 @@ initialState =
231233 State 0 Map.empty Map.empty Map.empty [] L.replEmpty
232234
233235
234−compile :: Output -> State -> Task.Task (Maybe FilePath)
235−compile output (State count imports types defs tricks localizer) =
236+compile :: Bool -> Output -> State -> Task.Task (Maybe FilePath)
237+compile noColors output (State count imports types defs tricks localizer) =
236238 let
237239 header =
238240 "module " <> N.toBuilder N.replModule <> " exposing (..)\n\n"
@@ -241,24 +243,27 @@ compile output (State count imports types defs tricks localizer) =
241243 (<>) header $
242244 addLines imports $ addLines types $ addLines defs $
243245 List.foldr (<>) mempty (map Text.encodeUtf8Builder tricks)
246+
247+ compileForRepl builder maybeName =
248+ Project.compileForRepl noColors localizer (LBS.toStrict (B.toLazyByteString builder)) maybeName
244249 in
245− case output of
246− None ->
247− if Map.null types && Map.null defs && null tricks then
248− evaluate localizer (elmSourceCode <> "unit = ()") Nothing
249− else
250− evaluate localizer elmSourceCode Nothing
250+ case output of
251+ None ->
252+ if Map.null types && Map.null defs && null tricks then
253+ compileForRepl (elmSourceCode <> "unit = ()") Nothing
254+ else
255+ compileForRepl elmSourceCode Nothing
251256
252− Def name ->
253− evaluate localizer elmSourceCode (Just name)
257+ Def name ->
258+ compileForRepl elmSourceCode (Just name)
254259
255− Expr expr ->
256− let
257− name = N.addIndex "repl_value_" count
258− text = Text.replace "\n" "\n " expr
259− def = N.toBuilder name <> " =\n " <> Text.encodeUtf8Builder text <> "\n"
260− in
261− evaluate localizer (elmSourceCode <> def) (Just name)
260+ Expr expr ->
261+ let
262+ name = N.addIndex "repl_value_" count
263+ text = Text.replace "\n" "\n " expr
264+ def = N.toBuilder name <> " =\n " <> Text.encodeUtf8Builder text <> "\n"
265+ in
266+ compileForRepl (elmSourceCode <> def) (Just name)
262267
263268
264269addLines :: Map.Map N.Name Text.Text -> B.Builder -> B.Builder
@@ -266,11 +271,6 @@ addLines dict builder =
266271 Map.foldr (\text b -> Text.encodeUtf8Builder text <> "\n" <> b) builder dict
267272
268273
269−evaluate :: L.Localizer -> B.Builder -> Maybe N.Name -> Task.Task (Maybe FilePath)
270−evaluate localizer builder maybeName =
271− Project.compileForRepl localizer (LBS.toStrict (B.toLazyByteString builder)) maybeName
272−
273−
274274
275275-- SETTINGS
276276