uiux 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da6e8648b84466d0aac78c927a315823c84b9e23
4
- data.tar.gz: 21ab68e5f0654a662dc77f7000a373a0317829ce
3
+ metadata.gz: e1c711b5fdd38488ac661673cbdce55b7bc19c83
4
+ data.tar.gz: 7de4ccf1036c00b3258879c9fe6202de7dfca635
5
5
  SHA512:
6
- metadata.gz: 98c967aadbeea734b2749839798ef4898d8e83ff47ee38a9596ad5bd0948fd420466dea81f7c686c2825f4b0d6c4b0d8408cc219f974b2c13b2ed25a640b8ea1
7
- data.tar.gz: 746df12f872281824d066617b4c5eb32b9298151793101003c7a6fa2cf4145bbbd5d8277bc8635477af9b2bcbdd08c2df354aabeadd1d4083049f514e21e78d0
6
+ metadata.gz: 9e63242501b901f80705a7aefc84a244754aa1bd4f98f46d2ae37b6fef8306d823bd417fb004817f65dc3e6433fc5ebdaae764b8631013404f52044c1c3de5c4
7
+ data.tar.gz: 95e5cb34f2d7effbd03c3fad7e17c5f4e31e6fb6396aebfbddd8177c29da87ee6da01663bfc347f78cb73ba4a44164f00ab81af36d943a178f92d9976a7fb872
data/README.md CHANGED
@@ -22,7 +22,11 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ * `UI.start` block provides start and finish headers with start and end times. This also provides better error display output which also includes the time
26
+ * `UI.heading` display a green heading with a line return before
27
+ * `UI.message` display a white message
28
+ * `UI.error` dispay a red error message
29
+ * `UI.execute` displays the command to execute, executes it and shows the output and also returns the result for potential further manipulations
26
30
 
27
31
  ## Development
28
32
 
data/lib/uiux/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module UIUX
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/uiux.rb CHANGED
@@ -8,7 +8,7 @@ module UI
8
8
  yield block
9
9
  finished
10
10
  rescue Exception => error
11
- puts "\nFailed #{'↓' * 61} #{time}".color(:red)
11
+ puts heading_with_columns("\nFailed", '↓', time).color(:red)
12
12
  raise error
13
13
  end
14
14
 
@@ -25,27 +25,40 @@ module UI
25
25
  end
26
26
 
27
27
  def self.execute(command)
28
- puts '==> '.color(:blue) + command.color('#7F461D') # Brown
28
+ puts "#{'==>'.color(:blue)} #{command.bright}"
29
29
  puts result = `#{command}`
30
30
  result
31
31
  end
32
32
 
33
33
  def self.time
34
- time = Time.respond_to?(:current) ? Time.current : Time.now.utc
35
- "🕑 #{time} 🕑 ".color(:white)
34
+ "🕑 #{Time.now.utc} 🕑 ".color(:white)
36
35
  end
37
36
 
38
37
  private
39
38
 
40
39
  def self.start_heading(message)
41
- fail if message.length > 70
42
- puts '='.color(:cyan) * 100
43
- print message.color(:cyan)
44
- puts ' ' * (70 - message.length) + time
40
+ puts heading_with_columns(nil, '='.color(:cyan), nil)
41
+ puts heading_with_columns(message.color(:cyan), ' ', time)
45
42
  end
46
43
 
47
44
  def self.finished
48
- puts "\nFinished#{' ' * 61} #{time}".color(:magenta)
49
- puts '='.color(:magenta) * 100
45
+ puts heading_with_columns("\nFinished".color(:magenta), ' ', time)
46
+ puts heading_with_columns(nil, '='.color(:magenta), nil)
47
+ end
48
+
49
+ def self.heading_with_columns(first_str, spacer_str, last_str, length = 100)
50
+ first_str = first_str ? "#{first_str} " : ''
51
+ last_str = last_str ? " #{last_str}" : ''
52
+ min_length = str_length("#{first_str}#{last_str}")
53
+ fail if min_length > length # TODO: Find a better way to handle long input strings
54
+ reps = (length - min_length) / str_length(spacer_str)
55
+ "#{first_str}#{spacer_str * reps}#{last_str}"
56
+ end
57
+
58
+ def self.str_length(str)
59
+ str = str.gsub(/\e\[\d+m/, '') # remove colors
60
+ str.chars.each_with_object('') do |char, new_str|
61
+ new_str << char unless char.ascii_only? && (char.ord < 32 || char.ord == 127)
62
+ end.length
50
63
  end
51
64
  end
data/uiux.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'rainbow', '~> 2.0'
22
+ spec.add_dependency 'awesome_print', '~> 1.0'
22
23
 
23
24
  spec.add_development_dependency 'bundler', '~> 1.10'
24
25
  spec.add_development_dependency 'rake', '~> 10.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uiux
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Endri Gjiri
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: awesome_print
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement