Write root menu to writer (not stdout) in engine loop
This commit is contained in:
parent
12d2b577f0
commit
91ee0568ca
@ -2,7 +2,7 @@ package engine
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
// "bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -16,9 +16,11 @@ func Loop(en *Engine, startSym string, ctx context.Context, reader io.Reader, wr
|
|||||||
return fmt.Errorf("cannot init: %v\n", err)
|
return fmt.Errorf("cannot init: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
b := bytes.NewBuffer(nil)
|
//b := bytes.NewBuffer(nil)
|
||||||
en.WriteResult(b, ctx)
|
//en.WriteResult(b, ctx)
|
||||||
fmt.Println(b.String())
|
en.WriteResult(writer, ctx)
|
||||||
|
writer.Write([]byte{0x0a})
|
||||||
|
//fmt.Println(b.String())
|
||||||
|
|
||||||
running := true
|
running := true
|
||||||
bufReader := bufio.NewReader(reader)
|
bufReader := bufio.NewReader(reader)
|
||||||
@ -36,12 +38,12 @@ func Loop(en *Engine, startSym string, ctx context.Context, reader io.Reader, wr
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unexpected termination: %v\n", err)
|
return fmt.Errorf("unexpected termination: %v\n", err)
|
||||||
}
|
}
|
||||||
//b := bytes.NewBuffer(nil)
|
|
||||||
err = en.WriteResult(writer, ctx)
|
err = en.WriteResult(writer, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
writer.Write([]byte{0x0a})
|
writer.Write([]byte{0x0a})
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,39 @@ import (
|
|||||||
"git.defalsify.org/festive/state"
|
"git.defalsify.org/festive/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestLoopTop(t *testing.T) {
|
||||||
|
generateTestData(t)
|
||||||
|
ctx := context.TODO()
|
||||||
|
st := state.NewState(0)
|
||||||
|
rs := resource.NewFsResource(dataDir)
|
||||||
|
ca := cache.NewCache().WithCacheSize(1024)
|
||||||
|
|
||||||
|
en := NewEngine(Config{}, &st, &rs, ca)
|
||||||
|
err := en.Init("root", ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
input := []string{
|
||||||
|
"2",
|
||||||
|
"j",
|
||||||
|
"1",
|
||||||
|
}
|
||||||
|
inputStr := strings.Join(input, "\n")
|
||||||
|
inputBuf := bytes.NewBuffer(append([]byte(inputStr), 0x0a))
|
||||||
|
outputBuf := bytes.NewBuffer(nil)
|
||||||
|
log.Printf("running with input: %s", inputBuf.Bytes())
|
||||||
|
|
||||||
|
err = Loop(&en, "root", ctx, inputBuf, outputBuf)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
location, _ := st.Where()
|
||||||
|
if location != "foo" {
|
||||||
|
fmt.Errorf("expected location 'foo', got %s", location)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestLoopBackForth(t *testing.T) {
|
func TestLoopBackForth(t *testing.T) {
|
||||||
generateTestData(t)
|
generateTestData(t)
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
|
@ -60,11 +60,9 @@ func(pg *Page) Usage() (uint32, uint32, error) {
|
|||||||
}
|
}
|
||||||
r := uint32(l)
|
r := uint32(l)
|
||||||
rsv := uint32(c)-r
|
rsv := uint32(c)-r
|
||||||
log.Printf("size before %v %v", r, c)
|
|
||||||
if pg.menu != nil {
|
if pg.menu != nil {
|
||||||
r += uint32(pg.menu.ReservedSize())
|
r += uint32(pg.menu.ReservedSize())
|
||||||
}
|
}
|
||||||
log.Printf("size after %v %v", r, c)
|
|
||||||
return r, rsv, nil
|
return r, rsv, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,6 +147,7 @@ func(pg *Page) RenderTemplate(sym string, values map[string]string, idx uint16)
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
b := bytes.NewBuffer([]byte{})
|
b := bytes.NewBuffer([]byte{})
|
||||||
err = tp.Execute(b, values)
|
err = tp.Execute(b, values)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user