bsdinstall: improve pkgbase target retry prompts
These now use bsddialog rather than prompting the user for input on the console. Reviewed by: emaste Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D50270
This commit is contained in:
@@ -23,18 +23,6 @@ local function capture(command)
|
||||
return output:match("(.-)\n$") or output
|
||||
end
|
||||
|
||||
local function prompt_yn(question)
|
||||
while true do
|
||||
io.write(question .. " (y/n) ")
|
||||
local input = io.read()
|
||||
if input == "y" or input == "Y" then
|
||||
return true
|
||||
elseif input == "n" or input == "N" then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function append_list(list, other)
|
||||
for _, item in ipairs(other) do
|
||||
table.insert(list, item)
|
||||
@@ -73,6 +61,18 @@ local function bsddialog(args)
|
||||
return exit_code, output
|
||||
end
|
||||
|
||||
-- Prompts the user for a yes/no answer to the given question using bsddialog
|
||||
-- Returns true if the user answers yes and false if the user answers no.
|
||||
local function prompt_yn(question)
|
||||
local exit_code = bsddialog({
|
||||
"--yesno",
|
||||
"--disable-esc",
|
||||
question,
|
||||
0, 0, -- autosize
|
||||
})
|
||||
return exit_code == 0
|
||||
end
|
||||
|
||||
-- Creates a dialog for component selection mirroring the
|
||||
-- traditional tarball component selection dialog.
|
||||
local function select_components(components, options)
|
||||
@@ -254,7 +254,6 @@ local function pkgbase()
|
||||
|
||||
while not os.execute(pkg .. "update") do
|
||||
if not prompt_yn("Updating repositories failed, try again?") then
|
||||
print("Canceled")
|
||||
os.exit(1)
|
||||
end
|
||||
end
|
||||
@@ -263,7 +262,6 @@ local function pkgbase()
|
||||
|
||||
while not os.execute(pkg .. "install -U -F -y -r FreeBSD-base " .. packages) do
|
||||
if not prompt_yn("Fetching packages failed, try again?") then
|
||||
print("Canceled")
|
||||
os.exit(1)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user