Module | Commander::UI |
In: |
lib/commander/user_interaction.rb
|
Prompt an editor for input. Optionally supply initial input which is written to the editor.
preferred_editor can be hinted.
ask_editor # => prompts EDITOR with no input ask_editor('foo') # => prompts EDITOR with default text of 'foo' ask_editor('foo', 'mate -w') # => prompts TextMate with default text of 'foo'
Find an editor available in path. Optionally supply the preferred editor. Returns the name as a string, nil if none is available.
‘Say’ something using the specified color
color 'I am blue', :blue color 'I am bold', :bold color 'White on Red', :white, :on_red
You may use: * color: black blue cyan green magenta red white yellow * style: blink bold clear underline * highligh: on_<color>
Converse with speech recognition.
Currently a "poorman‘s" DSL to utilize applescript and the MacOS speech recognition server.
case converse 'What is the best food?', :cookies => 'Cookies', :unknown => 'Nothing' when :cookies speak 'o.m.g. you are awesome!' else case converse 'That is lame, shall I convince you cookies are the best?', :yes => 'Ok', :no => 'No', :maybe => 'Maybe another time' when :yes speak 'Well you see, cookies are just fantastic.' else speak 'Ok then, bye.' end end
Normalize IO streams, allowing for redirection of input and/or output, for example:
$ foo # => read from terminal I/O $ foo in # => read from 'in' file, output to terminal output stream $ foo in out # => read from 'in' file, output to 'out' file $ foo < in > out # => equivalent to above (essentially)
Optionally a block may be supplied, in which case IO will be reset once the block has executed.
command :foo do |c| c.syntax = 'foo [input] [output]' c.when_called do |args, options| # or io(args.shift, args.shift) io *args str = $stdin.gets puts 'input was: ' + str.inspect end end
‘Log’ an action to the terminal. This is typically used for verbose output regarding actions performed. For example:
create path/to/file.rb remove path/to/old_file.rb remove path/to/old_file2.rb
Ask the user for a password. Specify a custom message other than ‘Password: ’ or override the default mask of ’*’.
Output progress while iterating arr.
uris = %w( http://vision-media.ca http://google.com ) progress uris, :format => "Remaining: :time_remaining" do |uri| res = open uri end
‘Say’ something using the ERROR color (red).
say_error 'Everything is not fine' say_error 'It is not ok', 'This is not ok too'
‘Say’ something using the OK color (green).
say_ok 'Everything is fine' say_ok 'It is ok', 'This is ok too'
‘Say’ something using the WARNING color (yellow).
say_warning 'This is a warning' say_warning 'Be careful', 'Think about it'
Speak message using voice at a speaking rate of rate
Voice defaults to ‘Alex’, which is one of the better voices. Speaking rate defaults to 175 words per minute
speak 'What is your favorite food? ' food = ask 'favorite food?: ' speak "Wow, I like #{food} too. We have so much in common." speak "I like #{food} as well!", "Victoria", 190