Revert "Remove MNEXT, MPREV again (sigh)"

This reverts commit b55edd2678.
This commit is contained in:
lash 2023-04-08 10:01:28 +01:00
parent b55edd2678
commit adbd790c6f
8 changed files with 92 additions and 92 deletions

View File

@ -69,10 +69,10 @@ func (mp *MenuProcessor) ToLines() []byte {
preLines = vm.NewLine(preLines, vm.MOUT, []string{v.choice, v.display}, nil, nil) preLines = vm.NewLine(preLines, vm.MOUT, []string{v.choice, v.display}, nil, nil)
postLines = vm.NewLine(postLines, vm.INCMP, []string{v.choice, "_"}, nil, nil) postLines = vm.NewLine(postLines, vm.INCMP, []string{v.choice, "_"}, nil, nil)
case MENU_NEXT: case MENU_NEXT:
preLines = vm.NewLine(preLines, vm.MOUT, []string{v.choice, v.display}, nil, nil) preLines = vm.NewLine(preLines, vm.MNEXT, []string{v.choice, v.display}, nil, nil)
postLines = vm.NewLine(postLines, vm.INCMP, []string{v.choice, ">"}, nil, nil) postLines = vm.NewLine(postLines, vm.INCMP, []string{v.choice, ">"}, nil, nil)
case MENU_PREVIOUS: case MENU_PREVIOUS:
preLines = vm.NewLine(preLines, vm.MOUT, []string{v.choice, v.display}, nil, nil) preLines = vm.NewLine(preLines, vm.MPREV, []string{v.choice, v.display}, nil, nil)
postLines = vm.NewLine(postLines, vm.INCMP, []string{v.choice, "<"}, nil, nil) postLines = vm.NewLine(postLines, vm.INCMP, []string{v.choice, "<"}, nil, nil)
default: default:
preLines = vm.NewLine(preLines, vm.MOUT, []string{v.choice, v.display}, nil, nil) preLines = vm.NewLine(preLines, vm.MOUT, []string{v.choice, v.display}, nil, nil)

View File

@ -35,8 +35,8 @@ func TestMenuInterpreter(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
expect := `MOUT 0 "inky" expect := `MOUT 0 "inky"
MOUT 1 "pinky" MNEXT 1 "pinky"
MOUT 2 "blinky clyde" MPREV 2 "blinky clyde"
MOUT 99 "tinky-winky" MOUT 99 "tinky-winky"
HALT HALT
INCMP 0 foo INCMP 0 foo

View File

@ -19,7 +19,7 @@ type Resource interface {
GetCode(sym string) ([]byte, error) // Get the bytecode for the given symbol. GetCode(sym string) ([]byte, error) // Get the bytecode for the given symbol.
PutMenu(string, string) error // Add a menu item. PutMenu(string, string) error // Add a menu item.
ShiftMenu() (string, string, error) // Remove and return the first menu item in list. ShiftMenu() (string, string, error) // Remove and return the first menu item in list.
// SetMenuBrowse(string, string, bool) error // Set menu browser display details. SetMenuBrowse(string, string, bool) error // Set menu browser display details.
RenderTemplate(sym string, values map[string]string, idx uint16, sizer *Sizer) (string, error) // Render the given data map using the template of the symbol. RenderTemplate(sym string, values map[string]string, idx uint16, sizer *Sizer) (string, error) // Render the given data map using the template of the symbol.
RenderMenu() (string, error) // Render the current state of menu RenderMenu() (string, error) // Render the current state of menu
Render(sym string, values map[string]string, idx uint16, sizer *Sizer) (string, error) // Render full output. Render(sym string, values map[string]string, idx uint16, sizer *Sizer) (string, error) // Render full output.
@ -55,20 +55,20 @@ func(m *MenuResource) WithTemplateGetter(templateGetter TemplateFunc) *MenuResou
return m return m
} }
//// SetMenuBrowse defines the how pagination menu options should be displayed. // SetMenuBrowse defines the how pagination menu options should be displayed.
//// //
//// The selector is the expected user input, and the title is the description string. // The selector is the expected user input, and the title is the description string.
//// //
//// If back is set, the option will be defined for returning to a previous page. // If back is set, the option will be defined for returning to a previous page.
//func(m *MenuResource) SetMenuBrowse(selector string, title string, back bool) error { func(m *MenuResource) SetMenuBrowse(selector string, title string, back bool) error {
// entry := [2]string{selector, title} entry := [2]string{selector, title}
// if back { if back {
// m.prev = entry m.prev = entry
// } else { } else {
// m.next = entry m.next = entry
// } }
// return nil return nil
//} }
// PutMenu adds a menu option to the menu rendering. // PutMenu adds a menu option to the menu rendering.
func(m *MenuResource) PutMenu(selector string, title string) error { func(m *MenuResource) PutMenu(selector string, title string) error {

View File

@ -129,22 +129,22 @@ func ParseAll(b []byte, w io.Writer) (int, error) {
rs = fmt.Sprintf("%s %s \"%s\"\n", s, r, v) rs = fmt.Sprintf("%s %s \"%s\"\n", s, r, v)
} }
} }
// case MNEXT: case MNEXT:
// r, v, bb, err := ParseMNext(b) r, v, bb, err := ParseMNext(b)
// b = bb b = bb
// if err == nil { if err == nil {
// if w != nil { if w != nil {
// rs = fmt.Sprintf("%s %s \"%s\"\n", s, r, v) rs = fmt.Sprintf("%s %s \"%s\"\n", s, r, v)
// } }
// } }
// case MPREV: case MPREV:
// r, v, bb, err := ParseMPrev(b) r, v, bb, err := ParseMPrev(b)
// b = bb b = bb
// if err == nil { if err == nil {
// if w != nil { if w != nil {
// rs = fmt.Sprintf("%s %s \"%s\"\n", s, r, v) rs = fmt.Sprintf("%s %s \"%s\"\n", s, r, v)
// } }
// } }
} }
if err != nil { if err != nil {
return rn, err return rn, err

View File

@ -91,25 +91,25 @@ func TestToString(t *testing.T) {
t.Fatalf("expected:\n\t%v\ngot:\n\t%v", expect, r) t.Fatalf("expected:\n\t%v\ngot:\n\t%v", expect, r)
} }
// b = NewLine(nil, MNEXT, []string{"11", "nextmenu"}, nil, nil) b = NewLine(nil, MNEXT, []string{"11", "nextmenu"}, nil, nil)
// r, err = ToString(b) r, err = ToString(b)
// if err != nil { if err != nil {
// t.Fatal(err) t.Fatal(err)
// } }
// expect = "MNEXT 11 \"nextmenu\"\n" expect = "MNEXT 11 \"nextmenu\"\n"
// if r != expect { if r != expect {
// t.Fatalf("expected:\n\t%v\ngot:\n\t%v", expect, r) t.Fatalf("expected:\n\t%v\ngot:\n\t%v", expect, r)
// } }
//
// b = NewLine(nil, MPREV, []string{"222", "previous menu item"}, nil, nil) b = NewLine(nil, MPREV, []string{"222", "previous menu item"}, nil, nil)
// r, err = ToString(b) r, err = ToString(b)
// if err != nil { if err != nil {
// t.Fatal(err) t.Fatal(err)
// } }
// expect = "MPREV 222 \"previous menu item\"\n" expect = "MPREV 222 \"previous menu item\"\n"
// if r != expect { if r != expect {
// t.Fatalf("expected:\n\t%v\ngot:\n\t%v", expect, r) t.Fatalf("expected:\n\t%v\ngot:\n\t%v", expect, r)
// } }
b = NewLine(nil, MOUT, []string{"1", "foo"}, nil, nil) b = NewLine(nil, MOUT, []string{"1", "foo"}, nil, nil)
r, err = ToString(b) r, err = ToString(b)

View File

@ -17,8 +17,8 @@ const (
INCMP = 8 INCMP = 8
MSIZE = 9 MSIZE = 9
MOUT = 10 MOUT = 10
//MNEXT = 11 MNEXT = 11
//MPREV = 12 MPREV = 12
_MAX = 12 _MAX = 12
) )
@ -35,8 +35,8 @@ var (
INCMP: "INCMP", INCMP: "INCMP",
MSIZE: "MSIZE", MSIZE: "MSIZE",
MOUT: "MOUT", MOUT: "MOUT",
//MNEXT: "MNEXT", MNEXT: "MNEXT",
//MPREV: "MPREV", MPREV: "MPREV",
} }
OpcodeIndex = map[string]Opcode { OpcodeIndex = map[string]Opcode {
@ -51,8 +51,8 @@ var (
"INCMP": INCMP, "INCMP": INCMP,
"MSIZE": MSIZE, "MSIZE": MSIZE,
"MOUT": MOUT, "MOUT": MOUT,
//"MNEXT": MNEXT, "MNEXT": MNEXT,
//"MPREV": MPREV, "MPREV": MPREV,
} }
) )

View File

@ -44,10 +44,10 @@ func Run(b []byte, st *state.State, rs resource.Resource, ctx context.Context) (
b, err = RunMSize(b, st, rs, ctx) b, err = RunMSize(b, st, rs, ctx)
case MOUT: case MOUT:
b, err = RunMOut(b, st, rs, ctx) b, err = RunMOut(b, st, rs, ctx)
// case MNEXT: case MNEXT:
// b, err = RunMNext(b, st, rs, ctx) b, err = RunMNext(b, st, rs, ctx)
// case MPREV: case MPREV:
// b, err = RunMPrev(b, st, rs, ctx) b, err = RunMPrev(b, st, rs, ctx)
case HALT: case HALT:
b, err = RunHalt(b, st, rs, ctx) b, err = RunHalt(b, st, rs, ctx)
return b, err return b, err
@ -257,25 +257,25 @@ func RunMOut(b []byte, st *state.State, rs resource.Resource, ctx context.Contex
return b, err return b, err
} }
//// RunMNext executes the MNEXT opcode // RunMNext executes the MNEXT opcode
//func RunMNext(b []byte, st *state.State, rs resource.Resource, ctx context.Context) ([]byte, error) { func RunMNext(b []byte, st *state.State, rs resource.Resource, ctx context.Context) ([]byte, error) {
// selector, display, b, err := ParseMNext(b) selector, display, b, err := ParseMNext(b)
// if err != nil { if err != nil {
// return b, err return b, err
// } }
// err = rs.SetMenuBrowse(selector, display, false) err = rs.SetMenuBrowse(selector, display, false)
// return b, err return b, err
//} }
//
//// RunMPrev executes the MPREV opcode // RunMPrev executes the MPREV opcode
//func RunMPrev(b []byte, st *state.State, rs resource.Resource, ctx context.Context) ([]byte, error) { func RunMPrev(b []byte, st *state.State, rs resource.Resource, ctx context.Context) ([]byte, error) {
// selector, display, b, err := ParseMPrev(b) selector, display, b, err := ParseMPrev(b)
// if err != nil { if err != nil {
// return b, err return b, err
// } }
// err = rs.SetMenuBrowse(selector, display, false) err = rs.SetMenuBrowse(selector, display, false)
// return b, err return b, err
//} }
// retrieve data for key // retrieve data for key
func refresh(key string, rs resource.Resource, ctx context.Context) (string, error) { func refresh(key string, rs resource.Resource, ctx context.Context) (string, error) {

View File

@ -75,15 +75,15 @@ func ParseInCmp(b []byte) (string, string, []byte, error) {
return parseTwoSym(b) return parseTwoSym(b)
} }
//// ParseMPrev parses and extracts the expected argument portion of a MPREV instruction // ParseMPrev parses and extracts the expected argument portion of a MPREV instruction
//func ParseMPrev(b []byte) (string, string, []byte, error) { func ParseMPrev(b []byte) (string, string, []byte, error) {
// return parseTwoSym(b) return parseTwoSym(b)
//} }
//
//// ParseMNext parses and extracts the expected argument portion of a MNEXT instruction // ParseMNext parses and extracts the expected argument portion of a MNEXT instruction
//func ParseMNext(b []byte) (string, string, []byte, error) { func ParseMNext(b []byte) (string, string, []byte, error) {
// return parseTwoSym(b) return parseTwoSym(b)
//} }
// ParseMSize parses and extracts the expected argument portion of a MSIZE instruction // ParseMSize parses and extracts the expected argument portion of a MSIZE instruction
func ParseMSize(b []byte) (uint32, uint32, []byte, error) { func ParseMSize(b []byte) (uint32, uint32, []byte, error) {