https://github.com/rvm/rvm2-ui
Abstract user interface handling in RVM2
https://github.com/rvm/rvm2-ui
Last synced: 9 months ago
JSON representation
Abstract user interface handling in RVM2
- Host: GitHub
- URL: https://github.com/rvm/rvm2-ui
- Owner: rvm
- License: other
- Created: 2013-12-03T19:53:33.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2015-05-17T17:54:21.000Z (over 10 years ago)
- Last Synced: 2025-04-26T23:09:52.762Z (9 months ago)
- Language: Ruby
- Size: 297 KB
- Stars: 3
- Watchers: 21
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rvm2::Ui
[](http://rubygems.org/gems/rvm2-ui)
[](https://codeclimate.com/github/rvm/rvm2-ui)
[](https://coveralls.io/r/rvm/rvm2-ui?branch=master)
[](https://travis-ci.org/rvm/rvm2-ui)
[](https://gemnasium.com/rvm/rvm2-ui)
[](http://rubydoc.info/gems/rvm2-ui/frames)
## Example output
Using `:console` handler:
[ ] Command 1
Log output 1
[x] Command 2
[ ] Command 3
Log output 2
[v] Command 3
[v] Command 1
## Installation
Get the gem:
gem install rvm2-ui
Load it:
require 'rvm2/ui'
## Usage
Different handlers can be loaded using `pluginator` group `rvm2` type `ui/output`:
Rvm2::Ui.get(type = :console, rvm2_plugins = nil, *args)
the `args` will be passed to the handler constructor.
To get the default console output:
@ui = Rvm2::Ui.get
## Wrapping code blocks
The `command` will produce checklist like item:
@ui.command('display name') do
do_something
end
Example output with `:console` output - before finish:
[ ] Group 1
after finish:
[v] Group 1
## Logging output
The `log` allows giving messages, warnings and errors to user:
log(message, type = :log)
Supported types are `:log`, `:warn`, `:warn_important`, `:error`, any other type might be supported
or should be handled as `:log` with the capitalized `type` as prefix.
Example:
@ui.log("something went wrong", :error)
Would produce with console:
Error: something went wrong
## Handling extra outputs
In some cases like running shell commands an `stdout` and `stderr` objects are available with `IO`
interface allowing proper output handling (not injecting text in random places):
@ui.command("test") do
@ui.stderr.puts("debugging output")
end
would produce with `:console`:
[ ] test
debugging output
[v] test
## Combining multiple outputs
In some cases it might be useful to send the same output to different targets like UI and log:
Rvm2::UI.multi(rvm2_plugins)
Example use:
@ui = Rvm2::UI.multi
@ui.add(:console)
@ui.add(:log, "my_app.log")
@ui.log("text")
@ui.remove # removes the last added logger
Example - temporarily use logger:
@ui = Rvm2::UI.multi
@ui.add(:console)
@ui.with(:log, "my_app.log") do
@ui.log("text")
end
In both examples the output will be written to both standard output and log file.