Skip to content

Commit

Permalink
Show the value that will be used if not customized (#177)
Browse files Browse the repository at this point in the history
* Show the value that will be used if not customized

* enhanced code organization

* Update src/template.jl

Co-authored-by: Chris de Graaf <[email protected]>

* Display default values for plugin options too

---------

Co-authored-by: Guillaume Dalle <[email protected]>
Co-authored-by: Chris de Graaf <[email protected]>
  • Loading branch information
3 people authored Dec 26, 2023
1 parent 2f97d4c commit 46997ed
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ using PkgTemplates
Template(interactive=true)("MyPkg")
```

This will prompt you to select options, displaying the default settings in parentheses.

### Manual creation

Creating a `Template` is as simple as:
Expand Down
12 changes: 8 additions & 4 deletions src/interactive.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ function interactive(T::Type)
just_one = length(pairs) == 1
just_one && push!(pairs, :None => Nothing)

menu = MultiSelectMenu(
collect(map(pair -> string(first(pair)), pairs));
pagesize=length(pairs),
)
println("$(nameof(T)) keywords to customize:")
opts = map(first.(pairs)) do k
if k != :None
"$k ($(repr(defaultkw(T, k))))"
else
"$k"
end
end
menu = MultiSelectMenu(opts; pagesize=length(pairs))
customize = sort!(collect(request(menu)))

# If the "None" option was selected, don't customize anything.
Expand Down
3 changes: 2 additions & 1 deletion src/template.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ function interactive(::Type{Template}; kwargs...)

try
println("Template keywords to customize:")
menu = MultiSelectMenu(map(string, customizable); pagesize=length(customizable))
opts = map(k -> "$k ($(repr(defaultkw(Template, k))))" , customizable)
menu = MultiSelectMenu(opts; pagesize=length(customizable))
customize = customizable[sort!(collect(request(menu)))]
just_one && last(customizable) in customize && return Template(; kwargs...)

Expand Down

0 comments on commit 46997ed

Please sign in to comment.