nicinfo 1.3.0.pre.alpha2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1541e4e748c2ac0eeddfefd4288d65ea85af1826
4
- data.tar.gz: 49e3d7584b192966fe458b2cd57911d4e48d244e
3
+ metadata.gz: d5fa366b19d52c697ed3b9beb65369186526be04
4
+ data.tar.gz: 902ebca0583c04b04a124f42ea3dfb76d9addbe5
5
5
  SHA512:
6
- metadata.gz: 8a0849a883b4cd8339ee447054c1dbcd5638403b7e75038c507c8dcb6a48a4accacb862c005fa45da22c93590072502478b9011461b0a586cc7ecd0277a8ef55
7
- data.tar.gz: cacddfe85ad2b640fd8b7622ca098dd7f3c4abca3e5245fdedf0c377935b3364395cb0b74ff272d2845f3b49f0b83f1495cb122f2ae71c668a85afbc0a42269b
6
+ metadata.gz: 4690149f62fc7a1c8fd1b91af76544ea64ed4373cf95b1b6f0633ba48f12fcc89cc37ca2e3f365ceb6f5a094449a3b3a625fca5a52990911da3d0a110d22d1c6
7
+ data.tar.gz: a43cdd24bcae1d910a97e92722e732cac56ab33b28b524b15b399ce8821281829e1d8503777776dec1bd962578db29364a6590ba04c04233e289b3bd181e2e5a
@@ -47,15 +47,15 @@ module NicInfo
47
47
  def display
48
48
  @config.logger.start_data_item
49
49
  @config.logger.data_title "[ AS NUMBER ]"
50
- @config.logger.terse "Handle", NicInfo::get_handle( @objectclass )
50
+ @config.logger.terse "Handle", NicInfo::get_handle( @objectclass ), NicInfo::AttentionType::SUCCESS
51
51
  @config.logger.extra "Object Class Name", NicInfo::get_object_class_name( @objectclass )
52
52
  endNum = NicInfo.get_endAutnum @objectclass
53
53
  startNum = NicInfo.get_startAutnum @objectclass
54
54
  if endNum
55
- @config.logger.terse "Start AS Number", startNum
56
- @config.logger.terse "End AS Number", endNum
55
+ @config.logger.terse "Start AS Number", startNum, NicInfo::AttentionType::SUCCESS
56
+ @config.logger.terse "End AS Number", endNum, NicInfo::AttentionType::SUCCESS
57
57
  else
58
- @config.logger.terse "AS Number", startNum
58
+ @config.logger.terse "AS Number", startNum, NicInfo::AttentionType::SUCCESS
59
59
  end
60
60
  @config.logger.extra "Name", NicInfo.get_name( @objectclass )
61
61
  @config.logger.terse "Country", NicInfo.get_country( @objectclass )
@@ -101,7 +101,7 @@ module NicInfo
101
101
  if config_version == nil || config_version < NicInfo::CONFIG_VERSION
102
102
  # if a reset hasn't been asked for
103
103
  if !@options.reset_config
104
- @logger.mesg( "Your configuration is old. Use --reset to create a new one.")
104
+ @logger.mesg( "Your configuration is old. Use --reset to create a new one.", NicInfo::AttentionType::ERROR )
105
105
  end
106
106
  end
107
107
  end
@@ -224,6 +224,9 @@ module NicInfo
224
224
  @logger.auto_wrap=output[ NicInfo::AUTO_WRAP ]
225
225
  @logger.default_width=output[ NicInfo::DEFAULT_WIDTH ]
226
226
  @logger.detect_width=output[ NicInfo::DETECT_WIDTH ]
227
+
228
+ @logger.color_scheme = output[ NicInfo::COLOR_SCHEME ]
229
+ @logger.validate_color_scheme
227
230
  end
228
231
 
229
232
  def self.clean
@@ -233,7 +236,7 @@ module NicInfo
233
236
  end
234
237
 
235
238
  def self.formulate_app_data_dir
236
- if RUBY_PLATFORM =~ /win32/
239
+ if Gem.win_platform?
237
240
  data_dir = File.join(ENV['APPDATA'], "NicInfo")
238
241
  elsif RUBY_PLATFORM =~ /linux/
239
242
  data_dir = File.join(ENV['HOME'], ".NicInfo")
@@ -284,6 +287,13 @@ output:
284
287
  # or cannot be detected
285
288
  default_width: 80
286
289
 
290
+ # The color scheme to use. Possible values are
291
+ # - DARK for terminals with dark background
292
+ # - LIGHT for terminals with light background
293
+ # - NONE for no color
294
+ # color is turned off automatically if a pager is used and the pager is not 'less'.
295
+ color_scheme: DARK
296
+
287
297
  cache:
288
298
 
289
299
  # The maximum age an item from the cache will be used.
@@ -18,7 +18,7 @@
18
18
 
19
19
  module NicInfo
20
20
 
21
- VERSION = "1.3.0-alpha2"
21
+ VERSION = "1.3.0"
22
22
  VERSION_LABEL = "NicInfo v." + VERSION
23
23
  COPYRIGHT = "Copyright (c) 2011-2017 American Registry for Internet Numbers (ARIN)"
24
24
  CONFIG_VERSION = 4
@@ -63,6 +63,7 @@ module NicInfo
63
63
  AUTO_WRAP = "auto_wrap"
64
64
  DETECT_WIDTH = "detect_width"
65
65
  DEFAULT_WIDTH = "default_width"
66
+ COLOR_SCHEME = "color_scheme"
66
67
  CACHE = "cache"
67
68
  CACHE_EXPIRY = "cache_expiry"
68
69
  CACHE_EVICTION = "cache_eviction"
@@ -144,7 +144,7 @@ module NicInfo
144
144
  end
145
145
  num_count = 1
146
146
  @logger.start_data_item if print_tree
147
- @logger.prose( @data_amount, "[ RESPONSE DATA ]", " ")
147
+ @logger.prose( @data_amount, "[ RESPONSE DATA ]", " ", NicInfo::AttentionType::SUCCESS )
148
148
  @roots.each do |root|
149
149
  if annotate
150
150
  if root.alert
@@ -157,7 +157,7 @@ module NicInfo
157
157
  else
158
158
  s = root.to_s
159
159
  end
160
- retval = @logger.log_tree_item( @data_amount, s )
160
+ retval = @logger.log_tree_item( @data_amount, s, NicInfo::AttentionType::SUCCESS )
161
161
  if annotate
162
162
  prefix = " "
163
163
  child_num = 1
@@ -193,7 +193,7 @@ module NicInfo
193
193
  child_num = 0
194
194
  end
195
195
  prefix = prefix.tr( "`", " ") + spacer + ( node == parent.children.last ? "`" : "|" )
196
- @logger.log_tree_item( @data_amount, prefix + num_str + node.to_s )
196
+ @logger.log_tree_item( @data_amount, prefix + num_str + node.to_s, NicInfo::AttentionType::SUCCESS )
197
197
  node.children.each do |child|
198
198
  rprint( child_num, node, child, prefix )
199
199
  child_num += 1 if child_num > 0
@@ -140,10 +140,10 @@ module NicInfo
140
140
  def display
141
141
  @config.logger.start_data_item
142
142
  @config.logger.data_title "[ DOMAIN ]"
143
- @config.logger.terse "Handle", NicInfo::get_handle( @objectclass )
143
+ @config.logger.terse "Handle", NicInfo::get_handle( @objectclass ), NicInfo::AttentionType::SUCCESS
144
144
  @config.logger.extra "Object Class Name", NicInfo::get_object_class_name( @objectclass )
145
- @config.logger.terse "Domain Name", NicInfo::get_ldhName( @objectclass )
146
- @config.logger.datum "I18N Domain Name", NicInfo::get_unicodeName( @objectclass )
145
+ @config.logger.terse "Domain Name", NicInfo::get_ldhName( @objectclass ), NicInfo::AttentionType::SUCCESS
146
+ @config.logger.datum "I18N Domain Name", NicInfo::get_unicodeName( @objectclass ), NicInfo::AttentionType::SUCCESS
147
147
  variants = @objectclass[ "variants" ]
148
148
  variant_no = 1
149
149
  variants.each do |variant|
@@ -282,20 +282,20 @@ module NicInfo
282
282
  def display
283
283
  @config.logger.start_data_item
284
284
  @config.logger.data_title "[ ENTITY ]"
285
- @config.logger.terse "Handle", NicInfo::get_handle( @objectclass )
285
+ @config.logger.terse "Handle", NicInfo::get_handle( @objectclass ), NicInfo::AttentionType::SUCCESS
286
286
  @config.logger.extra "Object Class Name", NicInfo::get_object_class_name( @objectclass )
287
287
  @jcard.fns.each do |fn|
288
- @config.logger.terse "Name", fn
288
+ @config.logger.terse "Name", fn, NicInfo::AttentionType::SUCCESS
289
289
  end
290
290
  @jcard.names.each do |n|
291
- @config.logger.extra "Name", n
291
+ @config.logger.extra "Name", n, NicInfo::AttentionType::SUCCESS
292
292
  end
293
293
  @jcard.orgs.each do |org|
294
294
  item_value = org.names.join( ", " )
295
295
  if !org.type.empty?
296
296
  item_value << " ( #{org.type.join( ", " )} )"
297
297
  end
298
- @config.logger.terse "Organization", item_value
298
+ @config.logger.terse "Organization", item_value, NicInfo::AttentionType::SUCCESS
299
299
  end
300
300
  @jcard.titles.each do |title|
301
301
  @config.logger.extra "Title", title
@@ -33,7 +33,7 @@ module NicInfo
33
33
  if title == nil
34
34
  title = ""
35
35
  end
36
- @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "[ ERROR ]", title
36
+ @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "[ ERROR ]", title, NicInfo::AttentionType::ERROR
37
37
  @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "Code", ec[ "errorCode" ]
38
38
  description = ec[ "description" ]
39
39
  i = 1
data/lib/nicinfo/ip.rb CHANGED
@@ -50,10 +50,10 @@ module NicInfo
50
50
  def display
51
51
  @config.logger.start_data_item
52
52
  @config.logger.data_title "[ IP NETWORK ]"
53
- @config.logger.terse "Handle", NicInfo::get_handle( @objectclass )
53
+ @config.logger.terse "Handle", NicInfo::get_handle( @objectclass ), NicInfo::AttentionType::SUCCESS
54
54
  @config.logger.extra "Object Class Name", NicInfo::get_object_class_name( @objectclass )
