// Command e3bc ("Elvish-editor-enhanced bc") is a wrapper for the bc command // that uses Elvish's cli library for an enhanced CLI experience.
package main import ( ) // A highlighter for bc code. Currently this just makes all digits green. // // TODO: Highlight more syntax of bc. type highlighter struct{} func (highlighter) ( string) (ui.Text, []error) { := ui.Text{} for , := range { var ui.Styling if unicode.IsDigit() { = ui.FgGreen } = append(, ui.T(string(), )...) } return , nil } func (highlighter) () <-chan struct{} { return nil } func () { var cli.App = cli.NewApp(cli.AppSpec{ Prompt: cli.NewConstPrompt(ui.T("bc> ")), Highlighter: highlighter{}, CodeAreaBindings: tk.MapBindings{ term.K('D', ui.Ctrl): func(tk.Widget) { .CommitEOF() }, term.K(ui.Tab): func( tk.Widget) { := .(tk.CodeArea) if .CopyState().Buffer.Content != "" { // Only complete with an empty buffer return } , := mode.NewCompletion(, mode.CompletionSpec{ Replace: diag.Ranging{From: 0, To: 0}, Items: candidates(), }) if == nil { .SetAddon(, false) } }, }, GlobalBindings: tk.MapBindings{ term.K('[', ui.Ctrl): func(tk.Widget) { .SetAddon(nil, false) }, }, }) := bc.Start() defer .Quit() for { , := .ReadCode() if != nil { if != io.EOF { fmt.Println("error:", ) } break } .Exec() } }