on master help sign in
Make type a bit greyed out in REPL
3ff1dd3Evan Czaplicki
builder/src/Generate/Output.hs+1−1
@@ -149,7 +149,7 @@ generateReplFile summary@(Summary.Summary _ project _ _ _) graph iface name =
149 objectGraph <- organize summary graph
149 objectGraph <- organize summary graph
150
150
151 let home = Module.Canonical (Project.getName project) "Elm_Repl"
151 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
153
153
154 liftIO $ IO.writeBuilder (Paths.temp "js") $
154 liftIO $ IO.writeBuilder (Paths.temp "js") $
155 replRecovery <> "(function(){\n'use strict';" <> Functions.functions <> builder <> "}());"
155 replRecovery <> "(function(){\n'use strict';" <> Functions.functions <> builder <> "}());"
compiler/src/Generate/JavaScript.hs+12−10
@@ -68,29 +68,31 @@ addMain mode graph home _ state =
68-- GENERATE FOR REPL
68-- GENERATE FOR REPL
69
69
70
70
71−generateForRepl :: Opt.Graph -> I.Interface -> ModuleName.Canonical -> N.Name -> B.Builder
71+generateForRepl :: Bool -> Opt.Graph -> I.Interface -> ModuleName.Canonical -> N.Name -> B.Builder
72−generateForRepl (Opt.Graph _ graph _) iface home name =
72+generateForRepl ansi (Opt.Graph _ graph _) iface home name =
73 let
73 let
74 mode = Mode.dev Mode.Client
74 mode = Mode.dev Mode.Client
75 debugState = addGlobal mode graph emptyState (Opt.Global ModuleName.debug "toString")
75 debugState = addGlobal mode graph emptyState (Opt.Global ModuleName.debug "toString")
76 evalState = addGlobal mode graph debugState (Opt.Global home name)
76 evalState = addGlobal mode graph debugState (Opt.Global home name)
77 in
77 in
78− stateToBuilder evalState <> print home name (I._types iface ! name)
78+ stateToBuilder evalState <> print ansi home name (I._types iface ! name)
79
79
80
80
81−print :: ModuleName.Canonical -> N.Name -> Can.Annotation -> B.Builder
81+print :: Bool -> ModuleName.Canonical -> N.Name -> Can.Annotation -> B.Builder
82−print home name annotation =
82+print ansi home name annotation =
83 let
83 let
84 value = Name.toBuilder (Name.fromGlobal home name)
84 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")
86 tipe = Type.toDoc Type.None (Extract.fromAnnotation annotation)
86 tipe = Type.toDoc Type.None (Extract.fromAnnotation annotation)
87+ bool = if ansi then "true" else "false"
87 in
88 in
88− "var _value = " <> toString <> "(" <> value <> ");\n" <>
89+ "var _value = " <> toString <> "(" <> bool <> ", " <> value <> ");\n\
89− "var _type = " <> B.stringUtf8 (show (D.toString tipe)) <> ";\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\
90 \if (_value.length + 3 + _type.length >= 80 || _type.indexOf('\\n') >= 0) {\n\
92 \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\
92 \} else {\n\
94 \} else {\n\
93− \ console.log(_value + ' : ' + _type);\n\
95+ \ _print(' : ' + _type);\n\
94 \}\n"
96 \}\n"
95
97
96
98