Skip to content

Commit

Permalink
Add 'stdlib/REPL/src/TerminalMenus/' from commit '9a3511a4a6edb26a64f…
Browse files Browse the repository at this point in the history
…7f252e1fd4c0713a6c12a'

git-subtree-dir: stdlib/REPL/src/TerminalMenus
git-subtree-mainline: f8acac7
git-subtree-split: 9a3511a
  • Loading branch information
KristofferC committed Feb 8, 2018
2 parents f8acac7 + 9a3511a commit cf3b0ab
Show file tree
Hide file tree
Showing 16 changed files with 1,078 additions and 0 deletions.
5 changes: 5 additions & 0 deletions stdlib/REPL/src/TerminalMenus/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.jl.cov
*.jl.*.cov
*.jl.mem
*.o
*.d
35 changes: 35 additions & 0 deletions stdlib/REPL/src/TerminalMenus/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Documentation: http://docs.travis-ci.com/user/languages/julia/
language: julia
os:
- linux
- osx
julia:
- 0.6
- nightly
notifications:
email: false
git:
depth: 99999999

## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
#matrix:
# allow_failures:
# - julia: nightly

## uncomment and modify the following lines to manually install system packages
#addons:
# apt: # apt-get for linux
# packages:
# - gfortran
#before_script: # homebrew for mac
# - if [ $TRAVIS_OS_NAME = osx ]; then brew install gcc; fi

## uncomment the following lines to override the default test script
#script:
# - julia -e 'Pkg.clone(pwd()); Pkg.build("TerminalMenus"); Pkg.test("TerminalMenus"; coverage=true)'
after_success:
# push coverage results to Coveralls
- julia -e 'cd(Pkg.dir("TerminalMenus")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
# push coverage results to Codecov
- julia -e 'cd(Pkg.dir("TerminalMenus")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
22 changes: 22 additions & 0 deletions stdlib/REPL/src/TerminalMenus/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The TerminalMenus.jl package is licensed under the MIT "Expat" License:

> Copyright (c) 2017: Nick Paul.
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all
> copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.
>
170 changes: 170 additions & 0 deletions stdlib/REPL/src/TerminalMenus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# TerminalMenus

[![Build Status](https://travis-ci.org/nick-paul/TerminalMenus.jl.svg?branch=master)](https://travis-ci.org/nick-paul/TerminalMenus.jl) [![Build status](https://ci.appveyor.com/api/projects/status/weaqa64co5boj87g?svg=true)](https://ci.appveyor.com/project/nick-paul/terminalmenus-jl)

![Demo](http://npaul.co/files/TerminalMenus-demo.gif)

TerminalMenus.jl enables small, low-profile interactive menus in the terminal.


# Installation

TerminalMenus requires Julia 0.6. Use `Pkg` to install:

```
Pkg.add("TerminalMenus")
```


# Examples

```julia
using TerminalMenus

options = ["apple", "orange", "grape", "strawberry",
"blueberry", "peach", "lemon", "lime"]

```

## RadioMenu

The RadioMenu allows the user to select one option from the list. The `request`
function displays the interactive menu and returns the index of the selected
choice. If a user presses 'q' or `ctrl-c`, `request` will return a `-1`.


```julia
# `pagesize` is the number of items to be displayed at a time.
# The UI will scroll if the number of options is greater
# than the `pagesize`
menu = RadioMenu(options, pagesize=4)

# `request` displays the menu and returns the index after the
# user has selected a choice
choice = request("Choose your favorite fruit:", menu)

if choice != -1
println("Your favorite fruit is ", options[choice], "!")
else
println("Menu canceled.")
end

```

Output:

```
Choose your favorite fruit:
^ grape
strawberry
> blueberry
v peach
Your favorite fruit is blueberry!
```

## MultiSelectMenu

The MultiSelectMenu allows users to select many choices from a list.

```julia
# here we use the default `pagesize` 10
menu = MultiSelectMenu(options)

# `request` returns a `Set` of selected indices
# if the menu us canceled (ctrl-c or q), return an empty set
choices = request("Select the fruits you like:", menu)

if length(choices) > 0
println("You like the following fruits:")
for i in choices
println(" - ", options[i])
end
else
println("Menu canceled.")
end
```

Output:

```
Select the fruits you like:
[press: d=done, a=all, n=none]
[ ] apple
> [X] orange
[X] grape
[ ] strawberry
[ ] blueberry
[X] peach
[ ] lemon
[ ] lime
You like the following fruits:
- orange
- grape
- peach
```

# Customization / Configuation

All interface customization is done through the keyword only
`TerminalMenus.config()` function.

## Arguments

- `charset::Symbol=:na`: ui characters to use (`:ascii` or `:unicode`); overridden by other arguments
- `cursor::Char='>'|'→'`: character to use for cursor
- `up_arrow::Char='^'|'↑'`: character to use for up arrow
- `down_arrow::Char='v'|'↓'`: character to use for down arrow
- `checked::String="[X]"|"✓"`: string to use for checked
- `unchecked::String="[ ]"|"⬚")`: string to use for unchecked
- `scroll::Symbol=:na`: If `:wrap` then wrap the cursor around top and bottom, if :`nowrap` do not wrap cursor
- `supress_output::Bool=false`: For testing. If true, menu will not be printed to console.
- `ctrl_c_interrupt::Bool=true`: If `false`, return empty on ^C, if `true` throw InterruptException() on ^C

## Examples

```julia
julia> menu = MultiSelectMenu(options, pagesize=5);

julia> request(menu) # ASCII is used by default
[press: d=done, a=all, n=none]
[ ] apple
[X] orange
[ ] grape
> [X] strawberry
v [ ] blueberry
Set([4, 2])

julia> TerminalMenus.config(charset=:unicode)

julia> request(menu)
[press: d=done, a=all, n=none]
⬚ apple
✓ orange
⬚ grape
✓ strawberry
⬚ blueberry
Set([4, 2])

julia> TerminalMenus.config(checked="YEP!", unchecked="NOPE", cursor='')

julia> request(menu)
[press: d=done, a=all, n=none]
NOPE apple
YEP! orange
NOPE grape
⧐ YEP! strawberry
NOPE blueberry
Set([4, 2])

```

# TODO

- Nested menus
- More customization?

---

*The interactive menu has been tested on Ubuntu 16.04 and windows 7, 8, & 10.
If there are any issues on your platform, please submit an issue or a pull
request.*
1 change: 1 addition & 0 deletions stdlib/REPL/src/TerminalMenus/REQUIRE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
julia 0.6
47 changes: 47 additions & 0 deletions stdlib/REPL/src/TerminalMenus/appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
#matrix:
# allow_failures:
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

branches:
only:
- master
- /release-.*/

notifications:
- provider: Email
on_build_success: false
on_build_failure: false
on_build_status_changed: false

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# If there's a newer build queued for the same PR, cancel this one
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
throw "There are newer queued builds for this pull request, failing early." }
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"TerminalMenus\"); Pkg.build(\"TerminalMenus\")"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"TerminalMenus\")"
10 changes: 10 additions & 0 deletions stdlib/REPL/src/TerminalMenus/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 0.0.2

- Add menu customization
- Add unicode and ascii UI sets
- Add wrap around top and bottom of menu (optional)
- Add better documentation and more comprehensive test cases

# 0.0.1

Initial release. Includes RadioMenu and MultiSelectMenu
Loading

0 comments on commit cf3b0ab

Please sign in to comment.