Got search working

This commit is contained in:
sloumdrone 2019-01-09 22:23:04 -08:00
parent 99b46a9c76
commit 9e20427b43
1 changed files with 31 additions and 14 deletions

45
stubb
View File

@ -1,13 +1,13 @@
#!/usr/bin/env lua
local version = 'v0.9.0'
local version = 'v0.11.0'
local socket = require("socket")
local urlparser = require("socket.url")
local separator = '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n'
local valid_types = {'0', '1', 'i'}
local valid_types = {'0', '1', 'i', '7'}
session = { tabs = { }, favorites = {} }
local save_file_location = string.format('%s/.stubbfaves', assert(os.getenv('HOME'), 'Unable to get home directory'))
local search_provider = 'gopher://gopher.floodgap.com:70/7/v2/vs'
@ -41,8 +41,8 @@ end
function table.out(t)
for i, v in ipairs(t) do
print(string.format('%q', v))
for i, v in pairs(t) do
print(i, string.format('%q', v))
end
end
@ -73,10 +73,10 @@ end
function request_gopher(host, port, query)
local tcp = assert(socket.tcp())
local response = {}
tcp:settimeout(4, 't')
local connection = tcp:connect(host, port);
local request
if connection then
request = tcp:send(query.."\n");
end
@ -121,7 +121,6 @@ function parse_url(u) -- takes URL string
end
parsed.full = parsed.scheme .. '://' .. parsed.host .. ':' .. parsed.port .. '/' .. parsed.gophertype .. parsed.path
return parsed
end
@ -133,6 +132,7 @@ function go_to_url(u, add2history, noprint)
print(separator)
print('Invalid url')
elseif table.has(valid_types, url.gophertype) then
if url.query ~= '' and url.query then url.path = url.path .. '?' .. url.query end
t.filedata = request_gopher(url.host, url.port, url.path)
print(separator)
@ -162,7 +162,7 @@ function display_gophermap_row(row)
local spacer = ' '
if gophertype == 'i' then
return spacer .. (text or '')
elseif table.has(valid_types, gophertype) then
elseif table.has(valid_types, gophertype) and gophertpe ~= '7' then
local leader = gophertype == '0' and 'TXT' or 'MAP'
local url = string.format('%s:%s/%s%s', val[3] or '', val[4] or '', gophertype, val[2] or '/')
table.insert(t.current_links, url)
@ -253,7 +253,7 @@ function print_help()
The command bar lists the current tab number, out of how many total tabs. It also
lists the current place in history (for the tab you are currently on).
Commands:
Command map:
<Navigation>
(B)ack
@ -264,8 +264,19 @@ function print_help()
- (T)ab
- (U)rl
(R)eload current address
(P)ipe to
- (R)eader
- (C)urrent
- (L)ink
- (T)ab
- (C)urrent
- (L)ink
- (D)isk
- (C)urrent
- (L)ink
(S)earch
<Bookmarks>
<Bookmarks/Tabs>
(A)dd
- (B)ookmark
- (T)ab
@ -280,7 +291,6 @@ function print_help()
<System>
(H)elp
(Q)uit Stubb
(S)ave file to disk
For more information, source code, or to get a copy:
@ -296,7 +306,14 @@ end
function search()
-- Do search here
io.write('Enter your search terms: ')
local st = io.read()
if not st or st == '' then return print('Invalid search entry') end
if url ~= '!' and url ~= '' then
go_to_url(search_provider .. '\t' .. st, true)
else
print('Cancelled')
end
end
@ -547,8 +564,6 @@ function add_favorite()
end
function remove_favorite()
io.write('Enter the bookmark id to remove (! to cancel): ')
local favid = io.read()
@ -619,6 +634,8 @@ function save_file()
else
return print('Invalid link id. Save cancelled.')
end
else
return print('Invalid entry')
end
local homedir = assert(os.getenv('HOME'), 'Unable to find home directory')
io.write('Enter the filename to save as (! to cancel): ' .. homedir .. '/')