• Stars
    star
    1,284
  • Rank 36,642 (Top 0.8 %)
  • Language
    Ruby
  • License
    Other
  • Created almost 16 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A higher level command-line oriented interface.

HighLine

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

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

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.

More Repositories

1

faster_csv

FasterCSV is CSV, but faster, smaller, and cleaner.
Ruby
174
star
2

oklahoma_mixer

An full featured and robust FFI interface to Tokyo Cabinet.
Ruby
57
star
3

hanabi_umbrella

The sample application for Paul Dawson and James Gray's Lonestar Elixir 2017 talk: The NeverEnding Application.
Elixir
53
star
4

simulations

Some simulations using Elixir processes.
Elixir
44
star
5

dotfiles

My personal configuration heaven.
YASnippet
41
star
6

rrdb

A simple Ruby wrapper for RRDtool backed databases.
Ruby
38
star
7

broadsides

The application for Ruby Programming Challenge for Newbies #7 in March 2010
Ruby
23
star
8

signal_lamp

A simple tool for decoupling Ruby object systems.
Ruby
17
star
9

go_gtp

I simple wrapper for the Go Text Protocol
Ruby
14
star
10

rurses

A more Ruby style wrapper over ncurses.
Ruby
12
star
11

peril

A Jeopardy application built with Ruby on Rails
Ruby
12
star
12

advent_of_code_2016

My solutions to the 2016 Advent of Code problems: http://adventofcode.com/
Elixir
11
star
13

better_bj

A rewrite of ara's bj to make it fit in better with modern Rails
Ruby
10
star
14

rubyquiz.com

The original Ruby Quiz site.
10
star
15

browser_captcha

A CAPTCHA system for the browser instead of the user
Ruby
9
star
16

bird_of_paradise

A command-line Twitter client as an example of how to build a curses application.
Ruby
8
star
17

release_training_elixirconf_2019

https://elixirconf.com/2019/training-classes/7
C
8
star
18

canvas

A library for building simple GUI canvases to draw on.
Elixir
7
star
19

advent_of_code_2018

https://adventofcode.com/
Elixir
7
star
20

land_of_emacs_lisp

A reworking of some Land of Lisp examples in Emacs Lisp
Emacs Lisp
6
star
21

shared_room

An experiment with Scenic and multiple players
Elixir
6
star
22

icfp12

Ruby
5
star
23

genetic_algorithms_in_elixir

Working through this book: https://pragprog.com/titles/smgaelixir/genetic-algorithms-in-elixir/
Elixir
5
star
24

fictional_work.tmbundle

The start of a fiction bundle for TextMate from my Prag Pub article
5
star
25

advent_of_code_2015

My solutions for http://adventofcode.com/ in 2015
Ruby
4
star
26

sim_frost

A solution to Ruby Quiz #117
4
star
27

advent_of_code_2017

My solutions for http://adventofcode.com/2017
Elixir
4
star
28

warehouse_keeper

A Sokoban recreation using Ruby Gosu.
Ruby
4
star
29

nand2tetris

SPOILER ALERT: Don't dig into these files if you don't want to see solutions!
Ruby
4
star
30

wig-wug

An unofficial simulator for the first homework assignment (August issue) in The Rubyist.
Ruby
4
star
31

the_toy_robot

My thoughts on The Toy Robot programming challenge.
Elixir
4
star
32

mungr

A Ruby DSL for building data munging scripts
Ruby
4
star
33

chat_app

The code for my Denver Erlang and Elixir Meetup presentation in 2021.
Elixir
3
star
34

advent_of_code_2019

Solutions to the 2019 problems from https://adventofcode.com/
Elixir
3
star
35

haunted_house

This is a Ruby wrapper around the ISY-99i's (a home automation controller) REST interface.
Ruby
3
star
36

the_verse

The TradeWars game I've always dreamed of creating!
Elixir
3
star
37

advent_of_code_2020

https://adventofcode.com/2020
Elixir
3
star
38

incendiary_locator

A Minesweeper clone in Elm
Elm
3
star
39

nested_comments

This was the problem for the first Ruby Quiz Study Group, held March 14th, 2014.
Ruby
2
star
40

jitter

JEG2 on Twitter: The Simplest Twitter Client That Could Possibly Work
2
star
41

global_process_experiments

Elixir
2
star
42

ender

My IRC bot that seems to be perpetually under development
2
star
43

digital_ocean_explorations

Exploring the DigitalOcean API in Elixir
Elixir
2
star
44

live_chart

A joint experiment with @piisalie to generate live charts in Elm from Phoenix channel data
Elixir
2
star
45

tiny_tracer

Experiments with a simpler solution to the 2018 ICFP programming contest
Elixir
2
star
46

hitting_rock_bottom

These are two solutions to PuzzleNode's #11 problem that were discussed in detail in Rubies in the Rough
Ruby
2
star
47

photobooth

My toy photobooth application.
Elixir
2
star
48

icfp-2011

Our 2011 entry
Ruby
2
star
49

ipsc_2014

Our code for the 2014 IPSC contest: http://ipsc.ksp.sk/
Lua
1
star
50

daves_no_test_challenge

Solving an IPSC problem without tests.
Ruby
1
star
51

its_magic

An experiment in testing the effectiveness of Magic decks.
Elixir
1
star
52

ecto_change

An example for the Ecto maintainers
Elixir
1
star
53

crates

Experimenting with Scenic sprites.
Elixir
1
star
54

conf_feed

A sample Rails application
Ruby
1
star
55

old_peeky_blinders

A Web interface on a Raspberry PI that controls the blinds in my office.
Elixir
1
star
56

programmers_stone

JEG2's Elixir blog.
HTML
1
star
57

asciimation

This is the tool used in Codalyzed videos.
Ruby
1
star
58

proper_book_exercises

A sandbox for playing with PropEr as I read the book.
Elixir
1
star
59

icfp_2014

Our contest entry.
Ruby
1
star
60

redeliver

Experiments in an edeliver replacement.
Elixir
1
star
61

random_blades

GM tools for Blades in the Dark.
Elixir
1
star
62

buggy

Playing with some Elixir debugging techniques
Elixir
1
star
63

cluster_test

An experiment in distributed computing
Elixir
1
star
64

ICFP-2009

Our submission for the ICFP 2009 contest
Ruby
1
star
65

concurrecy_exercises

Attempts to solve [these exercises](http://whipperstacker.com/2015/10/05/3-trivial-concurrency-exercises-for-the-confused-newbie-gopher/) in multiple languages.
Elm
1
star
66

pool_experiments

Playing around with different process pooling strategies.
Elixir
1
star
67

advent_of_code_2022

https://adventofcode.com/
Elixir
1
star
68

microservice_patterns

Practicing communication patterns using AWS
Ruby
1
star
69

s3_slideshow

A viewer for my photobooth application.
Elixir
1
star
70

elm_handoff_example

Handing data through a port
Elm
1
star
71

tracing_paper

An experiment with ray tracing.
Elixir
1
star
72

minesweeper_kata

Practicing a kata from the coding dojos at Strange Loop 2015
Ruby
1
star