Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for function keys #425

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ var CommandFuncs = map[parser.CommandType]CommandFunc{
token.ESCAPE: ExecuteKey(input.Escape),
token.PAGEUP: ExecuteKey(input.PageUp),
token.PAGEDOWN: ExecuteKey(input.PageDown),
token.F1: ExecuteKey(input.F1),
token.F2: ExecuteKey(input.F2),
token.F3: ExecuteKey(input.F3),
token.F4: ExecuteKey(input.F4),
token.F5: ExecuteKey(input.F5),
token.F6: ExecuteKey(input.F6),
token.F7: ExecuteKey(input.F7),
token.F8: ExecuteKey(input.F8),
token.F9: ExecuteKey(input.F9),
token.F10: ExecuteKey(input.F10),
token.F11: ExecuteKey(input.F11),
token.F12: ExecuteKey(input.F12),
token.HIDE: ExecuteHide,
token.REQUIRE: ExecuteRequire,
token.SHOW: ExecuteShow,
Expand Down
4 changes: 2 additions & 2 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
)

func TestCommand(t *testing.T) {
const numberOfCommands = 27
const numberOfCommands = 39
if len(parser.CommandTypes) != numberOfCommands {
t.Errorf("Expected %d commands, got %d", numberOfCommands, len(parser.CommandTypes))
}

const numberOfCommandFuncs = 27
const numberOfCommandFuncs = 39
if len(CommandFuncs) != numberOfCommandFuncs {
t.Errorf("Expected %d commands, got %d", numberOfCommandFuncs, len(CommandFuncs))
}
Expand Down
8 changes: 8 additions & 0 deletions examples/fixtures/all.tape
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ PageDown
PageDown 2
PageDown@1 3

F1
F1 2
F1@1 3

F12
F12 2
F12@1 3

Enter
Enter 2
Enter@1 3
Expand Down
14 changes: 14 additions & 0 deletions lexer/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@ func TestLexTapeFile(t *testing.T) {
{token.AT, "@"},
{token.NUMBER, "1"},
{token.NUMBER, "3"},
{token.F1, "F1"},
{token.F1, "F1"},
{token.NUMBER, "2"},
{token.F1, "F1"},
{token.AT, "@"},
{token.NUMBER, "1"},
{token.NUMBER, "3"},
{token.F12, "F12"},
{token.F12, "F12"},
{token.NUMBER, "2"},
{token.F12, "F12"},
{token.AT, "@"},
{token.NUMBER, "1"},
{token.NUMBER, "3"},
{token.ENTER, "Enter"},
{token.ENTER, "Enter"},
{token.NUMBER, "2"},
Expand Down
26 changes: 25 additions & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ var CommandTypes = []CommandType{ //nolint: deadcode
token.LEFT,
token.PAGEUP,
token.PAGEDOWN,
token.F1,
token.F2,
token.F3,
token.F4,
token.F5,
token.F6,
token.F7,
token.F8,
token.F9,
token.F10,
token.F11,
token.F12,
token.RIGHT,
token.SET,
token.OUTPUT,
Expand Down Expand Up @@ -147,7 +159,19 @@ func (p *Parser) parseCommand() Command {
token.RIGHT,
token.UP,
token.PAGEUP,
token.PAGEDOWN:
token.PAGEDOWN,
token.F1,
token.F2,
token.F3,
token.F4,
token.F5,
token.F6,
token.F7,
token.F8,
token.F9,
token.F10,
token.F11,
token.F12:
return p.parseKeypress(p.cur.Type)
case token.SET:
return p.parseSet()
Expand Down
6 changes: 6 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ func TestParseTapeFile(t *testing.T) {
{Type: token.PAGEDOWN, Options: "", Args: "1"},
{Type: token.PAGEDOWN, Options: "", Args: "2"},
{Type: token.PAGEDOWN, Options: "1s", Args: "3"},
{Type: token.F1, Options: "", Args: "1"},
{Type: token.F1, Options: "", Args: "2"},
{Type: token.F1, Options: "1s", Args: "3"},
{Type: token.F12, Options: "", Args: "1"},
{Type: token.F12, Options: "", Args: "2"},
{Type: token.F12, Options: "1s", Args: "3"},
{Type: token.ENTER, Options: "", Args: "1"},
{Type: token.ENTER, Options: "", Args: "2"},
{Type: token.ENTER, Options: "1s", Args: "3"},
Expand Down
25 changes: 25 additions & 0 deletions token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ const (
HOME = "HOME"
INSERT = "INSERT"
PAGEDOWN = "PAGEDOWN"
F1 = "F1"
F2 = "F2"
F3 = "F3"
F4 = "F4"
F5 = "F5"
F6 = "F6"
F7 = "F7"
F8 = "F8"
F9 = "F9"
F10 = "F10"
F11 = "F11"
F12 = "F12"
PAGEUP = "PAGEUP"
SLEEP = "SLEEP"
SPACE = "SPACE"
Expand Down Expand Up @@ -116,6 +128,18 @@ var Keywords = map[string]Type{
"Up": UP,
"PageUp": PAGEUP,
"PageDown": PAGEDOWN,
"F1": F1,
"F2": F2,
"F3": F3,
"F4": F4,
"F5": F5,
"F6": F6,
"F7": F7,
"F8": F8,
"F9": F9,
"F10": F10,
"F11": F11,
"F12": F12,
"Tab": TAB,
"Escape": ESCAPE,
"End": END,
Expand Down Expand Up @@ -168,6 +192,7 @@ func IsCommand(t Type) bool {
switch t {
case TYPE, SLEEP,
UP, DOWN, RIGHT, LEFT, PAGEUP, PAGEDOWN,
F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12,
ENTER, BACKSPACE, DELETE, TAB,
ESCAPE, HOME, INSERT, END, CTRL, SOURCE, SCREENSHOT, COPY, PASTE:
return true
Expand Down