on master help sign in
Make type a bit greyed out in REPL
commit3ff1dd32030a80a8c918280b3c44c678267c4766 authorEvan Czaplicki <evancz@users.noreply.github.com> dateTue 17 Apr 2018, 10:27 (9 years ago) parentf3bb610
2 files changed+13−11
builder/src/Generate/Output.hs+1−1 compiler/src/Generate/JavaScript.hs+12−10
builder/src/Generate/Output.hs+1−1
@@ -149,7 +149,7 @@ generateReplFile summary@(Summary.Summary _ project _ _ _) graph iface name =
149149 objectGraph <- organize summary graph
150150
151151 let home = Module.Canonical (Project.getName project) "Elm_Repl"
152− let builder = Obj.generateForRepl objectGraph iface home name
152+ let builder = Obj.generateForRepl True objectGraph iface home name
153153
154154 liftIO $ IO.writeBuilder (Paths.temp "js") $
155155 replRecovery <> "(function(){\n'use strict';" <> Functions.functions <> builder <> "}());"
compiler/src/Generate/JavaScript.hs+12−10
@@ -68,29 +68,31 @@ addMain mode graph home _ state =
6868-- GENERATE FOR REPL
6969
7070
71−generateForRepl :: Opt.Graph -> I.Interface -> ModuleName.Canonical -> N.Name -> B.Builder
72−generateForRepl (Opt.Graph _ graph _) iface home name =
71+generateForRepl :: Bool -> Opt.Graph -> I.Interface -> ModuleName.Canonical -> N.Name -> B.Builder
72+generateForRepl ansi (Opt.Graph _ graph _) iface home name =
7373 let
7474 mode = Mode.dev Mode.Client
7575 debugState = addGlobal mode graph emptyState (Opt.Global ModuleName.debug "toString")
7676 evalState = addGlobal mode graph debugState (Opt.Global home name)
7777 in
78− stateToBuilder evalState <> print home name (I._types iface ! name)
78+ stateToBuilder evalState <> print ansi home name (I._types iface ! name)
7979
8080
81−print :: ModuleName.Canonical -> N.Name -> Can.Annotation -> B.Builder
82−print home name annotation =
81+print :: Bool -> ModuleName.Canonical -> N.Name -> Can.Annotation -> B.Builder
82+print ansi home name annotation =
8383 let
8484 value = Name.toBuilder (Name.fromGlobal home name)
85− toString = Name.toBuilder (Name.fromKernel N.debug "toString")
85+ toString = Name.toBuilder (Name.fromKernel N.debug "toAnsiString")
8686 tipe = Type.toDoc Type.None (Extract.fromAnnotation annotation)
87+ bool = if ansi then "true" else "false"
8788 in
88− "var _value = " <> toString <> "(" <> value <> ");\n" <>
89− "var _type = " <> B.stringUtf8 (show (D.toString tipe)) <> ";\n\
89+ "var _value = " <> toString <> "(" <> bool <> ", " <> value <> ");\n\
90+ \var _type = " <> B.stringUtf8 (show (D.toString tipe)) <> ";\n\
91+ \function _print(t) { console.log(_value + (" <> bool <> " ? '\x1b[90m' + t + '\x1b[0m' : t)); }\n\
9092 \if (_value.length + 3 + _type.length >= 80 || _type.indexOf('\\n') >= 0) {\n\
91− \ console.log(_value + '\\n : ' + _type.split('\\n').join('\\n '));\n\
93+ \ _print('\\n : ' + _type.split('\\n').join('\\n '));\n\
9294 \} else {\n\
93− \ console.log(_value + ' : ' + _type);\n\
95+ \ _print(' : ' + _type);\n\
9496 \}\n"
9597
9698