summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md43
1 files changed, 28 insertions, 15 deletions
diff --git a/README.md b/README.md
index e8c953f..f6071e5 100644
--- a/README.md
+++ b/README.md
@@ -27,52 +27,65 @@ Documentation
See {HighLine} and {HighLine::Question} for documentation.
-Start hacking in your code with HighLine with:
+Usage
+-----
```ruby
-require 'highline/import'
-```
-Examples
---------
+require 'highline'
+
+# Basic usage
-Basic usage:
+cli = HighLine.new
+answer = cli.ask "What do you think?"
+puts "You have answered: #{answer}"
-ask("Company? ") { |q| q.default = "none" }
+
+# Default answer
+
+cli.ask("Company? ") { |q| q.default = "none" }
# Validation
-ask("Age? ", Integer) { |q| q.in = 0..105 }
-ask("Name? (last, first) ") { |q| q.validate = /\A\w+, ?\w+\Z/ }
+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:
-ask("Birthday? ", Date)
-ask("Interests? (comma sep list) ", lambda { |str| str.split(/,\s*/) })
+cli.ask("Birthday? ", Date)
+cli.ask("Interests? (comma sep list) ", lambda { |str| str.split(/,\s*/) })
# Reading passwords:
-ask("Enter your password: ") { |q| q.echo = false }
-ask("Enter your password: ") { |q| q.echo = "x" }
+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):
-say("This should be <%= color('bold', BOLD) %>!")
+cli.say("This should be <%= color('bold', BOLD) %>!")
# Menus:
-choose do |menu|
+cli.choose do |menu|
menu.prompt = "Please choose your favorite programming language? "
menu.choice(:ruby) { say("Good choice!") }
menu.choices(:python, :perl) { say("Not from around here, are you?") }
end
```
+If you want to save up some characteres, you can inject/import HighLine methods on Kernel by doing the following. Be aware to avoid name collisions at the main namespace.
+
+```ruby
+require 'highline/import'
+
+say "Now you can use #say directly"
+```
+
For more examples see the examples/ directory of this project.
Requirements