bogo-ui 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +80 -2
- data/lib/bogo-ui/table.rb +41 -1
- data/lib/bogo-ui/version.rb +1 -1
- data/lib/bogo-ui.rb +1 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 086eb9d9922c79a9021fe2ee6ea4b6644f472c9c
|
4
|
+
data.tar.gz: 109ea6e43441e94a1da2a78e42cc22aa1e0de5f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5719ce584cccc14b5d4143888ad728e65142fbd43cc19533774a1341b003bd157c651838826b2f813b13bd63dd4ded40c4d316d755334276b320b488a0ca8d4e
|
7
|
+
data.tar.gz: 0d0595a972d9a6d0504ed34e6744006797dc3136f2ccb43a2b1e9e94658a92d6178b6ce6e5794b0e4cdcd961008d1ce6ed5141574da9f047198b4710201499eb
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,84 @@
|
|
1
1
|
# Bogo UI
|
2
2
|
|
3
|
-
|
3
|
+
Simple CLI output helpers.
|
4
|
+
|
5
|
+
## Bogo::Ui
|
6
|
+
|
7
|
+
Output formatted information to the CLI.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require 'bogo-ui'
|
11
|
+
|
12
|
+
ui = Bogo::Ui.new(
|
13
|
+
:app_name => 'TestApp'
|
14
|
+
)
|
15
|
+
|
16
|
+
ui.info 'This is information'
|
17
|
+
ui.warn 'This is a warning'
|
18
|
+
ui.error 'This is an error'
|
19
|
+
|
20
|
+
ui.info "This is information with #{ui.color('color', :bold, :green)}"
|
21
|
+
|
22
|
+
result = ui.ask('Type a word')
|
23
|
+
ui.info "You provided: #{result}"
|
24
|
+
```
|
25
|
+
|
26
|
+
## Bogo::Ui::Table
|
27
|
+
|
28
|
+
This is a table helper. Under the hood it uses the Command Line Reporter
|
29
|
+
with a few modifications. Direct usage:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'bogo-ui'
|
33
|
+
|
34
|
+
ui = Bogo::Ui.new(:app_name => 'TestApp')
|
35
|
+
Bogo::Ui::Table.new(ui) do
|
36
|
+
table do
|
37
|
+
row do
|
38
|
+
column 'Name'
|
39
|
+
column 'Age'
|
40
|
+
end
|
41
|
+
row do
|
42
|
+
column 'me'
|
43
|
+
column '100'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end.display
|
47
|
+
```
|
48
|
+
|
49
|
+
This helper allows for appending data to an existing table. Useful
|
50
|
+
for when polling for updates and wanting to keep the existing table
|
51
|
+
structure:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
require 'bogo-ui'
|
55
|
+
|
56
|
+
ui = Bogo::Ui.new(:app_name => 'TestApp')
|
57
|
+
tbl = Bogo::Ui::Table.new(ui) do
|
58
|
+
table do
|
59
|
+
row do
|
60
|
+
column 'Name'
|
61
|
+
column 'Age'
|
62
|
+
end
|
63
|
+
row do
|
64
|
+
column 'me'
|
65
|
+
column '100'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
tbl.display
|
71
|
+
|
72
|
+
tbl.update do
|
73
|
+
row do
|
74
|
+
column 'you'
|
75
|
+
column '50'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
tbl.display
|
80
|
+
```
|
4
81
|
|
5
82
|
## Info
|
6
|
-
* Repository: https://github.com/spox/bogo-ui
|
83
|
+
* Repository: https://github.com/spox/bogo-ui
|
84
|
+
* Command Line Reporter: https://github.com/wbailey/command_line_reporter
|
data/lib/bogo-ui/table.rb
CHANGED
@@ -42,7 +42,19 @@ module Bogo
|
|
42
42
|
def table(options={})
|
43
43
|
@table = BufferedTable.new(options)
|
44
44
|
yield
|
45
|
-
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
# Override to provide buffered support
|
49
|
+
#
|
50
|
+
# @param options [Hash]
|
51
|
+
# @return [self]
|
52
|
+
def row(options={})
|
53
|
+
options[:encoding] ||= @table.encoding
|
54
|
+
@row = BufferedRow.new(options.merge(:buffer => @table.buffer))
|
55
|
+
yield
|
56
|
+
@table.add(@row)
|
57
|
+
self
|
46
58
|
end
|
47
59
|
|
48
60
|
# Output table to defined UI
|
@@ -56,6 +68,8 @@ module Bogo
|
|
56
68
|
@content.each do |tblock|
|
57
69
|
instance_exec(&tblock)
|
58
70
|
end
|
71
|
+
@table.output
|
72
|
+
@table.buffer.rewind
|
59
73
|
output = @table.buffer.read.split("\n")
|
60
74
|
output.slice!(0, @printed_lines)
|
61
75
|
@printed_lines = output.size
|
@@ -89,6 +103,32 @@ module Bogo
|
|
89
103
|
|
90
104
|
end
|
91
105
|
|
106
|
+
# Wrapper class to get desired buffering
|
107
|
+
class BufferedRow < CommandLineReporter::Row
|
108
|
+
|
109
|
+
# @return [StringIO]
|
110
|
+
attr_reader :buffer
|
111
|
+
|
112
|
+
# Create new instance and init buffer
|
113
|
+
#
|
114
|
+
# @return [self]
|
115
|
+
def initialize(options={})
|
116
|
+
@buffer = options.delete(:buffer)
|
117
|
+
super
|
118
|
+
end
|
119
|
+
|
120
|
+
# buffered puts
|
121
|
+
def puts(string)
|
122
|
+
buffer.puts(string)
|
123
|
+
end
|
124
|
+
|
125
|
+
# buffered print
|
126
|
+
def print(string)
|
127
|
+
buffer.print(string)
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
92
132
|
end
|
93
133
|
end
|
94
134
|
|
data/lib/bogo-ui/version.rb
CHANGED
data/lib/bogo-ui.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bogo-ui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Roberts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bogo
|