55
- @config.logger.terse "Start Address", NicInfo.get_startAddress( @objectclass )
56
- @config.logger.terse "End Address", NicInfo.get_endAddress( @objectclass )
55
+ @config.logger.terse "Start Address", NicInfo.get_startAddress( @objectclass ), NicInfo::AttentionType::SUCCESS
56
+ @config.logger.terse "End Address", NicInfo.get_endAddress( @objectclass ), NicInfo::AttentionType::SUCCESS
57
57
  @config.logger.terse "CIDRs", get_CIDRs
58
58
  @config.logger.datum "IP Version", @objectclass[ "ipVersion" ]
59
59
  @config.logger.extra "Name", NicInfo.get_name( @objectclass )
@@ -15,6 +15,7 @@
15
15
  # The run_pager code came from http://nex-3.com/posts/73-git-style-automatic-paging-in-ruby
16
16
  # and is credited to Nathan Weizenbaum
17
17
 
18
+ require 'rainbow'
18
19
  require 'nicinfo/enum'
19
20
 
20
21
  module NicInfo
@@ -47,18 +48,44 @@ module NicInfo
47
48
 
48
49
  end
49
50
 
51
+ class AttentionType < NicInfo::Enum
52
+
53
+ AttentionType.add_item(:SUCCESS, "SUCCESS" )
54
+ AttentionType.add_item(:INFO, "INFO" )
55
+ AttentionType.add_item(:PRIMARY, "PRIMARY" )
56
+ AttentionType.add_item(:SECONDARY, "SECONDARY" )
57
+ AttentionType.add_item(:ERROR, "ERROR" )
58
+
59
+ end
60
+
61
+ class ColorScheme < NicInfo::Enum
62
+
63
+ # dark background
64
+ ColorScheme.add_item(:DARK, "DARK")
65
+
66
+ # light background
67
+ ColorScheme.add_item(:LIGHT, "LIGHT")
68
+
69
+ # none
70
+ ColorScheme.add_item(:NONE, "NONE")
71
+
72
+ end
73
+
50
74
  # A logger for this application.
51
75
  class Logger
52
76
 
53
77
  attr_accessor :message_level, :data_amount, :message_out, :data_out, :item_name_length, :item_name_rjust, :pager
54
78
  attr_accessor :auto_wrap, :detect_width, :default_width, :prose_name_rjust, :prose_name_length
79
+ attr_accessor :is_less_available, :color_scheme, :rainbow
55
80
 
56
81
  def initialize
57
82
 
58
83
  @message_level = MessageLevel::SOME_MESSAGES
59
84
  @data_amount = DataAmount::NORMAL_DATA
85
+ @color_scheme = ColorScheme::DARK
60
86
  @message_out = $stdout
61
87
  @data_out = $stdout
88
+ @rainbow = Rainbow.new
62
89
  @item_name_length = 25
63
90
  @item_name_rjust = true
64
91
  @prose_name_length = 10
@@ -67,7 +94,7 @@ module NicInfo
67
94
  @message_last_written_to = false
68
95
  @data_last_written_to = false
69
96
 
70
- return if RUBY_PLATFORM =~ /win32/
97
+ return if Gem.win_platform?
71
98
  #else
72
99
  @columns = get_terminal_columns( `stty -a`, @default_width )
73
100
  end
@@ -80,12 +107,17 @@ module NicInfo
80
107
 
81
108
  def validate_message_level
82
109
  raise ArgumentError, "Message log level not defined" if @message_level == nil
83
- raise ArgumentError, "Unknown message log level '" + @message_level.to_s + "'" if !MessageLevel.has_value?(@message_level.to_s)
110
+ raise ArgumentError, "Unknown message log level '" + @message_level.to_s + "'" unless MessageLevel.has_value?(@message_level.to_s)
84
111
  end
85
112
 
86
113
  def validate_data_amount
87
114
  raise ArgumentError, "Data log level not defined" if @data_amount == nil
88
- raise ArgumentError, "Unknown data log level '" + @data_amount.to_s + "'" if !DataAmount.has_value?(@data_amount.to_s)
115
+ raise ArgumentError, "Unknown data log level '" + @data_amount.to_s + "'" unless DataAmount.has_value?(@data_amount.to_s)
116
+ end
117
+
118
+ def validate_color_scheme
119
+ raise ArgumentError, "Color scheme not defined" if @color_scheme == nil
120
+ raise ArgumentError, "Unknown color scheme '" + @color_scheme.to_s + "'" unless ColorScheme.has_value?(@color_scheme.to_s)
89
121
  end
90
122
 
91
123
  def start_data_item
@@ -107,147 +139,167 @@ module NicInfo
107
139
  end
108
140
 
109
141
  # Outputs at the :SOME_MESSAGES level
110
- def mesg message
142
+ def mesg message, attention_type = nil
111
143
  validate_message_level()
112
144
  if (@message_level != MessageLevel::NO_MESSAGES)
113
- log_info("# " + message.to_s)
145
+ log_info("# " + message.to_s, attention_type )
114
146
  return true
115
147
  end
116
148
  return false
117
149
  end
118
150
 
119
151
  # Outputs at the :ALL_MESSAGES level
120
- def trace message
152
+ def trace message, attention_type = nil
121
153
  validate_message_level()
122
154
  if (@message_level != MessageLevel::NO_MESSAGES && @message_level != MessageLevel::SOME_MESSAGES)
123
- log_info("## " + message.to_s)
155
+ log_info("## " + message.to_s, attention_type )
124
156
  return true
125
157
  end
126
158
  return false
127
159
  end
128
160
 
129
161
  # Outputs a datum at :TERSE_DATA level
130
- def terse item_name, item_value
162
+ def terse item_name, item_value, attention_type = nil
131
163
  validate_data_amount()
132
- log_data(item_name, item_value)
164
+ log_data(item_name, item_value, attention_type )
133
165
  return true
134
166
  end
135
167
 
136
168
  # Outputs a data at :NORMAL_DATA level
137
- def datum item_name, item_value
169
+ def datum item_name, item_value, attention_type = nil
138
170
  validate_data_amount()
139
171
  if (@data_amount != DataAmount::TERSE_DATA)
140
- log_data(item_name, item_value)
172
+ log_data(item_name, item_value, attention_type )
141
173
  return true
142
174
  end
143
175
  return false
144
176
  end
145
177
 
146
- def extra item_name, item_value
178
+ def extra item_name, item_value, attention_type = nil
147
179
  validate_data_amount()
148
180
  if (@data_amount != DataAmount::TERSE_DATA && @data_amount != DataAmount::NORMAL_DATA)
149
- log_data(item_name, item_value)
181
+ log_data(item_name, item_value, attention_type )
150
182
  return true
151
183
  end
152
184
  return false
153
185
  end
154
186
 
155
- def data_title title
187
+ def data_title title, attention_type = nil
156
188
  validate_data_amount()
157
- log_just title, " ", @item_name_length, @item_name_rjust, ""
189
+ log_just title, " ", @item_name_length, @item_name_rjust, "", attention_type
158
190
  return true
159
191
  end
160
192
 
161
- def info data_amount, item_name, item_value
193
+ def info data_amount, item_name, item_value, attention_type = nil
162
194
  retval = false
163
195
  validate_data_amount()
164
196
  case data_amount
165
197
  when DataAmount::TERSE_DATA
166
- log_data(item_name, item_value)
198
+ log_data(item_name, item_value, attention_type )
167
199
  retval = true
168
200
  when DataAmount::NORMAL_DATA
169
201
  if (@data_amount != DataAmount::TERSE_DATA)
170
- log_data( item_name, item_value)
202
+ log_data( item_name, item_value, attention_type )
171
203
  retval = true
172
204
  end
173
205
  when DataAmount::EXTRA_DATA
174
206
  if (@data_amount != DataAmount::TERSE_DATA && @data_amount != DataAmount::NORMAL_DATA)
175
- log_data( item_name, item_value )
207
+ log_data( item_name, item_value, attention_type )
176
208
  retval = true
177
209
  end
178
210
  end
179
211
  return retval
180
212
  end
181
213
 
182
- def raw data_amount, raw_data, wrap = true
214
+ def raw data_amount, raw_data, wrap = true, attention_type = nil
183
215
  retval = false
184
216
  validate_data_amount()
185
217
  case data_amount
186
218
  when DataAmount::TERSE_DATA
187
- log_raw(raw_data, wrap)
219
+ log_raw(raw_data, wrap, attention_type )
188
220
  retval = true
189
221
  when DataAmount::NORMAL_DATA
190
222
  if (@data_amount != DataAmount::TERSE_DATA)
191
- log_raw(raw_data, wrap)
223
+ log_raw(raw_data, wrap, attention_type )
192
224
  retval = true
193
225
  end
194
226
  when DataAmount::EXTRA_DATA
195
227
  if (@data_amount != DataAmount::TERSE_DATA && @data_amount != DataAmount::NORMAL_DATA)
196
- log_raw(raw_data, wrap)
228
+ log_raw(raw_data, wrap, attention_type )
197
229
  retval = true
198
230
  end
199
231
  end
200
232
  return retval
201
233
  end
202
234
 
203
- def prose data_amount, prose_name, prose_value
235
+ def prose data_amount, prose_name, prose_value, attention_type = nil
204
236
  retval = false
205
237
  validate_data_amount()
206
238
  case data_amount
207
239
  when DataAmount::TERSE_DATA
208
- log_prose prose_name, prose_value
240
+ log_prose prose_name, prose_value, attention_type
209
241
  retval = true
210
242
  when DataAmount::NORMAL_DATA
211
243
  if (@data_amount != DataAmount::TERSE_DATA)
212
- log_prose prose_name, prose_value
244
+ log_prose prose_name, prose_value, attention_type
213
245
  retval = true
214
246
  end
215
247
  when DataAmount::EXTRA_DATA
216
248
  if (@data_amount != DataAmount::TERSE_DATA && @data_amount != DataAmount::NORMAL_DATA)
217
- log_prose prose_name, prose_value
249
+ log_prose prose_name, prose_value, attention_type
218
250
  retval = true
219
251
  end
220
252
  end
221
253
  return retval
222
254
  end
223
255
 
224
- def log_tree_item data_amount, tree_item
256
+ def log_tree_item data_amount, tree_item, attention_type = nil
225
257
  retval = false
226
258
  validate_data_amount()
227
259
  case data_amount
228
260
  when DataAmount::TERSE_DATA
229
- log_raw(tree_item, true)
261
+ log_raw(tree_item, true, attention_type )
230
262
  retval = true
231
263
  when DataAmount::NORMAL_DATA
232
264
  if (@data_amount != DataAmount::TERSE_DATA)
233
- log_raw(tree_item, true)
265
+ log_raw(tree_item, true, attention_type )
234
266
  retval = true
235
267
  end
236
268
  when DataAmount::EXTRA_DATA
237
269
  if (@data_amount != DataAmount::TERSE_DATA && @data_amount != DataAmount::NORMAL_DATA)
238
- log_raw(tree_item, true)
270
+ log_raw(tree_item, true, attention_type )
239
271
  retval = true
240
272
  end
241
273
  end
242
274
  return retval
243
275
  end
244
276
 
277
+ def is_less_available?
278
+ if @is_less_available == nil
279
+ avail = ENV['PATH'].split(File::PATH_SEPARATOR).any? do |dir|
280
+ File.executable?(File.join(dir, "less"))
281
+ end
282
+ if avail
283
+ @is_less_available = "less"
284
+ else
285
+ @is_less_available = false
286
+ end
287
+ end
288
+ return @is_less_available
289
+ end
290
+
291
+ def get_pager
292
+ ENV['PAGER'] || is_less_available? || 'more'
293
+ end
294
+
245
295
  # This code came from http://nex-3.com/posts/73-git-style-automatic-paging-in-ruby
246
296
  def run_pager
247
297
  return unless @pager
248
- return if RUBY_PLATFORM =~ /win32/
298
+ return if Gem.win_platform?
249
299
  return unless STDOUT.tty?
250
300
 
301
+ @color_scheme = ColorScheme::NONE unless get_pager == "less"
302
+
251
303
  read, write = IO.pipe
252
304
 
253
305
  unless Kernel.fork # Child process
@@ -266,7 +318,7 @@ module NicInfo
266
318
  ENV['LESS'] = 'FSRX' # Don't page if the input is short enough
267
319
 
268
320
  Kernel.select [STDIN] # Wait until we have input before we start the pager
269
- pager = ENV['PAGER'] || 'more'
321
+ pager = get_pager
270
322
  exec pager rescue exec "/bin/sh", "-c", pager
271
323
  end
272
324
 
@@ -310,24 +362,24 @@ module NicInfo
310
362
 
311
363
  private
312
364
 
313
- def log_info message
365
+ def log_info message, attention_type
314
366
  if @data_last_written_to && @message_out == @data_out
315
367
  @data_out.puts
316
368
  end
317
- @message_out.puts(message)
369
+ puts_color( @message_out, message, attention_type)
318
370
  @message_last_written_to = true
319
371
  @data_last_written_to = false
320
372
  end
321
373
 
322
- def log_data item_name, item_value
323
- log_just item_name, item_value, @item_name_length, @item_name_rjust, ": "
374
+ def log_data item_name, item_value, attention_type
375
+ log_just item_name, item_value, @item_name_length, @item_name_rjust, ": ", attention_type
324
376
  end
325
377
 
326
- def log_prose item_name, item_value
327
- log_just item_name, item_value, @prose_name_length, @prose_name_rjust, " "
378
+ def log_prose item_name, item_value, attention_type
379
+ log_just item_name, item_value, @prose_name_length, @prose_name_rjust, " ", attention_type
328
380
  end
329
381
 
330
- def log_just item_name, item_value, name_length, name_rjust, separator
382
+ def log_just item_name, item_value, name_length, name_rjust, separator, attention_type
331
383
  if (item_value != nil && !item_value.to_s.empty?)
332
384
  format_string = "%" + name_length.to_s + "s%s%s"
333
385
  if (!name_rjust)
@@ -338,33 +390,80 @@ module NicInfo
338
390
  i = 0
339
391
  lines.each do |line|
340
392
  if i == 0
341
- @data_out.puts(format(format_string, item_name, separator, line))
393
+ puts_color( @data_out, format(format_string, item_name, separator, line), attention_type )
342
394
  else
343
- @data_out.puts(format(format_string, " ", separator, line))
395
+ puts_color( @data_out, format(format_string, " ", separator, line), attention_type )
344
396
  end
345
397
  i = i + 1
346
398
  end
347
399
  else
348
- @data_out.puts(format(format_string, item_name, separator, item_value))
400
+ puts_color( @data_out, format(format_string, item_name, separator, item_value), attention_type )
349
401
  end
350
402
  @data_last_written_to = true
351
403
  @message_last_written_to = false
352
404
  end
353
405
  end
354
406
 
355
- def log_raw item_value, wrap
407
+ def log_raw item_value, wrap, attention_type
356
408
  if @auto_wrap and wrap
357
409
  lines = break_up_line item_value, get_width
358
410
  lines.each do |line|
359
- @data_out.puts(line)
411
+ puts_color( @data_out, line, attention_type )
360
412
  end
361
413
  else
362
- @data_out.puts(item_value)
414
+ puts_color( @data_out, item_value, attention_type )
363
415
  end
364
416
  @data_last_written_to = true
365
417
  @message_last_written_to = false
366
418
  end
367
419
 
420
+ def puts_color out, string, attention_type
421
+ if !attention_type || @color_scheme == ColorScheme::NONE || attention_type == AttentionType::PRIMARY
422
+ out.puts string
423
+ else
424
+ case attention_type
425
+ when AttentionType::SUCCESS
426
+ case @color_scheme
427
+ when ColorScheme::DARK
428
+ out.puts @rainbow.wrap(string).aqua
429
+ when ColorScheme::LIGHT
430
+ out.puts @rainbow.wrap(string).blue
431
+ else
432
+ out.puts string
433
+ end
434
+ when AttentionType::SECONDARY
435
+ case @color_scheme
436
+ when ColorScheme::DARK
437
+ out.puts @rainbow.wrap(string).green
438
+ when ColorScheme::LIGHT
439
+ out.puts @rainbow.wrap(string).green
440
+ else
441
+ out.puts string
442
+ end
443
+ when AttentionType::INFO
444
+ case @color_scheme
445
+ when ColorScheme::DARK
446
+ out.puts @rainbow.wrap(string).yellow.bright
447
+ when ColorScheme::LIGHT
448
+ out.puts @rainbow.wrap(string).blue.bright
449
+ else
450
+ out.puts string
451
+ end
452
+ when AttentionType::ERROR
453
+ case @color_scheme
454
+ when ColorScheme::DARK
455
+ out.puts @rainbow.wrap(string).red.bright
456
+ when ColorScheme::LIGHT
457
+ out.puts @rainbow.wrap(string).red
458
+ else
459
+ out.puts string
460
+ end
461
+ else
462
+ out.puts string
463
+ end
464
+ end
465
+ end
466
+
368
467
  end
369
468
 
370
469
  end
@@ -199,6 +199,15 @@ module NicInfo
199
199
  raise OptionParser::InvalidArgument, pager.to_s unless pager =~ /yes|no|true|false/i
200
200
  end
201
201
 
202
+ opts.on( "--color-scheme DARK|LIGHT|NONE",
203
+ "Determines color scheme to use:",
204
+ " dark - for terminals with dark backgrounds",
205
+ " light - for terminals with light backgrounds",
206
+ " none - turn off colors" ) do |cs|
207
+ @config.logger.color_scheme = cs.to_s.upcase
208
+ raise OptionParser::InvalidArgument, cs.to_s unless cs =~ /dark|light|none/i
209
+ end
210
+
202
211
  opts.on( "-V",
203
212
  "Equivalent to --messages all and --data extra" ) do |v|
204
213
  @config.logger.data_amount = NicInfo::DataAmount::EXTRA_DATA
@@ -379,7 +388,7 @@ module NicInfo
379
388
  def run
380
389
 
381
390
  @config.logger.run_pager
382
- @config.logger.mesg(NicInfo::VERSION_LABEL)
391
+ @config.logger.mesg(NicInfo::VERSION_LABEL, NicInfo::AttentionType::PRIMARY )
383
392
  @config.setup_workspace
384
393
  @config.check_config_version
385
394
  @cache = Cache.new(@config)
@@ -395,16 +404,16 @@ module NicInfo
395
404
  check_bsfiles_age = @config.check_bsfiles_age?
396
405
  update_bsfiles = @config.update_bsfiles?( check_bsfiles_age )
397
406
  if update_bsfiles
398
- @config.logger.mesg( "IANA RDAP bootstrap files are old and need to be updated." )
407
+ @config.logger.mesg( "IANA RDAP bootstrap files are old and need to be updated.", NicInfo::AttentionType::ERROR )
399
408
  get_iana_files
400
409
  elsif check_bsfiles_age
401
- @config.logger.mesg( "IANA RDAP bootstrap files are old. Update them with --iana option" )
410
+ @config.logger.mesg( "IANA RDAP bootstrap files are old. Update them with --iana option", NicInfo::AttentionType::ERROR )
402
411
  end
403
412
  end
404
413
 
405
414
  if @config.options.demo
406
- @config.logger.mesg( "Populating cache with demonstration results" )
407
- @config.logger.mesg( "Try the following demonstration queries:" )
415
+ @config.logger.mesg( "Populating cache with demonstration results", NicInfo::AttentionType::INFO )
416
+ @config.logger.mesg( "Try the following demonstration queries:", NicInfo::AttentionType::INFO )
408
417
  demo_dir = File.join( File.dirname( __FILE__ ), NicInfo::DEMO_DIR )
409
418
  demo_files = Dir::entries( demo_dir )
410
419
  demo_files.each do |file|
@@ -415,7 +424,7 @@ module NicInfo
415
424
  demo_url = json_data[ NicInfo::NICINFO_DEMO_URL ]
416
425
  demo_hint = json_data[ NicInfo::NICINFO_DEMO_HINT ]
417
426
  @cache.create( demo_url, demo_data )
418
- @config.logger.mesg( " " + demo_hint )
427
+ @config.logger.mesg( " " + demo_hint, NicInfo::AttentionType::INFO )
419
428
  end
420
429
  end
421
430
  end
@@ -442,7 +451,7 @@ module NicInfo
442
451
  @config.logger.mesg("Unable to determine your IP Address. You must specify it.")
443
452
  exit
444
453
  elsif
445
- @config.logger.mesg("Your IP address is " + json_data["data"]["ip"])
454
+ @config.logger.mesg("Your IP address is " + json_data["data"]["ip"], NicInfo::AttentionType::SUCCESS )
446
455
  @config.options.argv[0] = json_data["data"]["ip"]
447
456
  end
448
457
  end
@@ -581,39 +590,39 @@ module NicInfo
581
590
  cache_self_references json_data
582
591
  retval = json_data
583
592
  rescue JSON::ParserError => a
584
- @config.logger.mesg( "Server returned invalid JSON!" )
593
+ @config.logger.mesg( "Server returned invalid JSON!", NicInfo::AttentionType::ERROR )
585
594
  rescue SocketError => a
586
- @config.logger.mesg(a.message)
595
+ @config.logger.mesg(a.message, NicInfo::AttentionType::ERROR )
587
596
  rescue ArgumentError => a
588
- @config.logger.mesg(a.message)
597
+ @config.logger.mesg(a.message, NicInfo::AttentionType::ERROR )
589
598
  rescue Net::HTTPServerException => e
590
599
  case e.response.code
591
600
  when "200"
592
- @config.logger.mesg( e.message )
601
+ @config.logger.mesg( e.message, NicInfo::AttentionType::SUCCESS )
593
602
  when "401"
594
- @config.logger.mesg("Authorization is required.")
603
+ @config.logger.mesg("Authorization is required.", NicInfo::AttentionType::ERROR )
595
604
  handle_error_response e.response
596
605
  when "404"
597
- @config.logger.mesg("Query yielded no results.")
606
+ @config.logger.mesg("Query yielded no results.", NicInfo::AttentionType::INFO )
598
607
  handle_error_response e.response
599
608
  else
600
- @config.logger.mesg("Error #{e.response.code}.")
609
+ @config.logger.mesg("Error #{e.response.code}.", NicInfo::AttentionType::ERROR )
601
610
  handle_error_response e.response
602
611
  end
603
612
  @config.logger.trace("Server response code was " + e.response.code)
604
613
  rescue Net::HTTPFatalError => e
605
614
  case e.response.code
606
615
  when "500"
607
- @config.logger.mesg("RDAP server is reporting an internal error.")
616
+ @config.logger.mesg("RDAP server is reporting an internal error.", NicInfo::AttentionType::ERROR )
608
617
  handle_error_response e.response
609
618
  when "501"
610
- @config.logger.mesg("RDAP server does not implement the query.")
619
+ @config.logger.mesg("RDAP server does not implement the query.", NicInfo::AttentionType::ERROR )
611
620
  handle_error_response e.response
612
621
  when "503"
613
- @config.logger.mesg("RDAP server is reporting that it is unavailable.")
622
+ @config.logger.mesg("RDAP server is reporting that it is unavailable.", NicInfo::AttentionType::ERROR )
614
623
  handle_error_response e.response
615
624
  else
616
- @config.logger.mesg("Error #{e.response.code}.")
625
+ @config.logger.mesg("Error #{e.response.code}.", NicInfo::AttentionType::ERROR )
617
626
  handle_error_response e.response
618
627
  end
619
628
  @config.logger.trace("Server response code was " + e.response.code)
@@ -705,7 +714,7 @@ module NicInfo
705
714
  rdap_conformance = json[ "rdapConformance" ]
706
715
  if rdap_conformance
707
716
  rdap_conformance.each do |conformance|
708
- @config.logger.trace( "Server conforms to #{conformance}" )
717
+ @config.logger.trace( "Server conforms to #{conformance}", NicInfo::AttentionType::SECONDARY )
709
718
  end
710
719
  else
711
720
  @config.conf_msgs << "Response has no RDAP Conformance level specified."
@@ -967,10 +976,10 @@ HELP_SUMMARY
967
976
 
968
977
  def show_conformance_messages
969
978
  return if @config.conf_msgs.size == 0
970
- @config.logger.mesg( "** WARNING: There are problems in the response that might cause some data to discarded. **" )
979
+ @config.logger.mesg( "** WARNING: There are problems in the response that might cause some data to discarded. **", NicInfo::AttentionType::ERROR )
971
980
  i = 1
972
981
  @config.conf_msgs.each do |msg|
973
- @config.logger.trace( "#{i} : #{msg}" )
982
+ @config.logger.trace( "#{i} : #{msg}", NicInfo::AttentionType::ERROR )
974
983
  i = i + 1
975
984
  end
976
985
  end
@@ -979,7 +988,7 @@ HELP_SUMMARY
979
988
  truncated = json_data[ "searchResultsTruncated" ]
980
989
  if truncated.instance_of?(TrueClass) || truncated.instance_of?(FalseClass)
981
990
  if truncated
982
- @config.logger.mesg( "Results have been truncated by the server." )
991
+ @config.logger.mesg( "Results have been truncated by the server.", NicInfo::AttentionType::INFO )
983
992
  end
984
993
  end
985
994
  if truncated != nil
@@ -52,10 +52,10 @@ module NicInfo
52
52
  return if notices == nil
53
53
  if (is_excessive_notice(notices) ) && (@config.logger.data_amount != NicInfo::DataAmount::EXTRA_DATA) && !ignore_excessive
54
54
  @config.logger.start_data_item
