Added more complete keyhandling
This commit is contained in:
parent
59ee19882e
commit
de13bc5bee
57
stubb
57
stubb
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env lua
|
#!/usr/bin/env lua
|
||||||
|
|
||||||
local version = 'v0.11.0'
|
local version = 'v0.12.0'
|
||||||
local socket = require("socket")
|
local socket = require("socket")
|
||||||
local urlparser = require("socket.url")
|
local urlparser = require("socket.url")
|
||||||
local separator = '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n'
|
local separator = '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n'
|
||||||
|
@ -66,6 +66,12 @@ table.truncate = function(t, i)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function invalid_key(key)
|
||||||
|
if key == 'enter' then io.write('\27[2A\27[200D\27[K\27[1A\27[200D\27[K')
|
||||||
|
elseif key == 'other' then io.write('\27[1A\27[200D\27[K')
|
||||||
|
else io.write('\27[1A\27[200D\27[K\27[1A\27[200D\27[K') end
|
||||||
|
end
|
||||||
|
|
||||||
--||__||--||__||--||__||--||__||--||__||--||__||--||__||--||
|
--||__||--||__||--||__||--||__||--||__||--||__||--||__||--||
|
||||||
------------------------------------------------------------
|
------------------------------------------------------------
|
||||||
-- TCP Requests and processing -----------------------------
|
-- TCP Requests and processing -----------------------------
|
||||||
|
@ -190,8 +196,11 @@ function getch()
|
||||||
-- taken from: http://lua.2524044.n2.nabble.com/How-to-get-one-keystroke-without-hitting-Enter-td5858614.html
|
-- taken from: http://lua.2524044.n2.nabble.com/How-to-get-one-keystroke-without-hitting-Enter-td5858614.html
|
||||||
os.execute("stty cbreak </dev/tty >/dev/tty 2>&1")
|
os.execute("stty cbreak </dev/tty >/dev/tty 2>&1")
|
||||||
local key = io.read(1)
|
local key = io.read(1)
|
||||||
|
if string.byte(key) == 27 then io.read(2) end
|
||||||
|
|
||||||
os.execute("stty -cbreak </dev/tty >/dev/tty 2>&1");
|
os.execute("stty -cbreak </dev/tty >/dev/tty 2>&1");
|
||||||
print('\27[1D ')
|
print('\27[1D ')
|
||||||
|
key = string.byte(key) == string.byte('\n') and 'enter' or key
|
||||||
|
|
||||||
return string.lower(key);
|
return string.lower(key);
|
||||||
end
|
end
|
||||||
|
@ -236,7 +245,8 @@ function mainloop()
|
||||||
elseif key == 'd' then delete()
|
elseif key == 'd' then delete()
|
||||||
elseif key == 'g' then go_to()
|
elseif key == 'g' then go_to()
|
||||||
elseif key == 'c' then clean_screen()
|
elseif key == 'c' then clean_screen()
|
||||||
else print('Invalid entry') end
|
elseif key == 'enter' then io.write('\27[2A\27[200D\27[K')
|
||||||
|
else print('\27[2A\27[200D\27[K') end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -341,7 +351,7 @@ function back()
|
||||||
if th.loc > 1 and #th.items > 1 then
|
if th.loc > 1 and #th.items > 1 then
|
||||||
th.loc = th.loc - 1
|
th.loc = th.loc - 1
|
||||||
go_to_url(th.items[th.loc])
|
go_to_url(th.items[th.loc])
|
||||||
end
|
else invalid_key('other') end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -350,6 +360,8 @@ function forward()
|
||||||
if th.loc < #th.items then
|
if th.loc < #th.items then
|
||||||
th.loc = th.loc + 1
|
th.loc = th.loc + 1
|
||||||
go_to_url(th.items[th.loc])
|
go_to_url(th.items[th.loc])
|
||||||
|
else
|
||||||
|
invalid_key('other')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -392,48 +404,37 @@ end
|
||||||
function pipe()
|
function pipe()
|
||||||
io.write('Pipe to: (D)isk, (R)eader, New (T)ab')
|
io.write('Pipe to: (D)isk, (R)eader, New (T)ab')
|
||||||
local subkey = getch()
|
local subkey = getch()
|
||||||
if subkey == 'd' then
|
if subkey == 'd' then save_file()
|
||||||
save_file()
|
elseif subkey == 't' then open_in_tab()
|
||||||
elseif subkey == 't' then
|
elseif subkey == 'r' then open_in_less()
|
||||||
open_in_tab()
|
else invalid_key(subkey) end
|
||||||
elseif subkey == 'r' then
|
|
||||||
open_in_less()
|
|
||||||
else
|
|
||||||
print('Invalid entry')
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function add()
|
function add()
|
||||||
io.write('Add: (B)ookmark, (T)ab')
|
io.write('Add: (B)ookmark, (T)ab')
|
||||||
local subkey = getch()
|
local subkey = getch()
|
||||||
if subkey == 'b' then
|
if subkey == 'b' then add_favorite()
|
||||||
add_favorite()
|
elseif subkey == 't' then new_tab()
|
||||||
elseif subkey == 't' then
|
else invalid_key(subkey) end
|
||||||
new_tab()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function list()
|
function list()
|
||||||
io.write('List: (B)ookmarks, (T)abs')
|
io.write('List: (B)ookmarks, (T)abs')
|
||||||
local subkey = getch()
|
local subkey = getch()
|
||||||
if subkey == 'b' then
|
if subkey == 'b' then show_favorites()
|
||||||
show_favorites()
|
elseif subkey == 't' then show_tabs()
|
||||||
elseif subkey == 't' then
|
else invalid_key(subkey) end
|
||||||
show_tabs()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function delete()
|
function delete()
|
||||||
io.write('Delete: (B)ookmark, (T)ab')
|
io.write('Delete: (B)ookmark, (T)ab')
|
||||||
local subkey = getch()
|
local subkey = getch()
|
||||||
if subkey == 'b' then
|
if subkey == 'b' then remove_favorite()
|
||||||
remove_favorite()
|
elseif subkey == 't' then remove_tab()
|
||||||
elseif subkey == 't' then
|
else invalid_key(subkey) end
|
||||||
remove_tab()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -462,7 +463,7 @@ function go_to()
|
||||||
else
|
else
|
||||||
print('Cancelled')
|
print('Cancelled')
|
||||||
end
|
end
|
||||||
end
|
else invalid_key(subkey) end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue