Giter Site home page Giter Site logo

terminalmenus.jl's People

Contributors

bjarthur avatar christopher-dg avatar keno avatar kristofferc avatar nick-paul avatar staticfloat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

terminalmenus.jl's Issues

Suppress `request` table output?

Hi,

I have two questions about the usage of terminal menus:

  1. In TerminalMenus.config(), I see the option of supress_output. Is there a typo? suppress_output?
  2. During testing, I want to turn off all the outputs, but setting this arg is not working me. I don't know where I did wrong:
using REPL.TerminalMenus
using Test

function simulateInput(keys...)

   keydict = Dict(:up => "\e[A",
                  :down => "\e[B",
                  :enter => "\r")

   for key in keys
      if isa(key, Symbol)
         write(Base.stdin.buffer, keydict[key])
      else
         write(Base.stdin.buffer, "$key")
      end
   end
end

TerminalMenus.config(supress_output=true)
options = ["a", "b", "c"]
menu = RadioMenu(options)
simulateInput(:enter)
choice = request("Choose variable:", menu)
@test choice == 1
julia> include("test_menu.jl")
Choose variable:
 > a
   b
   c
Test Passed
  Expression: choice == 1
   Evaluated: 1 == 1

The writing to stdin works fine, but how should I turn off the menu display?

multi-select from a single choice

my use case is that i programmatically calculate the choices from a search in a database, and then want to give the user the opportunity to manually prune a few bad results. multi-select is perfect for this.

the problem is that on occasion there is just one entry in the database, and i'd still like to give the user the opportunity to discard it. as terminalmenus.jl stands now, i have to add logic to handle this case. would be better to remove the restriction that there must be at least two choices. if you agree, i'm happy to work up a PR. let me know. thanks.

`writeline` ignores styled printing

Hi, I realize this library has been merged, and this repo is inactive, but the solution to my problem would probably end up with me forking this repo anyway, so I'd like to ask here. Maybe someone is still listening all these years later.

When overwriting the writeline method to use printstyled instead of print, TerminalMenus.request ignores the colored output:

import REPL
using REPL.TerminalMenus

# create menu
options = ["answer_01", "answer_02", "answer_03"]
menu = RadioMenu(options)

# print what options should look like
for e in menu.options
    printstyled(stdout, e * "\n", reverse=true)
end

# overwrite writeline to print styled 
function TerminalMenus.writeline(io::IO, menu::RadioMenu, cursor::Int, iscursor::Bool)
    printstyled(io, (iscursor ? "> " : "  ") * menu.options[cursor], reverse=true)
end

# request menu
request(menu)

This will first print the three answers with reverse properly displayed, then, when the answers are printed through the TerminalMenus routine, the style is ignored, despite printsytled writing to the menu-supplied buffer io.

Any tips what I function I would have to modify to make this work? I think it would be super nice to for example make the selected answer bold and yellow while making the other ones a darker gray, but this is currently not possible, which is a shame, considering how customizable TerminalMenus already is

I assume it may be related to https://github.com/nick-paul/TerminalMenus.jl/blob/master/src/AbstractMenu.jl#L129 but I don't fully understand this method

MethodError on Travis OSX builds

https://travis-ci.org/invenia/PkgTemplates.jl/jobs/267682403#L115

It appears that in environments where a TTY is not available, terminal.in_stream is an IOStream which has no check_open method defined for it.

Some tests for request would catch this, you can write some by manually writing to STDIN. For example, this will select the third entry from the top in a MultiSelectMenu:

write(STDIN.buffer, "$('\x1b')[B\r$('\x1b')[B\rd")

As for a fix, the simplest option is just for {enable,disable}RawMode to no-op if terminal.in_stream is an IOStream, since I'd imagine it's an exceedingly rare case in the "real world".

press <enter> to select?

currently the prompt for a MultiSelectMenu is [press: d=done, a=all, n=none]. took me awhile to figure out that one should press enter to select. how about changing the prompt to [press: d=done, a=all, n=none, <enter>=select] ?

Refer to official docs

Currently, I is not clear if this README is the best and updated source for documentation for TerminalMenus. To me, it would feel more appropriate to replace the readme with a short description of the history and scope of the package, and then just link to the official docs.

Would you agree? Because the current situation feels like it is split between this package and the official docs, and the maintenance burden is doubled (right)?

Line overflow bug

Issue originally submitted here by @vdayanand

If the text is longer than the width of the terminal, wrapping will occur and cause the text to be rendered improperly:

julia> A = [string(repeat("ABC-", x*2), "ABC") for x in 7:10]
4-element Array{String,1}:
 "ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC"
 "ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC"
 "ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC"
 "ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC"

julia> m = RadioMenu(A)
TerminalMenus.RadioMenu(String["ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC", "ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC", "ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC", "ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC"], 4, 0, -1)

julia> request(m)
 > ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC
   ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC
   ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC
   ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC

After pressing the down arrow, some lines are duplicated:

julia> request(m)
 > ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC
   ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC
 > ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC
   ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABCABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-   ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC

Possible solution: trim lines before printing. Show the end of the selection if it is highlighted by the cursor.

julia> request(m)
   ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC
   ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-A...
 > ...C-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC
   ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-ABC-A...

Feature request: vim keybindings j - k to navigate between options

First of all thanks for such a nice package! This is not really an issue but I wanted to suggest to allow J and K keys for navigating between options (meaning down and up respectively). I've found myself instinctively trying to use them when selecting options and it'd be nice if that worked out of the box.

merge into stdlib/REPL?

@nick-paul, you may have noticed that @KristofferC and I have been using this lovely package for interactive prompting in the new Pkg3 package manager, which we're currently in the process of moving into Julia's standard library. Since dependencies of stdlib packages need to also be in the stdlib somewhere and we are planning on continuing to use and extend the interactive REPL menu functionality, at this point it seems to make sense to include the functionality of TerminalMenus as a standard part of Julia's built-in REPL library. However, I wanted to run the idea past you first since it's your code. There are few different approaches we could take to this:

  1. We could use git filter-branch to preserve the commit history from this repo, so you would retain full credit for the code you've written (thank you!). However, since the stdlib is (for the time being) part of the main Julia repo, you'd have to make PR's to make changes to your own code, which you might not be happy about.

  2. We could instead use git subtree to make the stdlib repo essentially a mirror of this repo instead. However, I've never used git subtree and I don't know how much this will complicate things, so I'm a bit reluctant. Even if it works well technically, it may become confusing where to open issues and make PRs to the TerminalMenus code.

Anyway, that's the situation and I wanted to run it by you to see what you think.

accept other escapes for arrows

I was directed here from JuliaLang/Pkg.jl#61. I have looked at the sources and it seems that the problem is that ansi-term in Emacs sends \eOA etc as the arrow keys, TerminalMenus.jl expects \e[A etc.

While ansi-terms codes can be changed, the change is global, not buffer-specific. So if possible, it would be great if TerminalMenus.jl could also accept \eOA (up), \eOB (down), \eOC (right), \eOD (left).

Allow for preselected/default items

It would be cool to allow for some default or pre-selected item to be specified.

To me it seems most logical to add an optional argument, say default = 1, to the request function. In the case of a RadioMenu, the default option will already have the cursor on it. In the case of the MultiSelectMenu, each of the indices in default will be prechecked when displayed.

Additionally, it could be cool to have the menu object remember the last choice and use that as the default. So request will update its menu object with the last choice and this will be used as the default value next time there is a request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.