Revert "Remove MNEXT, MPREV again (sigh)"
This reverts commit b55edd2678
.
This commit is contained in:
parent
b55edd2678
commit
adbd790c6f
@ -69,10 +69,10 @@ func (mp *MenuProcessor) ToLines() []byte {
|
||||
preLines = vm.NewLine(preLines, vm.MOUT, []string{v.choice, v.display}, nil, nil)
|
||||
postLines = vm.NewLine(postLines, vm.INCMP, []string{v.choice, "_"}, nil, nil)
|
||||
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)
|
||||
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)
|
||||
default:
|
||||
preLines = vm.NewLine(preLines, vm.MOUT, []string{v.choice, v.display}, nil, nil)
|
||||
|
@ -35,8 +35,8 @@ func TestMenuInterpreter(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expect := `MOUT 0 "inky"
|
||||
MOUT 1 "pinky"
|
||||
MOUT 2 "blinky clyde"
|
||||
MNEXT 1 "pinky"
|
||||
MPREV 2 "blinky clyde"
|
||||
MOUT 99 "tinky-winky"
|
||||
HALT
|
||||
INCMP 0 foo
|
||||
|
@ -19,7 +19,7 @@ type Resource interface {
|
||||
GetCode(sym string) ([]byte, error) // Get the bytecode for the given symbol.
|
||||
PutMenu(string, string) error // Add a menu item.
|
||||
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.
|
||||
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.
|
||||
@ -55,20 +55,20 @@ func(m *MenuResource) WithTemplateGetter(templateGetter TemplateFunc) *MenuResou
|
||||
return m
|
||||
}
|
||||
|
||||
//// SetMenuBrowse defines the how pagination menu options should be displayed.
|
||||
////
|
||||
//// 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.
|
||||
//func(m *MenuResource) SetMenuBrowse(selector string, title string, back bool) error {
|
||||
// entry := [2]string{selector, title}
|
||||
// if back {
|
||||
// m.prev = entry
|
||||
// } else {
|
||||
// m.next = entry
|
||||
// }
|
||||
// return nil
|
||||
//}
|
||||
// SetMenuBrowse defines the how pagination menu options should be displayed.
|
||||
//
|
||||
// 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.
|
||||
func(m *MenuResource) SetMenuBrowse(selector string, title string, back bool) error {
|
||||
entry := [2]string{selector, title}
|
||||
if back {
|
||||
m.prev = entry
|
||||
} else {
|
||||
m.next = entry
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PutMenu adds a menu option to the menu rendering.
|
||||
func(m *MenuResource) PutMenu(selector string, title string) error {
|
||||
|
@ -129,22 +129,22 @@ func ParseAll(b []byte, w io.Writer) (int, error) {
|
||||
rs = fmt.Sprintf("%s %s \"%s\"\n", s, r, v)
|
||||
}
|
||||
}
|
||||
// case MNEXT:
|
||||
// r, v, bb, err := ParseMNext(b)
|
||||
// b = bb
|
||||
// if err == nil {
|
||||
// if w != nil {
|
||||
// rs = fmt.Sprintf("%s %s \"%s\"\n", s, r, v)
|
||||
// }
|
||||
// }
|
||||
// case MPREV:
|
||||
// r, v, bb, err := ParseMPrev(b)
|
||||
// b = bb
|
||||
// if err == nil {
|
||||
// if w != nil {
|
||||
// rs = fmt.Sprintf("%s %s \"%s\"\n", s, r, v)
|
||||
// }
|
||||
// }
|
||||
case MNEXT:
|
||||
r, v, bb, err := ParseMNext(b)
|
||||
b = bb
|
||||
if err == nil {
|
||||
if w != nil {
|
||||
rs = fmt.Sprintf("%s %s \"%s\"\n", s, r, v)
|
||||
}
|
||||
}
|
||||
case MPREV:
|
||||
r, v, bb, err := ParseMPrev(b)
|
||||
b = bb
|
||||
if err == nil {
|
||||
if w != nil {
|
||||
rs = fmt.Sprintf("%s %s \"%s\"\n", s, r, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return rn, err
|
||||
|
@ -91,25 +91,25 @@ func TestToString(t *testing.T) {
|
||||
t.Fatalf("expected:\n\t%v\ngot:\n\t%v", expect, r)
|
||||
}
|
||||
|
||||
// b = NewLine(nil, MNEXT, []string{"11", "nextmenu"}, nil, nil)
|
||||
// r, err = ToString(b)
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// expect = "MNEXT 11 \"nextmenu\"\n"
|
||||
// if r != expect {
|
||||
// t.Fatalf("expected:\n\t%v\ngot:\n\t%v", expect, r)
|
||||
// }
|
||||
//
|
||||
// b = NewLine(nil, MPREV, []string{"222", "previous menu item"}, nil, nil)
|
||||
// r, err = ToString(b)
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// expect = "MPREV 222 \"previous menu item\"\n"
|
||||
// if r != expect {
|
||||
// t.Fatalf("expected:\n\t%v\ngot:\n\t%v", expect, r)
|
||||
// }
|
||||
b = NewLine(nil, MNEXT, []string{"11", "nextmenu"}, nil, nil)
|
||||
r, err = ToString(b)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expect = "MNEXT 11 \"nextmenu\"\n"
|
||||
if r != expect {
|
||||
t.Fatalf("expected:\n\t%v\ngot:\n\t%v", expect, r)
|
||||
}
|
||||
|
||||
b = NewLine(nil, MPREV, []string{"222", "previous menu item"}, nil, nil)
|
||||
r, err = ToString(b)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expect = "MPREV 222 \"previous menu item\"\n"
|
||||
if r != expect {
|
||||
t.Fatalf("expected:\n\t%v\ngot:\n\t%v", expect, r)
|
||||
}
|
||||
|
||||
b = NewLine(nil, MOUT, []string{"1", "foo"}, nil, nil)
|
||||
r, err = ToString(b)
|
||||
|
@ -17,8 +17,8 @@ const (
|
||||
INCMP = 8
|
||||
MSIZE = 9
|
||||
MOUT = 10
|
||||
//MNEXT = 11
|
||||
//MPREV = 12
|
||||
MNEXT = 11
|
||||
MPREV = 12
|
||||
_MAX = 12
|
||||
)
|
||||
|
||||
@ -35,8 +35,8 @@ var (
|
||||
INCMP: "INCMP",
|
||||
MSIZE: "MSIZE",
|
||||
MOUT: "MOUT",
|
||||
//MNEXT: "MNEXT",
|
||||
//MPREV: "MPREV",
|
||||
MNEXT: "MNEXT",
|
||||
MPREV: "MPREV",
|
||||
}
|
||||
|
||||
OpcodeIndex = map[string]Opcode {
|
||||
@ -51,8 +51,8 @@ var (
|
||||
"INCMP": INCMP,
|
||||
"MSIZE": MSIZE,
|
||||
"MOUT": MOUT,
|
||||
//"MNEXT": MNEXT,
|
||||
//"MPREV": MPREV,
|
||||
"MNEXT": MNEXT,
|
||||
"MPREV": MPREV,
|
||||
}
|
||||
|
||||
)
|
||||
|
@ -44,10 +44,10 @@ func Run(b []byte, st *state.State, rs resource.Resource, ctx context.Context) (
|
||||
b, err = RunMSize(b, st, rs, ctx)
|
||||
case MOUT:
|
||||
b, err = RunMOut(b, st, rs, ctx)
|
||||
// case MNEXT:
|
||||
// b, err = RunMNext(b, st, rs, ctx)
|
||||
// case MPREV:
|
||||
// b, err = RunMPrev(b, st, rs, ctx)
|
||||
case MNEXT:
|
||||
b, err = RunMNext(b, st, rs, ctx)
|
||||
case MPREV:
|
||||
b, err = RunMPrev(b, st, rs, ctx)
|
||||
case HALT:
|
||||
b, err = RunHalt(b, st, rs, ctx)
|
||||
return b, err
|
||||
@ -257,25 +257,25 @@ func RunMOut(b []byte, st *state.State, rs resource.Resource, ctx context.Contex
|
||||
return b, err
|
||||
}
|
||||
|
||||
//// RunMNext executes the MNEXT opcode
|
||||
//func RunMNext(b []byte, st *state.State, rs resource.Resource, ctx context.Context) ([]byte, error) {
|
||||
// selector, display, b, err := ParseMNext(b)
|
||||
// if err != nil {
|
||||
// return b, err
|
||||
// }
|
||||
// err = rs.SetMenuBrowse(selector, display, false)
|
||||
// return b, err
|
||||
//}
|
||||
//
|
||||
//// RunMPrev executes the MPREV opcode
|
||||
//func RunMPrev(b []byte, st *state.State, rs resource.Resource, ctx context.Context) ([]byte, error) {
|
||||
// selector, display, b, err := ParseMPrev(b)
|
||||
// if err != nil {
|
||||
// return b, err
|
||||
// }
|
||||
// err = rs.SetMenuBrowse(selector, display, false)
|
||||
// return b, err
|
||||
//}
|
||||
// RunMNext executes the MNEXT opcode
|
||||
func RunMNext(b []byte, st *state.State, rs resource.Resource, ctx context.Context) ([]byte, error) {
|
||||
selector, display, b, err := ParseMNext(b)
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
err = rs.SetMenuBrowse(selector, display, false)
|
||||
return b, err
|
||||
}
|
||||
|
||||
// RunMPrev executes the MPREV opcode
|
||||
func RunMPrev(b []byte, st *state.State, rs resource.Resource, ctx context.Context) ([]byte, error) {
|
||||
selector, display, b, err := ParseMPrev(b)
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
err = rs.SetMenuBrowse(selector, display, false)
|
||||
return b, err
|
||||
}
|
||||
|
||||
// retrieve data for key
|
||||
func refresh(key string, rs resource.Resource, ctx context.Context) (string, error) {
|
||||
|
18
go/vm/vm.go
18
go/vm/vm.go
@ -75,15 +75,15 @@ func ParseInCmp(b []byte) (string, string, []byte, error) {
|
||||
return parseTwoSym(b)
|
||||
}
|
||||
|
||||
//// ParseMPrev parses and extracts the expected argument portion of a MPREV instruction
|
||||
//func ParseMPrev(b []byte) (string, string, []byte, error) {
|
||||
// return parseTwoSym(b)
|
||||
//}
|
||||
//
|
||||
//// ParseMNext parses and extracts the expected argument portion of a MNEXT instruction
|
||||
//func ParseMNext(b []byte) (string, string, []byte, error) {
|
||||
// return parseTwoSym(b)
|
||||
//}
|
||||
// ParseMPrev parses and extracts the expected argument portion of a MPREV instruction
|
||||
func ParseMPrev(b []byte) (string, string, []byte, error) {
|
||||
return parseTwoSym(b)
|
||||
}
|
||||
|
||||
// ParseMNext parses and extracts the expected argument portion of a MNEXT instruction
|
||||
func ParseMNext(b []byte) (string, string, []byte, error) {
|
||||
return parseTwoSym(b)
|
||||
}
|
||||
|
||||
// ParseMSize parses and extracts the expected argument portion of a MSIZE instruction
|
||||
func ParseMSize(b []byte) (uint32, uint32, []byte, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user