Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Welcome to HighLine.
HighLine was designed to ease the tedious tasks of doing console input and
output with low-level methods like gets
and puts
. HighLine provides a
robust system for requesting data from a user, without needing to code all the
error checking and validation rules and without needing to convert the typed
Strings into what your program really needs. Just tell HighLine what you're
after, and let it do all the work.
See: Rubydoc.info for HighLine. Specially HighLine and HighLine::Question.
require 'highline'
# Basic usage
cli = HighLine.new
answer = cli.ask "What do you think?"
puts "You have answered: #{answer}"
# Default answer
cli.ask("Company? ") { |q| q.default = "none" }
## Disable default value hint showing
my_special_default_object = Object.new
cli.ask("Question? ") do |q|
q.default = my_special_default_object
q.default_hint_show = false
end
# Validation
cli.ask("Age? ", Integer) { |q| q.in = 0..105 }
cli.ask("Name? (last, first) ") { |q| q.validate = /\A\w+, ?\w+\Z/ }
## Validation with custom class
class ZeroToTwentyFourValidator
def self.valid?(answer)
(0..24).include? answer.to_i
end
def self.inspect
"(0..24) rule"
end
end
cli.ask("What hour of the day is it?: ", Integer) do |q|
q.validate = ZeroToTwentyFourValidator
end
## Validation with Dry::Types
## `Dry::Types` provides a `valid?` method so it can be used effortlessly
require 'dry-type'
module Types
include Dry.Types
end
cli.ask("Type an integer:", Integer) do |q|
q.validate = Types::Coercible::Integer
end
# Type conversion for answers:
cli.ask("Birthday? ", Date)
cli.ask("Interests? (comma sep list) ", lambda { |str| str.split(/,\s*/) })
# Reading passwords:
cli.ask("Enter your password: ") { |q| q.echo = false }
cli.ask("Enter your password: ") { |q| q.echo = "x" }
# ERb based output (with HighLine's ANSI color tools):
cli.say("This should be <%= color('bold', BOLD) %>!")
# Menus:
cli.choose do |menu|
menu.prompt = "Please choose your favorite programming language? "
menu.choice(:ruby) { cli.say("Good choice!") }
menu.choices(:python, :perl) { cli.say("Not from around here, are you?") }
menu.default = :ruby
end
## Using colored indices on Menus
HighLine::Menu.index_color = :rgb_77bbff # set default index color
cli.choose do |menu|
menu.index_color = :rgb_999999 # override default color of index
# you can also use constants like :blue
menu.prompt = "Please choose your favorite programming language? "
menu.choice(:ruby) { cli.say("Good choice!") }
menu.choices(:python, :perl) { cli.say("Not from around here, are you?") }
end
If you want to save some characters, you can inject/import HighLine methods on Kernel by doing the following. Just be sure to avoid name collisions in the top-level namespace.
require 'highline/import'
say "Now you can use #say directly"
For more examples see the examples/ directory of this project.
HighLine from version >= 3.0.0 requires ruby >= 3.0.0
To install HighLine, use the following command:
$ gem install highline
(Add sudo
if you're installing under a POSIX system as root)
If you're using Bundler, add this to your Gemfile:
source "https://rubygems.org"
gem 'highline'
And then run:
$ bundle
If you want to build the gem locally, use the following command from the root of the sources:
$ rake package
You can also build and install directly:
$ rake install
git clone git@github.com:YOUR-USERNAME/highline.git
cd highline
# to enter the cloned repository directory.git remote add upstream https://github.com/JEG2/highline
git fetch upstream
git checkout master
git merge upstream/master
git checkout -b your_branch
rake test
rake acceptance
pronto run
Alternatively, if you're in a Dockerised environment,
don't care about installing anything locally -- just run bin/test
instead.
git commit -am "Your commit message"
git push
Details on:
For a list of people who have contributed to the codebase, see GitHub's list of contributors.
FAQs
Unknown package
We found that highline demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.