Added functional pipes. Still need a larger refactor.

This commit is contained in:
sloumdrone 2019-01-09 21:20:51 -08:00
parent 7a127f573d
commit 99b46a9c76
1 changed files with 21 additions and 5 deletions

26
stubb
View File

@ -1,6 +1,6 @@
#!/usr/bin/env lua
local version = 'v0.8.8'
local version = 'v0.9.0'
local socket = require("socket")
local urlparser = require("socket.url")
local separator = '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n'
@ -362,6 +362,8 @@ function pipe()
open_in_tab()
elseif subkey == 'r' then
open_in_less()
else
print('Invalid entry')
end
end
@ -524,6 +526,8 @@ function open_in_less()
local less = io.popen('less', 'w')
less:write(str)
less:close()
else
print('No current URL to open in less')
end
end
@ -574,6 +578,10 @@ function remove_tab()
local item = session.tabs[id]
if item then
table.remove(session.tabs, id)
if #session.tabs < session.current_tab then
session.current_tab = #session.tabs
refresh()
end
print('Tab has been removed')
else
print('Invalid tab id')
@ -594,15 +602,23 @@ function save_file()
io.write('Save to disk: (C)urrent, (L)ink')
local subkey = getch()
local out
local t = session.tabs[session.current_tab]
if subkey == 'c' then
local t = session.tabs[session.current_tab]
out = t.filedata
if not out then return print('No file available. Save cancelled.') end
elseif subkey == 'l' then
local linkid = io.read()
local location = t.currentlinks[linkid]
-- handle getting data from the link
-- maybe set a flag on the get from url to return the data?
io.write('Enter link id (! to cancel): ')
local linkid = tonumber(io.read())
if linkid == '!' then return print('Cancelled') end
local location = t.current_links[linkid]
if location then
local parsed = parse_url(location)
out = request_gopher(parsed.host, parsed.port, parsed.path)
if not out then return print('No file data available. Save cancelled.') end
else
return print('Invalid link id. Save cancelled.')
end
end
local homedir = assert(os.getenv('HOME'), 'Unable to find home directory')
io.write('Enter the filename to save as (! to cancel): ' .. homedir .. '/')