Project

rvm2-ui

0.0
No commit activity in last 3 years
No release in over 3 years
Abstract user interface handling in RVM2
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Rvm2::Ui

Gem Version Code Climate Coverage Status Build Status Dependency Status Documentation

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.