GithubHelp home page GithubHelp logo

tiancheng-luo / highline Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jeg2/highline

0.0 1.0 0.0 2.1 MB

A higher level command-line oriented interface.

License: Other

Ruby 99.00% CSS 0.38% HTML 0.62%

highline's Introduction

HighLine

Build Status Build status Gem Version Code Climate Test Coverage Inline docs

Description

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.

Documentation

See: Rubydoc.info for HighLine. Specially HighLine and HighLine::Question.

Usage

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" }


# Validation

cli.ask("Age?  ", Integer) { |q| q.in = 0..105 }
cli.ask("Name?  (last, first)  ") { |q| q.validate = /\A\w+, ?\w+\Z/ }


# 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.

Requirements

HighLine from version >= 1.7.0 requires ruby >= 1.9.3

Installing

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

Contributing

  1. Open an issue
  1. Fork the repository
  1. Clone it locally
  1. Add the main HighLine repository as the upstream remote
  • cd highline # to enter the cloned repository directory.
  • git remote add upstream https://github.com/JEG2/highline
  1. Keep your fork in sync with upstream
  • git fetch upstream
  • git checkout master
  • git merge upstream/master
  1. Create your feature branch
  • git checkout -b your_branch
  1. Hack the source code, run the tests and pronto
  • rake test
  • rake acceptance
  • pronto run
  1. Commit your changes
  • git commit -am "Your commit message"
  1. Push it
  • git push
  1. Open a pull request

Details on:

The Core HighLine Team

For a list of people who have contributed to the codebase, see GitHub's list of contributors.

highline's People

Contributors

abinoam avatar jeg2 avatar practicingruby avatar yazgoo avatar matugm avatar rleber avatar presidentbeef avatar davispuh avatar stomar avatar mnzaki avatar stepheneb avatar aregic avatar lachlan avatar fredrb avatar elyscape avatar fissionxuiptz avatar kachick avatar iconoclast avatar mmihira avatar zzzzou avatar whiteleaf7 avatar roniegh avatar koic avatar km4n avatar krausefx avatar sax avatar cgorshing avatar rossmeissl avatar jordimassaguerpla avatar kevinoid avatar

Watchers

Tiancheng-Luo avatar

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.