-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from chef/mp/add-configurable-spinner-element
Make plain-text spinner element avaialble via config Merging this, but will add a card to move the logging up the next time we want to pick up minor infra improvement .
- Loading branch information
Showing
4 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
test_results/ | ||
tags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
components/chef-workstation/lib/chef-workstation/ui/plain_text_element.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
module ChefWorkstation | ||
module UI | ||
class PlainTextElement | ||
def initialize(format, opts) | ||
@orig_format = format | ||
@format = format | ||
@output = opts[:output] | ||
end | ||
|
||
def run(&block) | ||
yield | ||
end | ||
|
||
def update(params) | ||
# SOme of this is particular to our usage - | ||
# prefix does not cause a text update, but does | ||
# change the prefix for future messages. | ||
if params.has_key?(:prefix) | ||
@format = @orig_format.gsub(":prefix", params[:prefix]) | ||
return | ||
end | ||
|
||
if @succ | ||
ind = "OK" | ||
@succ = false | ||
log_method = :info | ||
elsif @err | ||
ind = "ERR" | ||
@err = false | ||
log_method = :error | ||
else | ||
log_method = :debug | ||
ind = " - " | ||
end | ||
|
||
# Since this is a generic type, we can replace any component | ||
# name in this regex - but for now :spinner is the only component | ||
# we're standing in for. | ||
msg = @format.gsub(/:spinner/, ind) | ||
params.each_pair do |k, v| | ||
msg.gsub!(/:#{k}/, v) | ||
end | ||
ChefWorkstation::Log.send(log_method, msg) | ||
@output.puts(msg) | ||
end | ||
|
||
def error | ||
@err = true | ||
@succ = false | ||
end | ||
|
||
def success | ||
@succ = true | ||
@err = false | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters