Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Viet (Drake) Tran
    @tiev
    I see directory templates contains many generated folders for each command. What are templates used for?
    Piotr Murach
    @piotrmurach
    @tiev The idea with templates is that you can create file templates using the erb engine, populate them with data from the command. This is exactly what teletype is doing to setup all the files for you. In future I will add some glue code to make it obvious what is happening here and create some empty template files.
    @coreynwops_gitlab Ok, if I understand you correctly, you want something that converts arbitrary objects/hashes into another format json/yaml you name it. That would be cool to have but this is not specific to terminal apps and hence won't fit into tty namespace. However, if you want to convert tabular data into different formats then I can surely see this as part of https://github.com/piotrmurach/tty-table
    Viet (Drake) Tran
    @tiev
    @piotrmurach make sense, I also intend to use it like that
    Felix Wolfsteller
    @fwolfst
    hey there. Question about TTY::Command . I want to use the the #run(command, *[option, ..., argument, ...])- style to leverage automatic shell escaping. There is some cases where I DONT want the arguments and options to be escaped, though. Is there any way to do this.
    I dont have a real-world-issue with it right now, its more about the API and consistency of calling stuff. E.g. mysql:
    TTY::Command.new.run(:mysql, *["--user", conf.user, "--password=#{conf.password}"], in: open("/tmp/stuff.sql"))
    I prefer the above form over TTY::Command.new.run("mysql --user #{conf.user} --password=#{...}") (direct string interpolation)
    Felix Wolfsteller
    @fwolfst
    Now, this is a special case bacause of the mysql-command being bitchy. It does not accept --password mypass, but requires the equal sign and no space, like --passwod=mypass. This is the case only for this option, probably because of security considerations. Because of this, I cannot use the first shown example, because cmd.run(:mysql, *["--password=#{'mypass']") will result in mysql --password\=mypass. Usually that is what you want: nicely escaped! But in rare cases like this one, I dont want it. Same is true for the following command mysql -uuser -ppass mydb -e 'SHOW TABLES'. As SHOW TABLES has a space inside, it will be escaped and not be correcty parsed by mysql.
    Should I open an issue to discuss a possible API design if there is no workaround or overlooked solution?
    Samuel Williams
    @ioquatix
    @piotrmurach hey how is it going?
    Samuel Williams
    @ioquatix
    @fwolfst I think you've misunderstood how it works.
    @fwolfst I believe the command is basically the same as system(...). If you specify one string, it gets executed using the shell. If you provide multiple arguments, they get provided to the OS level execve.
    Felix Wolfsteller
    @fwolfst
    @ioquatix yes. I was asking if an extension makes sense and if we should discuss API details for that, so that it can overcome the execve conventions. Or am I still misunderstanding something?
    Samuel Williams
    @ioquatix
    I'm not sure why cmd.run(:mysql, *["--password=#{'mypass']") is escaping the = that seems very wrong to me
    system("mysql", "-e", "SHOW TABLES") should work just fine
    execve shouldn't be touching the args, they are passed directly through to the child process
    Viet (Drake) Tran
    @tiev
    @piotrmurach Is there any gem to help open the editor to edit a content and get result when quit the editor? Similar with how we can edit commit messages
    I saw the tty-editor but seems it cannot do that
    Viet (Drake) Tran
    @tiev
    ahh, I've figured it out, just when the editor is exited, we can get the changed file
    nivpgir
    @nivpgir
    hi, is there a way to make a prompt work inside a box? I tried the trivial: box = TTY::Box.frame(width: 30, height: 10) {prompt.multi_select("Select drinks?", choices)}, and it crashed
    ok I actually get why it crashed, the content of the block should evaluate to a string (duh....) but my question stands, is there a way?
    Minh
    @minhl337
    how do i ask users for a date and set a reminder like (yyyy-mm-dd)?
    Danny Wakeling
    @Dwake5
    Hello. Im making a CLI choose your own adventure. Is there a library/gem on here for making a constant top bar to which I can display stats in?
    Viet (Drake) Tran
    @tiev
    @Minh input for each field separately
    @Dwake5 you must get terminal size and draw box for the whole terminal. Tty has thay two features
    Piotr Murach
    @piotrmurach
    @Dwake5 You can use tty-box to draw a status box and center it with tty-screen.
    Piotr Murach
    @piotrmurach

    @minhl337 One way I can think of doing this:

    prompt = TTY::Prompt.new
    prompt.ask("Date of birth (yyyy-mm-dd)?") do |q|
      q.validate(/\A\d{4}-d{2}-d{2}\Z/)
      q.messages[:valid?] = "Invalid date format"
      q.convert :datetime
    end

    This will validate correct format and convert the input into DateTime for you.

    @nivpgir Currently there is no way, tty-prompt was developed much earlier than tty-box and cannot be absolutely positioned inside terminal to allow it to be wrapped inside a box.
    nivpgir
    @nivpgir
    I see, I've moved on from it anyways, but thanks
    Ben
    @benjamin-hull
    Hey folks ... I've hit what I think is a simple snag working with tty-table for the first time: I'm trying to show the first few rows of a loaded CSV in a table. Everything seems to work fine, except that render yields... nothing
    If I pause within the script, between table creation and render, and then call render myself, I get a string with what looks the table in it as the response, but nothing is actually output to the terminal. This is within a rake task.
    Am I missing something obvious?
    Ben
    @benjamin-hull
    So yeah, it was kinda obvious: you gotta puts if you want to puts! :)
    Piotr Murach
    @piotrmurach
    @benjamin-hull That was on purpose to allow greater flexibility. The table gets rendered to whatever you decide, this can be standard terminal stream or a file. The tty gems main focus is terminal but really they have wider applicability in different contexts.
    Matheus Silva Santos de Oliveira
    @matheussilvasantos
    Hello, how can I use teletype without adding a command?
    I would like to make an app like ls or mkdir that we call without passing a command.
    Piotr Murach
    @piotrmurach
    @matheussilvasantos I would generate a new gem with teletype and add command, so for example, you get mkdir create and then in cli.rb use default_command :create to instruct your binary to run create command when no command is provided. It's a bit roundabout way but it should work and gives you benefits of writing tests and more.
    Tay Kang Sheng
    @TayKangSheng

    Hello. I found a behaviour about default option for multiline input in tty-prompt and am wondering whether this is deliberate? In the spec, it states that the returned value for a multiline question with default option enabled returns an empty array. If this is deliberate, can I know what is the rationale behind this design?

    https://github.com/piotrmurach/tty-prompt/blob/master/spec/unit/multiline_spec.rb#L19

    Piotr Murach
    @piotrmurach
    Hi @TayKangSheng You're right it makes little sense to have a default option that isn't used. I'd open an issue on GitHub, or even better if you have a minute to cook up a fix and submit PR that would be really great.
    Tay Kang Sheng
    @TayKangSheng
    sure thing! thanks for the clarifacton :)
    JohnConfidence
    @JohnConfidence
    Hey! Does tty-prompt or tty-table play well with Curses? I ask because I couldn't find a way to refresh the screen if the content of a table or prompt changes. Would I be able to run tty-prompt or tty-table within a curses window and call Curses.refresh to get content to update?
    Piotr Murach
    @piotrmurach
    @JohnConfidence TTY components don't use curses so that they can work on all platforms. Can you mix the two? I think you can but you will have to test yourself. If you wish to refresh the terminal window, you can use ANSI codes, for example, tty-cursor has clear_screen code. I hope this helps.
    Robert Fletcher
    @mockdeep
    Hey there, I'm trying to combine tty-progressbar with tty-prompt.
    Any advice on how to make them play nice together?
    Essentially, I want to show a progressbar above a prompt asking the user for input.
    Or below, doesn't really matter.
    Robert Fletcher
    @mockdeep
    nm, think I figured it out.
    Adding a \n to the format string seems to have done the trick.
    TTY::ProgressBar.new("progress [:bar]\n")
    Side note, render seems like it might be good to have as public api.