Added custom printers
This commit is contained in:
parent
62724e3f37
commit
7a92eeddac
7 changed files with 287 additions and 63 deletions
18
repl/repl.go
18
repl/repl.go
|
|
@ -1,6 +1,9 @@
|
|||
package repl
|
||||
|
||||
import (
|
||||
"io"
|
||||
"reflect"
|
||||
"slices"
|
||||
"ucl.lmika.dev/ucl"
|
||||
)
|
||||
|
||||
|
|
@ -11,16 +14,19 @@ type CommandOpt interface {
|
|||
type REPL struct {
|
||||
inst *ucl.Inst
|
||||
|
||||
commandDocs map[string]Doc
|
||||
commandDocs map[string]Doc
|
||||
typePrinters map[reflect.Type]func(w io.Writer, v any, brief bool) error
|
||||
}
|
||||
|
||||
func New(opts ...ucl.InstOption) *REPL {
|
||||
inst := ucl.New(opts...)
|
||||
|
||||
r := &REPL{
|
||||
inst: inst,
|
||||
commandDocs: make(map[string]Doc),
|
||||
commandDocs: make(map[string]Doc),
|
||||
typePrinters: make(map[reflect.Type]func(w io.Writer, v any, brief bool) error),
|
||||
}
|
||||
|
||||
instOpts := append(slices.Clone(opts), ucl.WithCustomEchoPrinter(r.echoPrinter))
|
||||
r.inst = ucl.New(instOpts...)
|
||||
|
||||
r.SetCommand("help", r.helpBuiltin, Doc{
|
||||
Brief: "displays help about a command",
|
||||
Usage: "[command]",
|
||||
|
|
@ -36,6 +42,8 @@ func New(opts ...ucl.InstOption) *REPL {
|
|||
`,
|
||||
})
|
||||
|
||||
AddTypePrinter(r, func(w io.Writer, t NoResults, concise bool) error { return nil })
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue