diff --git a/src/REPLMode/REPLMode.jl b/src/REPLMode/REPLMode.jl index 5431182521..5dc92e2def 100644 --- a/src/REPLMode/REPLMode.jl +++ b/src/REPLMode/REPLMode.jl @@ -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) @@ -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) @@ -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