From 99b46a9c765e1add1996951b41c06ae9504db63e Mon Sep 17 00:00:00 2001 From: sloumdrone Date: Wed, 9 Jan 2019 21:20:51 -0800 Subject: [PATCH] Added functional pipes. Still need a larger refactor. --- stubb | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/stubb b/stubb index 6b44cd7..b55ca24 100755 --- a/stubb +++ b/stubb @@ -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 .. '/')