From 74db639ba4f89c4e26e95d64659c5309002b136b Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Sat, 8 Dec 2018 15:10:36 +0000 Subject: Gracefully handle empty lines. --- telem.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/telem.lua b/telem.lua index bb68f7c..b73c275 100755 --- a/telem.lua +++ b/telem.lua @@ -279,11 +279,13 @@ function do_type() -- Show prompt and read one char io.write("[f]irst, [n]ext, [p]rev, [l]last, [r]eply, [d]one > ") c = getchar() - io.write("\n") + if c ~= "\n" then io.write("\n") end -- Dispatch to sub-command - if type_dispatch[c] == nil then + if c == "\n" then + -- pass + elseif type_dispatch[c] == nil then print("Invalid command!") - else + elseif c ~= "\n" then type_dispatch[c]() end until c == "d" @@ -357,11 +359,13 @@ repeat -- Show prompt and read 1 char from keyboard io.write("["..current_board.."] COMMAND :> ") c = getchar() - io.write("\n") + if c ~= "\n" then io.write("\n") end -- Use char as index into dispatch table - if dispatch[c] == nil then + if c == "\n" then + -- pass + elseif dispatch[c] == nil then print("Unrecognised command, hit `h` for help.") - else + else dispatch[c]() end until c == "q" -- cgit v1.2.3