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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3806ec515d426c9a9ce068b1a2f31d786890f7e8
4
- data.tar.gz: 19e031956c263db5be7c8e4b94503451ed76cf4a
3
+ metadata.gz: 086eb9d9922c79a9021fe2ee6ea4b6644f472c9c
4
+ data.tar.gz: 109ea6e43441e94a1da2a78e42cc22aa1e0de5f2
5
5
  SHA512:
6
- metadata.gz: 4b4143699d0bc034ab3705c221e4c0e2e7e0f4d8420e790d7ff7c6fd922cd2c842454fc02fcdd1f82220db261fa6a3772be465445656fddb229fd5d49a2ed460
7
- data.tar.gz: 7828448db39baa5c94b0655ad98e331255083a21a62b9110655f8c49e61dd8f4564e12d5ea0af231a375320bc536de9181dc66ac636e3ab7f9856948dc797e82
6
+ metadata.gz: 5719ce584cccc14b5d4143888ad728e65142fbd43cc19533774a1341b003bd157c651838826b2f813b13bd63dd4ded40c4d316d755334276b320b488a0ca8d4e
7
+ data.tar.gz: 0d0595a972d9a6d0504ed34e6744006797dc3136f2ccb43a2b1e9e94658a92d6178b6ce6e5794b0e4cdcd961008d1ce6ed5141574da9f047198b4710201499eb
data/CHANGELOG.md CHANGED
@@ -1,2 +1,6 @@
1
+ ## v0.1.2
2
+ * Fix table generation
3
+ * Add test coverage
4
+
1
5
  ## v0.1.0
2
6
  * Initial release
data/README.md CHANGED
@@ -1,6 +1,84 @@
1
1
  # Bogo UI
2
2
 
3
- A collection of UI libraries.
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
- [self]
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
 
@@ -1,6 +1,6 @@
1
1
  module Bogo
2
2
  class Ui
3
3
  # Current library version
4
- VERSION = Gem::Version.new('0.1.0')
4
+ VERSION = Gem::Version.new('0.1.2')
5
5
  end
6
6
  end
data/lib/bogo-ui.rb CHANGED
@@ -1,6 +1,3 @@
1
1
  require 'bogo'
2
+ require 'bogo-ui/ui'
2
3
  require 'bogo-ui/version'
3
-
4
- module Bogo
5
- autoload :Ui, 'bogo-ui/ui'
6
- end
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.0
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-29 00:00:00.000000000 Z
11
+ date: 2014-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bogo