vt 0.8.0 → 0.8.1

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.
@@ -0,0 +1,7 @@
1
+ ## 0.8.1
2
+ - Bug fixing on the formate command
3
+ - Bring in code from the colorize ruby gem
4
+
5
+ ## 0.8.0
6
+ - First Draft
7
+ - There are some bugs
@@ -1,8 +1,11 @@
1
1
  require 'json'
2
+
2
3
  module Vt
3
4
  class FormatCommand
4
5
  attr_reader :raw_contract, :colored_contract, :compressed_contract
5
6
 
7
+ CIPHER_TEXT_COLOR = :yellow
8
+
6
9
  def initialize(c)
7
10
  @raw_contract = c
8
11
  end
@@ -16,9 +19,12 @@ module Vt
16
19
 
17
20
  private
18
21
 
19
-
20
22
  def contract
21
- JSON.parse(raw_contract)
23
+ JSON.parse(pretty_generated_contract)
24
+ end
25
+
26
+ def pretty_generated_contract
27
+ JSON.pretty_generate JSON.parse(raw_contract)
22
28
  end
23
29
 
24
30
  def color_vault_contents(c)
@@ -42,7 +48,7 @@ module Vt
42
48
  end
43
49
 
44
50
  def colored_vault_contents(v)
45
- contract['vaults'][v]['contents'].yellow
51
+ contract['vaults'][v]['contents'].colorize(CIPHER_TEXT_COLOR)
46
52
  end
47
53
 
48
54
  def compressed_vault_contents(v)
@@ -50,22 +56,186 @@ module Vt
50
56
  end
51
57
 
52
58
  end
53
- end
59
+ end
54
60
 
55
61
  class String
56
- def yellow
57
- colorize(33)
58
- end
59
62
 
60
- def colorize(color_code)
61
- "\e[#{color_code}m#{self}\e[0m"
62
- end
63
+ CIPHER_TEXT_CHAR_LENGTH = 60
64
+ CIPHER_TEXT_CHAR_INDENT = 18
65
+
63
66
 
64
67
  def compressed
65
- gsub(/(.{60})(?=.)/, '\1 \2').gsub(' ',"\n").gsub("\n","\n #{blank_spaces(18)}")
68
+ gsub(/(.{#{CIPHER_TEXT_CHAR_LENGTH}})(?=.)/, '\1 \2').gsub(' ',"\n").gsub("\n","\n #{blank_spaces(CIPHER_TEXT_CHAR_INDENT)}")
66
69
  end
67
70
 
68
71
  def blank_spaces(number)
69
72
  x = ''; number.times{x = x + ' '}; x;
70
73
  end
71
74
  end
75
+
76
+ # Colorize String class extension.
77
+ # This code is from https://github.com/fazibear/colorize
78
+ class String
79
+
80
+ #
81
+ # Colors Hash
82
+ #
83
+ COLORS = {
84
+ :black => 0,
85
+ :red => 1,
86
+ :green => 2,
87
+ :yellow => 3,
88
+ :blue => 4,
89
+ :magenta => 5,
90
+ :cyan => 6,
91
+ :white => 7,
92
+ :default => 9,
93
+
94
+ :light_black => 60,
95
+ :light_red => 61,
96
+ :light_green => 62,
97
+ :light_yellow => 63,
98
+ :light_blue => 64,
99
+ :light_magenta => 65,
100
+ :light_cyan => 66,
101
+ :light_white => 67
102
+ }
103
+
104
+ #
105
+ # Modes Hash
106
+ #
107
+ MODES = {
108
+ :default => 0, # Turn off all attributes
109
+ :bold => 1, # Set bold mode
110
+ :underline => 4, # Set underline mode
111
+ :blink => 5, # Set blink mode
112
+ :swap => 7, # Exchange foreground and background colors
113
+ :hide => 8 # Hide text (foreground color would be the same as background)
114
+ }
115
+
116
+ REGEXP_PATTERN = /\033\[([0-9]+);([0-9]+);([0-9]+)m(.+?)\033\[0m|([^\033]+)/m
117
+ COLOR_OFFSET = 30
118
+ BACKGROUND_OFFSET = 40
119
+
120
+ public
121
+
122
+ #
123
+ # Change color of string
124
+ #
125
+ # Examples:
126
+ #
127
+ # puts "This is blue".colorize(:blue)
128
+ # puts "This is light blue".colorize(:light_blue)
129
+ # puts "This is also blue".colorize(:color => :blue)
130
+ # puts "This is light blue with red background".colorize(:color => :light_blue, :background => :red)
131
+ # puts "This is light blue with red background".colorize(:light_blue ).colorize( :background => :red)
132
+ # puts "This is blue text on red".blue.on_red
133
+ # puts "This is red on blue".colorize(:red).on_blue
134
+ # puts "This is red on blue and underline".colorize(:red).on_blue.underline
135
+ # puts "This is blue text on red".blue.on_red.blink
136
+ # puts "This is uncolorized".blue.on_red.uncolorize
137
+ #
138
+ def colorize(params)
139
+ begin
140
+ require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32/
141
+ rescue LoadError
142
+ raise 'You must gem install win32console to use colorize on Windows'
143
+ end
144
+
145
+ self.scan(REGEXP_PATTERN).inject("") do |str, match|
146
+ match[0] ||= MODES[:default]
147
+ match[1] ||= COLORS[:default] + COLOR_OFFSET
148
+ match[2] ||= COLORS[:default] + BACKGROUND_OFFSET
149
+ match[3] ||= match[4]
150
+
151
+ if (params.instance_of?(Hash))
152
+ match[0] = MODES[params[:mode]] if params[:mode] && MODES[params[:mode]]
153
+ match[1] = COLORS[params[:color]] + COLOR_OFFSET if params[:color] && COLORS[params[:color]]
154
+ match[2] = COLORS[params[:background]] + BACKGROUND_OFFSET if params[:background] && COLORS[params[:background]]
155
+ elsif (params.instance_of?(Symbol))
156
+ match[1] = COLORS[params] + COLOR_OFFSET if params && COLORS[params]
157
+ end
158
+
159
+ str << "\033[#{match[0]};#{match[1]};#{match[2]}m#{match[3]}\033[0m"
160
+ end
161
+ end
162
+
163
+ #
164
+ # Return uncolorized string
165
+ #
166
+ def uncolorize
167
+ self.scan(REGEXP_PATTERN).inject("") do |str, match|
168
+ str << (match[3] || match[4])
169
+ end
170
+ end
171
+
172
+ #
173
+ # Return true if string is colorized
174
+ #
175
+ def colorized?
176
+ self.scan(REGEXP_PATTERN).reject do |match|
177
+ match.last
178
+ end.any?
179
+ end
180
+
181
+ #
182
+ # Make some color and on_color methods
183
+ #
184
+ COLORS.each_key do |key|
185
+ next if key == :default
186
+
187
+ define_method key do
188
+ self.colorize(:color => key)
189
+ end
190
+
191
+ define_method "on_#{key}" do
192
+ self.colorize(:background => key)
193
+ end
194
+ end
195
+
196
+ #
197
+ # Methods for modes
198
+ #
199
+ MODES.each_key do |key|
200
+ next if key == :default
201
+
202
+ define_method key do
203
+ self.colorize(:mode => key)
204
+ end
205
+ end
206
+
207
+ class << self
208
+
209
+ #
210
+ # Return array of available modes used by colorize method
211
+ #
212
+ def modes
213
+ MODES.keys
214
+ end
215
+
216
+ #
217
+ # Return array of available colors used by colorize method
218
+ #
219
+ def colors
220
+ COLORS.keys
221
+ end
222
+
223
+ #
224
+ # Display color matrix with color names
225
+ #
226
+ def color_matrix(txt = '[X]')
227
+ size = String.colors.length
228
+ String.colors.each do |color|
229
+ String.colors.each do |back|
230
+ print txt.colorize(:color => color, :background => back)
231
+ end
232
+ puts " < #{color}"
233
+ end
234
+ String.colors.reverse.each_with_index do |back, index|
235
+ puts "#{"|".rjust(txt.length)*(size-index)} < #{back}"
236
+ end
237
+ ''
238
+ end
239
+
240
+ end
241
+ end
@@ -1,3 +1,3 @@
1
1
  module Vt
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
  end
@@ -2,11 +2,17 @@
2
2
  "header": {},
3
3
  "vaults": {
4
4
  "test_vault":{
5
- "description":"A Simple Message",
6
- "fill_with": "EXTERNAL_INPUT['VAULT_MESSAGE']",
5
+ "fill_with": "RANDOM_NUMBER",
7
6
  "lock_with": "UNLOCKED",
8
7
  "unlock_with": "UNLOCKED",
9
8
  "contents": ""
10
- }
9
+ },
10
+ "second_vault":{
11
+ "description":"A Simple Message",
12
+ "fill_with": "EXTERNAL_INPUT['VAULT_MESSAGE']",
13
+ "lock_with": "KEY['test_vault']",
14
+ "unlock_with": "KEY['test_vault']",
15
+ "contents": ""
16
+ }
11
17
  }
12
18
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-01 00:00:00.000000000 Z
12
+ date: 2014-09-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: vault-tree
@@ -69,8 +69,8 @@ extra_rdoc_files: []
69
69
  files:
70
70
  - .gitignore
71
71
  - .ruby-version
72
+ - CHANGE_LOG.md
72
73
  - Gemfile
73
- - Gemfile.lock
74
74
  - LICENSE.txt
75
75
  - README.md
76
76
  - Rakefile