bogo-ui 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3806ec515d426c9a9ce068b1a2f31d786890f7e8
4
+ data.tar.gz: 19e031956c263db5be7c8e4b94503451ed76cf4a
5
+ SHA512:
6
+ metadata.gz: 4b4143699d0bc034ab3705c221e4c0e2e7e0f4d8420e790d7ff7c6fd922cd2c842454fc02fcdd1f82220db261fa6a3772be465445656fddb229fd5d49a2ed460
7
+ data.tar.gz: 7828448db39baa5c94b0655ad98e331255083a21a62b9110655f8c49e61dd8f4564e12d5ea0af231a375320bc536de9181dc66ac636e3ab7f9856948dc797e82
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## v0.1.0
2
+ * Initial release
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,25 @@
1
+ # Contributing
2
+
3
+ ## Branches
4
+
5
+ ### `master` branch
6
+
7
+ The master branch is the current stable released version.
8
+
9
+ ### `develop` branch
10
+
11
+ The develop branch is the current edge of development.
12
+
13
+ ## Pull requests
14
+
15
+ * https://github.com/spox/bogo-ui/pulls
16
+
17
+ Please base all pull requests of the `develop` branch. Merges to
18
+ `master` only occur through the `develop` branch. Pull requests
19
+ based on `master` will likely be cherry picked.
20
+
21
+ ## Issues
22
+
23
+ Need to report an issue? Use the github issues:
24
+
25
+ * https://github.com/spox/bogo-ui/issues
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2014 Chris Roberts
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # Bogo UI
2
+
3
+ A collection of UI libraries.
4
+
5
+ ## Info
6
+ * Repository: https://github.com/spox/bogo-ui
data/bogo-ui.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib/'
2
+ require 'bogo-ui/version'
3
+ Gem::Specification.new do |s|
4
+ s.name = 'bogo-ui'
5
+ s.version = Bogo::Ui::VERSION.version
6
+ s.summary = 'UI Helper libraries'
7
+ s.author = 'Chris Roberts'
8
+ s.email = 'code@chrisroberts.org'
9
+ s.homepage = 'https://github.com/spox/bogo-ui'
10
+ s.description = 'UI Helper libraries'
11
+ s.require_path = 'lib'
12
+ s.license = 'Apache 2.0'
13
+ s.add_dependency 'bogo'
14
+ s.add_dependency 'command_line_reporter'
15
+ s.add_dependency 'paint'
16
+ s.files = Dir['lib/**/*'] + %w(bogo-ui.gemspec README.md CHANGELOG.md CONTRIBUTING.md LICENSE)
17
+ end
@@ -0,0 +1,95 @@
1
+ require 'bogo-ui'
2
+ require 'command_line_reporter'
3
+
4
+ module Bogo
5
+
6
+ class Ui
7
+ # Table output helper
8
+ class Table
9
+
10
+ include CommandLineReporter
11
+
12
+ # @return [Bogo::Ui]
13
+ attr_reader :ui
14
+ # @return [Array<Proc>]
15
+ attr_reader :table
16
+
17
+ # Create a new instance
18
+ #
19
+ # @param ui [Bogo::Ui]
20
+ # @yield table content
21
+ # @return [self]
22
+ def initialize(ui, &block)
23
+ @ui = ui
24
+ @base = block
25
+ @content = []
26
+ @printed_lines = 0
27
+ end
28
+
29
+ # Update the table content
30
+ #
31
+ # @yield table content
32
+ # @return [self]
33
+ def update(&block)
34
+ @content << block
35
+ self
36
+ end
37
+
38
+ # Override to provide buffered support
39
+ #
40
+ # @param options [Hash]
41
+ # @return [self]
42
+ def table(options={})
43
+ @table = BufferedTable.new(options)
44
+ yield
45
+ [self]
46
+ end
47
+
48
+ # Output table to defined UI
49
+ #
50
+ # @return [self]
51
+ # @note can be called multiple times to print table updates
52
+ def display
53
+ # init the table
54
+ instance_exec(&@base)
55
+ # load the table
56
+ @content.each do |tblock|
57
+ instance_exec(&tblock)
58
+ end
59
+ output = @table.buffer.read.split("\n")
60
+ output.slice!(0, @printed_lines)
61
+ @printed_lines = output.size
62
+ ui.puts output.join("\n")
63
+ self
64
+ end
65
+
66
+ # Wrapper class to get desired buffering
67
+ class BufferedTable < CommandLineReporter::Table
68
+
69
+ # @return [StringIO]
70
+ attr_reader :buffer
71
+
72
+ # Create new instance and init buffer
73
+ #
74
+ # @return [self]
75
+ def initialize(*args)
76
+ @buffer = StringIO.new
77
+ super
78
+ end
79
+
80
+ # buffered puts
81
+ def puts(string)
82
+ buffer.puts(string)
83
+ end
84
+
85
+ # buffered print
86
+ def print(string)
87
+ buffer.print(string)
88
+ end
89
+
90
+ end
91
+
92
+ end
93
+ end
94
+
95
+ end
data/lib/bogo-ui/ui.rb ADDED
@@ -0,0 +1,115 @@
1
+ require 'bogo-ui'
2
+ require 'paint'
3
+
4
+ module Bogo
5
+ # CLI UI helper
6
+ class Ui
7
+
8
+ autoload :Table, 'bogo-ui/table'
9
+
10
+ # @return [Truthy, Falsey]
11
+ attr_accessor :colorize
12
+ # @return [String]
13
+ attr_accessor :application_name
14
+
15
+ # Build new UI instance
16
+ #
17
+ # @param args [Hash]
18
+ # @option args [String] :app_name name of application
19
+ # @option args [TrueClass, FalseClass] :colors enable/disable colors
20
+ # @option args [IO] :output_to IO to write
21
+ # @return [self]
22
+ def initialize(args={})
23
+ @application_name = args.fetch(:app_name)
24
+ @colorize = args.fetch(:colors, true)
25
+ @output_to = args.fetch(:output_to, $stdout)
26
+ end
27
+
28
+ # Output directly
29
+ #
30
+ # @param string [String]
31
+ # @return [String]
32
+ def puts(string='')
33
+ @output_to.puts string
34
+ string
35
+ end
36
+
37
+ # Output directly
38
+ #
39
+ # @param string [String]
40
+ # @return [String]
41
+ def print(string='')
42
+ @output_to.print string
43
+ string
44
+ end
45
+
46
+ # Output information string
47
+ #
48
+ # @param string [String]
49
+ # @return [String]
50
+ def info(string, *args)
51
+ output_method = args.include?(:nonewline) ? :print : :puts
52
+ self.send(output_method, "#{color("[#{application_name}]:", :green)} #{string}")
53
+ string
54
+ end
55
+
56
+ # Format warning string
57
+ #
58
+ # @param string [String]
59
+ # @return [String]
60
+ def warn(string, *args)
61
+ output_method = args.include?(:nonewline) ? :print : :puts
62
+ self.send(output_method, "#{color('[WARN]:', :yellow, :bold)} #{string}")
63
+ string
64
+ end
65
+
66
+ # Format error string
67
+ #
68
+ # @param string [String]
69
+ # @return [String]
70
+ def error(string, *args)
71
+ output_method = args.include?(:nonewline) ? :print : :puts
72
+ self.send(output_method, "#{color('[ERROR]:', :red, :bold)} #{string}")
73
+ string
74
+ end
75
+
76
+ # Colorize string
77
+ #
78
+ # @param string [String]
79
+ # @param args [Symbol]
80
+ # @return [String]
81
+ def color(string, *args)
82
+ if(colorize)
83
+ Paint[string, *args]
84
+ else
85
+ string
86
+ end
87
+ end
88
+
89
+ # Prompt for question and receive answer
90
+ #
91
+ # @param question [String]
92
+ # @param default [String]
93
+ # @return [String]
94
+ def ask(question, default=nil)
95
+ string = question.dup
96
+ if(default)
97
+ string << " [#{default}]"
98
+ end
99
+ result = nil
100
+ until(result)
101
+ info "#{string}: ", :nonewline
102
+ result = $stdin.gets.strip
103
+ if(result.empty? && default)
104
+ result = default
105
+ end
106
+ if(result.empty?)
107
+ error 'Please provide a value'
108
+ result = nil
109
+ end
110
+ end
111
+ result
112
+ end
113
+
114
+ end
115
+ end
@@ -0,0 +1,6 @@
1
+ module Bogo
2
+ class Ui
3
+ # Current library version
4
+ VERSION = Gem::Version.new('0.1.0')
5
+ end
6
+ end
data/lib/bogo-ui.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'bogo'
2
+ require 'bogo-ui/version'
3
+
4
+ module Bogo
5
+ autoload :Ui, 'bogo-ui/ui'
6
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bogo-ui
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Roberts
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bogo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: command_line_reporter
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: paint
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: UI Helper libraries
56
+ email: code@chrisroberts.org
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - CHANGELOG.md
62
+ - CONTRIBUTING.md
63
+ - LICENSE
64
+ - README.md
65
+ - bogo-ui.gemspec
66
+ - lib/bogo-ui.rb
67
+ - lib/bogo-ui/table.rb
68
+ - lib/bogo-ui/ui.rb
69
+ - lib/bogo-ui/version.rb
70
+ homepage: https://github.com/spox/bogo-ui
71
+ licenses:
72
+ - Apache 2.0
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.2.2
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: UI Helper libraries
94
+ test_files: []
95
+ has_rdoc: