@@ -29,6 +29,7 @@ type REPL struct {
2929 prompt string
3030 rl * readline.Instance
3131 logger * diaglog.Logger
32+ c colorPalette
3233}
3334
3435// SetLogger sets the diagnostics logger for the REPL and its executor.
@@ -41,11 +42,13 @@ func (r *REPL) SetLogger(l *diaglog.Logger) {
4142func New (input io.Reader , output io.Writer ) * REPL {
4243 exec := executor .New (output )
4344 exec .SetBackendFactory (func () backend.FullBackend { return mprbackend .New () })
45+ c := newColorPalette ()
4446 return & REPL {
4547 executor : exec ,
4648 input : input ,
4749 output : output ,
4850 prompt : "mdl> " ,
51+ c : c ,
4952 }
5053}
5154
@@ -80,7 +83,7 @@ func (r *REPL) Run() error {
8083 if errors .Is (err , executor .ErrExit ) {
8184 return nil
8285 }
83- fmt .Fprintf (r .output , "Error: %v \n " , err )
86+ fmt .Fprintf (r .output , "%s \n " , r . c . Red ( "Error: " + err . Error ()) )
8487 }
8588 buffer .Reset ()
8689 }
@@ -92,7 +95,7 @@ func (r *REPL) Run() error {
9295 if strings .TrimSpace (input ) != "" {
9396 err := r .execute (input )
9497 if err != nil && ! errors .Is (err , executor .ErrExit ) {
95- fmt .Fprintf (r .output , "Error: %v \n " , err )
98+ fmt .Fprintf (r .output , "%s \n " , r . c . Red ( "Error: " + err . Error ()) )
9699 }
97100 }
98101 }
@@ -130,17 +133,17 @@ func (r *REPL) RunWithReadline() error {
130133
131134 var buffer strings.Builder
132135
133- fmt .Fprintln (r .output , "MDL REPL - Mendix Definition Language" )
134- fmt .Fprintln (r .output , "Type 'help' or '?' for commands, 'exit' or 'quit' to quit" )
135- fmt .Fprintln (r .output , "Tab: autocomplete, ↑↓: history, Ctrl+R: search history" )
136+ fmt .Fprintln (r .output , r . c . Bold ( "MDL REPL" ) + " — Mendix Definition Language" )
137+ fmt .Fprintln (r .output , r . c . Gray ( "Type 'help' or '?' for commands, 'exit' or 'quit' to quit" ) )
138+ fmt .Fprintln (r .output , r . c . Gray ( "Tab: autocomplete, ↑↓: history, Ctrl+R: search history" ) )
136139 fmt .Fprintln (r .output )
137140
138141 for {
139142 // Set prompt based on whether we're continuing a multi-line statement
140143 if buffer .Len () == 0 {
141- rl .SetPrompt (r .prompt )
144+ rl .SetPrompt (r .c . PromptPrimary ( r . prompt ) )
142145 } else {
143- rl .SetPrompt ("...> " )
146+ rl .SetPrompt (r . c . PromptContinue ( "...> " ) )
144147 }
145148
146149 // Read line with readline (supports history, arrow keys, etc.)
@@ -189,7 +192,7 @@ func (r *REPL) RunWithReadline() error {
189192 fmt .Fprintln (r .output , "Goodbye!" )
190193 return nil
191194 }
192- fmt .Fprintf (r .output , "Error: %v \n " , err )
195+ fmt .Fprintf (r .output , "%s \n " , r . c . Red ( "Error: " + err . Error ()) )
193196 }
194197 buffer .Reset ()
195198 }
@@ -218,7 +221,7 @@ func (r *REPL) execute(input string) error {
218221 prog , errs := visitor .Build (input )
219222 if len (errs ) > 0 {
220223 for _ , err := range errs {
221- fmt .Fprintf (r .output , "Parse error: %v \n " , err )
224+ fmt .Fprintf (r .output , "%s \n " , r . c . Red ( "Parse error: " + err . Error ()) )
222225 }
223226 r .logger .ParseError (input , errs )
224227 return nil // Don't return error, just print and continue
0 commit comments