From 742ca290c1c831b144be3a32a99ecb656f7a41a1 Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 11 Jul 2021 22:32:10 -0400 Subject: [PATCH 1/6] extend install prompt functionality --- src/REPLMode/REPLMode.jl | 66 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/src/REPLMode/REPLMode.jl b/src/REPLMode/REPLMode.jl index 83b81662b8..4c41b8b235 100644 --- a/src/REPLMode/REPLMode.jl +++ b/src/REPLMode/REPLMode.jl @@ -6,6 +6,7 @@ using Markdown, UUIDs, Dates import REPL import REPL: LineEdit, REPLCompletions +import REPL: TerminalMenus import ..casesensitive_isdir, ..OFFLINE_MODE, ..linewrap using ..Types, ..Operations, ..API, ..Registry, ..Resolve @@ -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/t or ? for details)", default = "y") catch err if err isa InterruptException # if ^C is entered println(ctx.io) @@ -692,15 +693,72 @@ function try_prompt_pkg_add(pkgs::Vector{Symbol}) println(ctx.io) return false end - if lowercase(resp) in ["y", "yes"] - API.add(string.(available_pkgs)) + function handle_resp(resp, called_from_help) + lower_resp = lowercase(resp) + if lower_resp in ["y", "yes"] + API.add(string.(available_pkgs)) + elseif lower_resp in ["t", "temp"] + API.activate(temp = true) + API.add(string.(available_pkgs)) + elseif lower_resp in ["o"] + envs = filter(v -> v != "@stdlib", Base.LOAD_PATH) + menu = TerminalMenus.RadioMenu(envs, pagesize=length(envs)) + rows_to_clear = called_from_help ? 5 : 1 + for _ in 1:rows_to_clear + print(ctx.io, "\e[1A\e[1G\e[0J") + end + printstyled(ctx.io, " └ "; color=:green) + choice = try + TerminalMenus.request("Select an environment from the load path", 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 !called_from_help && (lower_resp in ["?"]) + options = ["y: Add package to the current environment", + "n: Don't add the package", + "o: Select an environment from the load path to add the package to", + "t: Activate a new temporary environment and add the package"] + menu = TerminalMenus.RadioMenu(options, pagesize=4) + print(ctx.io, "\e[1A\e[1G\e[0J") + printstyled(ctx.io, " └ "; color=:green) + choice = try + TerminalMenus.request("Select an option", menu) + catch err + if err isa InterruptException # if ^C is entered + println(ctx.io) + return false + end + rethrow() + end + choice == -1 && return false + return ["y", "n", "o", "t"][choice] + 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 end - return false + + ret = handle_resp(resp, false) + if ret isa Bool + return ret + else + return handle_resp(ret, true) + end end end #module From c8dd7a0e0315292b2a0e7452f6e52fbb3fdbc7d3 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 12 Jul 2021 20:33:02 -0400 Subject: [PATCH 2/6] use expanded load_path paths --- src/REPLMode/REPLMode.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/REPLMode/REPLMode.jl b/src/REPLMode/REPLMode.jl index 4c41b8b235..8ba2c041a7 100644 --- a/src/REPLMode/REPLMode.jl +++ b/src/REPLMode/REPLMode.jl @@ -701,7 +701,8 @@ function try_prompt_pkg_add(pkgs::Vector{Symbol}) API.activate(temp = true) API.add(string.(available_pkgs)) elseif lower_resp in ["o"] - envs = filter(v -> v != "@stdlib", Base.LOAD_PATH) + expanded_envs = Base.load_path_expand.(filter(v -> v != "@stdlib", LOAD_PATH)) + envs = convert(Vector{String}, filter(x -> !isnothing(x), expanded_envs)) menu = TerminalMenus.RadioMenu(envs, pagesize=length(envs)) rows_to_clear = called_from_help ? 5 : 1 for _ in 1:rows_to_clear From 43e13908499efb2c17ab621c4b9a8f8806380724 Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 13 Jul 2021 09:12:47 -0400 Subject: [PATCH 3/6] simpler setup from suggestions --- src/REPLMode/REPLMode.jl | 99 ++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 59 deletions(-) diff --git a/src/REPLMode/REPLMode.jl b/src/REPLMode/REPLMode.jl index 8ba2c041a7..7656775d9d 100644 --- a/src/REPLMode/REPLMode.jl +++ b/src/REPLMode/REPLMode.jl @@ -681,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/o/t or ? for details)", 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,72 +693,53 @@ function try_prompt_pkg_add(pkgs::Vector{Symbol}) println(ctx.io) return false end - function handle_resp(resp, called_from_help) - lower_resp = lowercase(resp) - if lower_resp in ["y", "yes"] - API.add(string.(available_pkgs)) - elseif lower_resp in ["t", "temp"] + + lower_resp = lowercase(resp) + if lower_resp in ["y", "yes"] + API.add(string.(available_pkgs)) + elseif lower_resp in ["t", "temp"] # hidden option + API.activate(temp = true) + API.add(string.(available_pkgs)) + 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[] + for i in 1:length(envs) + push!(option_list, "`$(envs[i])` ($(editable_envs[i]))") + end + push!(option_list, "Activate and install into new temporary environment") + menu = TerminalMenus.RadioMenu(option_list, pagesize=length(option_list)) + print(ctx.io, "\e[1A\e[1G\e[0J") + 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 + if choice == length(option_list) API.activate(temp = true) API.add(string.(available_pkgs)) - elseif lower_resp in ["o"] - expanded_envs = Base.load_path_expand.(filter(v -> v != "@stdlib", LOAD_PATH)) - envs = convert(Vector{String}, filter(x -> !isnothing(x), expanded_envs)) - menu = TerminalMenus.RadioMenu(envs, pagesize=length(envs)) - rows_to_clear = called_from_help ? 5 : 1 - for _ in 1:rows_to_clear - print(ctx.io, "\e[1A\e[1G\e[0J") - end - printstyled(ctx.io, " └ "; color=:green) - choice = try - TerminalMenus.request("Select an environment from the load path", menu) - catch err - if err isa InterruptException # if ^C is entered - println(ctx.io) - return false - end - rethrow() - end - choice == -1 && return false + else API.activate(envs[choice]) do API.add(string.(available_pkgs)) end - elseif !called_from_help && (lower_resp in ["?"]) - options = ["y: Add package to the current environment", - "n: Don't add the package", - "o: Select an environment from the load path to add the package to", - "t: Activate a new temporary environment and add the package"] - menu = TerminalMenus.RadioMenu(options, pagesize=4) - print(ctx.io, "\e[1A\e[1G\e[0J") - printstyled(ctx.io, " └ "; color=:green) - choice = try - TerminalMenus.request("Select an option", menu) - catch err - if err isa InterruptException # if ^C is entered - println(ctx.io) - return false - end - rethrow() - end - choice == -1 && return false - return ["y", "n", "o", "t"][choice] - 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 + elseif (lower_resp in ["n"]) + return false + else + println(ctx.io, "Selection not recognized") + return false end - - ret = handle_resp(resp, false) - if ret isa Bool - return ret + if length(available_pkgs) < length(pkgs) + return false # declare that some pkgs couldn't be installed else - return handle_resp(ret, true) + return true end end From 3f5dc670e3f31f627054e2e6efa9ba9ada073079 Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 13 Jul 2021 12:17:58 -0400 Subject: [PATCH 4/6] use pathrepr --- src/REPLMode/REPLMode.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/REPLMode/REPLMode.jl b/src/REPLMode/REPLMode.jl index 7656775d9d..233061c135 100644 --- a/src/REPLMode/REPLMode.jl +++ b/src/REPLMode/REPLMode.jl @@ -8,7 +8,7 @@ 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) @@ -706,7 +706,7 @@ function try_prompt_pkg_add(pkgs::Vector{Symbol}) envs = convert(Vector{String}, filter(x -> !isnothing(x), expanded_envs)) option_list = String[] for i in 1:length(envs) - push!(option_list, "`$(envs[i])` ($(editable_envs[i]))") + push!(option_list, "$(pathrepr(envs[i])) ($(editable_envs[i]))") end push!(option_list, "Activate and install into new temporary environment") menu = TerminalMenus.RadioMenu(option_list, pagesize=length(option_list)) From 5208f30974b635e462efbe3d3ca854a04a485748 Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 13 Jul 2021 23:55:47 -0400 Subject: [PATCH 5/6] use keybindings on options menu --- src/REPLMode/REPLMode.jl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/REPLMode/REPLMode.jl b/src/REPLMode/REPLMode.jl index 233061c135..957d809362 100644 --- a/src/REPLMode/REPLMode.jl +++ b/src/REPLMode/REPLMode.jl @@ -705,11 +705,14 @@ function try_prompt_pkg_add(pkgs::Vector{Symbol}) 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, "$(pathrepr(envs[i])) ($(editable_envs[i]))") + push!(option_list, "$(i): $(pathrepr(envs[i])) ($(editable_envs[i]))") + push!(keybindings, only("$i")) end - push!(option_list, "Activate and install into new temporary environment") - menu = TerminalMenus.RadioMenu(option_list, pagesize=length(option_list)) + push!(option_list, "t: Activate and install into new temporary environment") + push!(keybindings, 't') + menu = TerminalMenus.RadioMenu(option_list, keybindings=keybindings, pagesize=length(option_list)) print(ctx.io, "\e[1A\e[1G\e[0J") printstyled(ctx.io, " └ "; color=:green) choice = try From 5e7ade858330961fc2bbe364c1b05e01753abde4 Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 21 Jul 2021 17:05:22 -0400 Subject: [PATCH 6/6] remove temp env option --- src/REPLMode/REPLMode.jl | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/REPLMode/REPLMode.jl b/src/REPLMode/REPLMode.jl index 35a02a1751..5dc92e2def 100644 --- a/src/REPLMode/REPLMode.jl +++ b/src/REPLMode/REPLMode.jl @@ -697,9 +697,6 @@ function try_prompt_pkg_add(pkgs::Vector{Symbol}) lower_resp = lowercase(resp) if lower_resp in ["y", "yes"] API.add(string.(available_pkgs)) - elseif lower_resp in ["t", "temp"] # hidden option - API.activate(temp = true) - API.add(string.(available_pkgs)) elseif lower_resp in ["o"] editable_envs = filter(v -> v != "@stdlib", LOAD_PATH) expanded_envs = Base.load_path_expand.(editable_envs) @@ -710,10 +707,8 @@ function try_prompt_pkg_add(pkgs::Vector{Symbol}) push!(option_list, "$(i): $(pathrepr(envs[i])) ($(editable_envs[i]))") push!(keybindings, only("$i")) end - push!(option_list, "t: Activate and install into new temporary environment") - push!(keybindings, 't') menu = TerminalMenus.RadioMenu(option_list, keybindings=keybindings, pagesize=length(option_list)) - print(ctx.io, "\e[1A\e[1G\e[0J") + 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) @@ -725,13 +720,8 @@ function try_prompt_pkg_add(pkgs::Vector{Symbol}) rethrow() end choice == -1 && return false - if choice == length(option_list) - API.activate(temp = true) + API.activate(envs[choice]) do API.add(string.(available_pkgs)) - else - API.activate(envs[choice]) do - API.add(string.(available_pkgs)) - end end elseif (lower_resp in ["n"]) return false