55
- @config.logger.raw NicInfo::DataAmount::NORMAL_DATA, "Excessive Notices"
56
- @config.logger.raw NicInfo::DataAmount::NORMAL_DATA, "-----------------"
57
- @config.logger.raw NicInfo::DataAmount::NORMAL_DATA, "Response contains excessive notices."
58
- @config.logger.raw NicInfo::DataAmount::NORMAL_DATA, "Use the \"-V\" or \"--data extra\" options to see them."
55
+ @config.logger.raw NicInfo::DataAmount::NORMAL_DATA, "Excessive Notices", NicInfo::AttentionType::INFO
56
+ @config.logger.raw NicInfo::DataAmount::NORMAL_DATA, "-----------------", NicInfo::AttentionType::INFO
57
+ @config.logger.raw NicInfo::DataAmount::NORMAL_DATA, "Response contains excessive notices.", NicInfo::AttentionType::INFO
58
+ @config.logger.raw NicInfo::DataAmount::NORMAL_DATA, "Use the \"-V\" or \"--data extra\" options to see them.", NicInfo::AttentionType::INFO
59
59
  @config.logger.end_data_item
60
60
  else
61
61
  notices.each do |notice|
@@ -72,17 +72,17 @@ module NicInfo
72
72
  title = ""
73
73
  end
74
74
  @config.conf_msgs << "'title' in 'notice' is not a string." unless title.instance_of?( String )
75
- @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "[ NOTICE ]", title
75
+ @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "[ NOTICE ]", title, NicInfo::AttentionType::SECONDARY
76
76
  type = notice[ "type" ]
77
77
  if type != nil
78
- @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "Type", NicInfo.capitalize( type )
78
+ @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "Type", NicInfo.capitalize( type ), NicInfo::AttentionType::SECONDARY
79
79
  end
80
80
  description = notice[ "description" ]
81
81
  i = 1
82
82
  if description.instance_of?( Array )
83
83
  description.each do |line|
84
84
  if line.instance_of?( String )
85
- @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, i.to_s, line
85
+ @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, i.to_s, line, NicInfo::AttentionType::SECONDARY
86
86
  i = i + 1
87
87
  else
88
88
  @config.conf_msgs << "eleemnt of 'description' in 'notice' is not a string."
@@ -95,15 +95,15 @@ module NicInfo
95
95
  if links
96
96
  if links.instance_of?( Array )
97
97
  alternate = NicInfo.get_alternate_link links
98
- @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "More", alternate if alternate
98
+ @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "More", alternate, NicInfo::AttentionType::SECONDARY if alternate
99
99
  about = NicInfo.get_about_link links
100
- @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "About", about if about
100
+ @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "About", about, NicInfo::AttentionType::SECONDARY if about
101
101
  tos = NicInfo.get_tos_link links
102
- @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "TOS", tos if tos
102
+ @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "TOS", tos, NicInfo::AttentionType::SECONDARY if tos
103
103
  copyright = NicInfo.get_copyright_link links
104
- @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "(C)", copyright if copyright
104
+ @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "(C)", copyright, NicInfo::AttentionType::SECONDARY if copyright
105
105
  license = NicInfo.get_license_link links
106
- @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "License", license if license
106
+ @config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "License", license, NicInfo::AttentionType::SECONDARY if license
107
107
  else
108
108
  @config.conf_msgs << "'links' is not an array."
109
109
  end
data/lib/nicinfo/ns.rb CHANGED
@@ -65,19 +65,19 @@ module NicInfo
65
65
  def display
66
66
  @config.logger.start_data_item
67
67
  @config.logger.data_title "[ NAME SERVER ]"
68
- @config.logger.terse "Handle", NicInfo::get_handle( @objectclass )
68
+ @config.logger.terse "Handle", NicInfo::get_handle( @objectclass ), NicInfo::AttentionType::SUCCESS
69
69
  @config.logger.extra "Object Class Name", NicInfo::get_object_class_name( @objectclass )
70
- @config.logger.terse "Host Name", NicInfo::get_ldhName( @objectclass )
71
- @config.logger.terse "IDN Host Name", NicInfo::get_unicodeName( @objectclass )
70
+ @config.logger.terse "Host Name", NicInfo::get_ldhName( @objectclass ), NicInfo::AttentionType::SUCCESS
71
+ @config.logger.terse "IDN Host Name", NicInfo::get_unicodeName( @objectclass ), NicInfo::AttentionType::SUCCESS
72
72
  ipAddrs = @objectclass[ "ipAddresses" ]
73
73
  if ipAddrs
74
74
  v6Addrs = ipAddrs[ "v6" ]
75
75
  v6Addrs.each do |v6|
76
- @config.logger.terse "IPv6 Address", v6
76
+ @config.logger.terse "IPv6 Address", v6, NicInfo::AttentionType::SUCCESS
77
77
  end if v6Addrs
78
78
  v4Addrs = ipAddrs[ "v4" ]
79
79
  v4Addrs.each do |v4|
80
- @config.logger.terse "IPv4 Address", v4
80
+ @config.logger.terse "IPv4 Address", v4, NicInfo::AttentionType::SUCCESS
81
81
  end if v4Addrs
82
82
  end
83
83
  @common.display_status @objectclass
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nicinfo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0.pre.alpha2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Newton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-19 00:00:00.000000000 Z
11
+ date: 2017-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: netaddr
@@ -101,9 +101,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
101
  version: '0'
102
102
  required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
- - - ">"
104
+ - - ">="
105
105
  - !ruby/object:Gem::Version
106
- version: 1.3.1
106
+ version: '0'
107
107
  requirements: []
108
108
  rubyforge_project:
109
109
  rubygems_version: 2.6.14