Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend install prompt functionality #2669

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletions src/REPLMode/REPLMode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ using Markdown, UUIDs, Dates

import REPL
import REPL: LineEdit, REPLCompletions
import REPL: TerminalMenus

import ..casesensitive_isdir, ..OFFLINE_MODE, ..linewrap
import ..casesensitive_isdir, ..OFFLINE_MODE, ..linewrap, ..pathrepr
using ..Types, ..Operations, ..API, ..Registry, ..Resolve

const TEST_MODE = Ref{Bool}(false)
Expand Down Expand Up @@ -680,7 +681,7 @@ function try_prompt_pkg_add(pkgs::Vector{Symbol})
println(ctx.io, line)
end
printstyled(ctx.io, " └ "; color=:green)
Base.prompt(stdin, ctx.io, "(y/n)", default = "y")
Base.prompt(stdin, ctx.io, "(y/n/o)", default = "y")
catch err
if err isa InterruptException # if ^C is entered
println(ctx.io)
Expand All @@ -693,15 +694,46 @@ function try_prompt_pkg_add(pkgs::Vector{Symbol})
return false
end
resp = strip(resp)
if lowercase(resp) in ["y", "yes"]
lower_resp = lowercase(resp)
if lower_resp in ["y", "yes"]
API.add(string.(available_pkgs))
if length(available_pkgs) < length(pkgs)
return false # declare that some pkgs couldn't be installed
else
return true
elseif lower_resp in ["o"]
editable_envs = filter(v -> v != "@stdlib", LOAD_PATH)
expanded_envs = Base.load_path_expand.(editable_envs)
envs = convert(Vector{String}, filter(x -> !isnothing(x), expanded_envs))
option_list = String[]
keybindings = Char[]
for i in 1:length(envs)
push!(option_list, "$(i): $(pathrepr(envs[i])) ($(editable_envs[i]))")
push!(keybindings, only("$i"))
end
menu = TerminalMenus.RadioMenu(option_list, keybindings=keybindings, pagesize=length(option_list))
print(ctx.io, "\e[1A\e[1G\e[0J") # go up one line, to the start, and clear it
printstyled(ctx.io, " └ "; color=:green)
choice = try
TerminalMenus.request("Select environment:", menu)
catch err
if err isa InterruptException # if ^C is entered
println(ctx.io)
return false
end
rethrow()
end
choice == -1 && return false
API.activate(envs[choice]) do
API.add(string.(available_pkgs))
end
elseif (lower_resp in ["n"])
return false
else
println(ctx.io, "Selection not recognized")
return false
end
if length(available_pkgs) < length(pkgs)
return false # declare that some pkgs couldn't be installed
else
return true
end
return false
end

end #module