abstract the output of the last few places I missed
This commit is contained in:
parent
6efa404712
commit
06ad13dd28
21
builtins.go
21
builtins.go
@ -321,20 +321,26 @@ func (b *Builtins) Rot(s *Stack) func() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Words outputs a list of all known words in the dictionary
|
// Words outputs a list of all known words in the dictionary
|
||||||
func (b *Builtins) Words(d Dictionary) func() error {
|
func (b *Builtins) Words(out io.Writer, d Dictionary) func() error {
|
||||||
|
if out == nil {
|
||||||
|
out = os.Stdout
|
||||||
|
}
|
||||||
return func() error {
|
return func() error {
|
||||||
for n := range d {
|
for n := range d {
|
||||||
fmt.Printf("%s ", n)
|
fmt.Fprintf(out, "%s ", n)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flags outputs a list of all flags
|
// Flags outputs a list of all flags
|
||||||
func (b *Builtins) Flags(c Context) func() error {
|
func (b *Builtins) Flags(out io.Writer, c Context) func() error {
|
||||||
|
if out == nil {
|
||||||
|
out = os.Stdout
|
||||||
|
}
|
||||||
return func() error {
|
return func() error {
|
||||||
for n := range c.Flags {
|
for n := range c.Flags {
|
||||||
fmt.Printf("%s %v\n", n, c.Flags.GetFlag(n))
|
fmt.Fprintf(out, "%s %v\n", n, c.Flags.GetFlag(n))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -529,9 +535,12 @@ func (b *Builtins) Quit() func() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Debug prints the stack without modifying it
|
// Debug prints the stack without modifying it
|
||||||
func (b *Builtins) Debug(s *Stack) func() error {
|
func (b *Builtins) Debug(out io.Writer, s *Stack) func() error {
|
||||||
|
if out == nil {
|
||||||
|
out = os.Stdout
|
||||||
|
}
|
||||||
return func() error {
|
return func() error {
|
||||||
fmt.Print(s.values, " ")
|
fmt.Fprint(out, s.values, " ")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
main.go
10
main.go
@ -60,11 +60,11 @@ func main() {
|
|||||||
dict.AddWord("DROP", Word{Name: "DROP", Impl: b.Drop(&stack)})
|
dict.AddWord("DROP", Word{Name: "DROP", Impl: b.Drop(&stack)})
|
||||||
dict.AddWord("ROT", Word{Name: "ROT", Impl: b.Rot(&stack)})
|
dict.AddWord("ROT", Word{Name: "ROT", Impl: b.Rot(&stack)})
|
||||||
// debugging
|
// debugging
|
||||||
dict.AddWord("WORDS", Word{Name: "WORDS", Impl: b.Words(dict)})
|
dict.AddWord("WORDS", Word{Name: "WORDS", Impl: b.Words(os.Stdout, dict)})
|
||||||
dict.AddWord("FLAGS", Word{Name: "FLAGS", Impl: b.Flags(c)})
|
dict.AddWord("FLAGS", Word{Name: "FLAGS", Impl: b.Flags(os.Stdout, c)})
|
||||||
dict.AddWord(".S", Word{Name: ".S", Impl: b.Debug(&stack)})
|
dict.AddWord(".S", Word{Name: ".S", Impl: b.Debug(os.Stdout, &stack)})
|
||||||
dict.AddWord(".R", Word{Name: ".R", Impl: b.Debug(&rstack)})
|
dict.AddWord(".R", Word{Name: ".R", Impl: b.Debug(os.Stdout, &rstack)})
|
||||||
dict.AddWord(".I", Word{Name: ".I", Impl: b.Debug(&ifstack)})
|
dict.AddWord(".I", Word{Name: ".I", Impl: b.Debug(os.Stdout, &ifstack)})
|
||||||
dict.AddWord("R>", Word{Name: "R>", Impl: b.RFrom(&stack, &rstack)})
|
dict.AddWord("R>", Word{Name: "R>", Impl: b.RFrom(&stack, &rstack)})
|
||||||
dict.AddWord(">R", Word{Name: ">R", Impl: b.ToR(&stack, &rstack)})
|
dict.AddWord(">R", Word{Name: ">R", Impl: b.ToR(&stack, &rstack)})
|
||||||
dict.AddWord("R@", Word{Name: "R@", Impl: b.RFetch(&stack, &rstack)})
|
dict.AddWord("R@", Word{Name: "R@", Impl: b.RFetch(&stack, &rstack)})
|
||||||
|
Loading…
Reference in New Issue
Block a user