Skip to content

Commit

Permalink
Refactor command execution
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimyr committed Jun 8, 2020
1 parent 6320514 commit 172f387
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
10 changes: 4 additions & 6 deletions src/module/repl.wren
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ class Repl {
// TODO: Handle ESC 0 sequences.
}
} else if (byte == Chars.carriageReturn) {
var next = executeInput()
if (next == Chars.ctrlD) return true
if (next != null) handleChar(next)
return executeInput()
} else if (byte == Chars.delete) {
deleteLeft()
} else if (byte >= Chars.space && byte <= Chars.tilde) {
Expand Down Expand Up @@ -215,13 +213,13 @@ class Repl {
}
}

executeCommand(command, arguments) {
executeCommand(command, argument) {
if (command == Command.clear) {
return Chars.ctrlL
return this.handleChar(Chars.ctrlL)
}

if (command == Command.exit) {
return Chars.ctrlD
return true
}

if (command == Command.help) {
Expand Down
10 changes: 4 additions & 6 deletions src/module/repl.wren.inc
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ static const char* replModuleSource =
" // TODO: Handle ESC 0 sequences.\n"
" }\n"
" } else if (byte == Chars.carriageReturn) {\n"
" var next = executeInput()\n"
" if (next == Chars.ctrlD) return true\n"
" if (next != null) handleChar(next)\n"
" return executeInput()\n"
" } else if (byte == Chars.delete) {\n"
" deleteLeft()\n"
" } else if (byte >= Chars.space && byte <= Chars.tilde) {\n"
Expand Down Expand Up @@ -217,13 +215,13 @@ static const char* replModuleSource =
" }\n"
" }\n"
"\n"
" executeCommand(command, arguments) {\n"
" executeCommand(command, argument) {\n"
" if (command == Command.clear) {\n"
" return Chars.ctrlL\n"
" return this.handleChar(Chars.ctrlL)\n"
" }\n"
"\n"
" if (command == Command.exit) {\n"
" return Chars.ctrlD\n"
" return true\n"
" }\n"
"\n"
" if (command == Command.help) {\n"
Expand Down

0 comments on commit 172f387

Please sign in to comment.