Giter Site home page Giter Site logo

Comments (8)

abinoam avatar abinoam commented on July 1, 2024

from highline.

abinoam avatar abinoam commented on July 1, 2024

Hi @jblaine,

You can overwrite the default responses like this.

require 'highline'

cli = HighLine.new

cli.ask("A question to be validated against a lambda") do |q|
  # Some kind of validation logic
  # If lambda returns a truethy value, it's validated
  q.validate = ->(answer){ false }

  # As there's no easy way HighLine could infer what happens inside
  # the lambda, you may override the default responses.
  q.responses[:not_valid] = "Some customized message"
end

See: http://www.rubydoc.info/github/JEG2/highline/master/HighLine%2FQuestion:responses

Do you think this can help at your use case?

Unfortunatelly, this answer is a static String.

If I have some spare time I can try and see if I can make it accept a lambda so we can give a response according to user answer.

from highline.

jblaine avatar jblaine commented on July 1, 2024

@abinoam The hardcoded string response will work well enough for us for now. Thanks for the speedy reply and thanks for making highline available for everyone.

from highline.

abinoam avatar abinoam commented on July 1, 2024

Thank you for your feedback. I'll let this issue open as a reminder to me. I'll try to find time to do it.

from highline.

abinoam avatar abinoam commented on July 1, 2024

@jblaine I have just released 2.0.0-develop.13 from PR #220.
Now you can use a proc or a string.
The given user answer will be yielded/passed to the lambda/proc.
Could you give me any feedback on this?

from highline.

abinoam avatar abinoam commented on July 1, 2024

Feedback = Has this featured worked on your use case?

from highline.

jblaine avatar jblaine commented on July 1, 2024

Tried 2.0.0.pre.develop.13 and the Proc response works fine for our use case.

from highline.

abinoam avatar abinoam commented on July 1, 2024

Thanks for your feedback @jblaine! 👍

from highline.

Related Issues (20)

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.