color-console 0.3.2 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c6caaaa3c163e9a30514ae3426ad18e3cc9b2b8f
4
+ data.tar.gz: 6fe85bf1de6c9be81efaaacc12e4ffeb473dd583
5
+ SHA512:
6
+ metadata.gz: 811f6cd628eaadc98f4ad020c509eb04f96dc891be98eae94674cb32fcb60ed529fdcc6c6176281bcea98fc84d4e074eaa0dcca27280ba5b60f01caa2371d295
7
+ data.tar.gz: 7e538adcae1183a166f1611b6ce5756051d655ea9d08aa433343e1fa6f0d2384bd30aef90d9a6a93f62605475f2ffdbff94c43e301d71db3e9ecd6372fb527a5
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ColorConsole
2
2
 
3
- ColorConsole is a small cross-platform library for outputting color text to the console, as well as providing utilities for drawing progress bars and outputting tabular data.
3
+ ColorConsole is a small *cross-platform* library for outputting color text to the console on both Linux and Windows, as well as providing utilities for drawing progress bars and outputting tabular data.
4
4
 
5
5
  On Windows, Fiddler (under MRI) or FFI (other engines) is used to dynamically link to the Windows Console API functions, while on other platforms, ANSI escape sequences are used. As such, there are no dependencies and no libraries to install other than this gem.
6
6
 
@@ -11,8 +11,8 @@ module Console
11
11
  include_package 'java.util.logging'
12
12
 
13
13
 
14
- # Extends the java.util.ConsoleHandler, adding colorised logging output to
15
- # the console.
14
+ # Extends the java.util.logging.ConsoleHandler, adding colorised logging
15
+ # output to the console.
16
16
  class ColorConsoleHandler < ConsoleHandler
17
17
 
18
18
  def initialize(format = RubyFormatter::DEFAULT_FORMAT)
@@ -72,6 +72,12 @@ module Console
72
72
  attr_accessor :indent
73
73
  # Level labels
74
74
  attr_reader :level_labels
75
+ # Optional proc for processing formatted msg before line wrapping.
76
+ # If a proc is set on this formatter, it will be called with the
77
+ # log record and message text before the message is formatted. It
78
+ # should return the revised message text to be logged (or nil if
79
+ # the message should be ignored).
80
+ attr_accessor :msg_proc
75
81
 
76
82
 
77
83
  # Constructs a new formatter for formatting log records according to
@@ -82,7 +88,7 @@ module Console
82
88
  def initialize(format = DEFAULT_FORMAT, width = nil)
83
89
  super()
84
90
  @format_string = format
85
- @width = width || Console.width
91
+ @width = width || Console.width || -1
86
92
  mark = java.lang.String.format(@format_string, Time.now,
87
93
  '', '', '', '!$!', nil, nil)
88
94
  @indent = mark.lines.first.index('!$!')
@@ -94,7 +100,13 @@ module Console
94
100
 
95
101
 
96
102
  # Format a log record and return a string for publishing by a log handler.
103
+ # If a +msg_proc+ handler has been set on this formatter, it will get passed
104
+ # the +log_record+ for pre-processing before it is formatted by this method.
97
105
  def format(log_record)
106
+ msg_txt = self.formatMessage(log_record)
107
+ msg_txt = msg_proc.call(log_record, msg_txt) if msg_proc
108
+ return unless msg_txt
109
+
98
110
  lvl = @level_labels[log_record.level]
99
111
  indent = @indent || 0
100
112
  spacer = ''
@@ -103,9 +115,7 @@ module Console
103
115
  spacer = ' '
104
116
  wrap_width -= 2
105
117
  end
106
-
107
- msg = wrap_width > 0 ? Console.wrap_text(log_record.message, wrap_width) :
108
- [log_record.message]
118
+ msg = wrap_width > 0 ? Console.wrap_text(msg_txt, wrap_width) : [msg_txt]
109
119
  sb = java.lang.StringBuilder.new()
110
120
  msg.each_with_index do |line, i|
111
121
  if i == 0
@@ -148,7 +158,12 @@ module Console
148
158
  # Remove any existing console handler
149
159
  l = Java::JavaUtilLogging::Logger.getLogger(logger)
150
160
  l.getHandlers.each do |h|
151
- l.removeHandler(h) if h.is_a?(Java::JavaUtilLogging::ConsoleHandler)
161
+ case h
162
+ when Console::JavaUtilLogger::ColorConsoleHandler
163
+ return
164
+ when Java::JavaUtilLogging::ConsoleHandler
165
+ l.removeHandler(h)
166
+ end
152
167
  end
153
168
 
154
169
  # Add a ColorConsoleHandler
@@ -36,7 +36,10 @@ module Console
36
36
  case
37
37
  when event.data.is_a?(Exception) || (RUBY_ENGINE == 'jruby' &&
38
38
  event.data.java_kind_of?(java.lang.Throwable))
39
- msg = Exception.format(event.data)
39
+ e = event.data
40
+ msg = "%-8s %-2s %s: %s\n" % [level, thread, e.class, e.message]
41
+ bt = e.backtrace.take(3).map{ |s| " from #{s}" }.join("\n")
42
+ msg += bt
40
43
  when event.data.is_a?(Array)
41
44
  msg = event.data
42
45
  case msg.first
@@ -45,7 +45,7 @@ module Console
45
45
  # @see #status for other supported options
46
46
  def show_progress(label, complete, opts = {})
47
47
  if self.width
48
- opts = {total: opts} if opts.is_a?(Fixnum)
48
+ opts = {total: opts} if opts.is_a?(Numeric)
49
49
  total = opts.fetch(:total, 100)
50
50
  complete = total if complete > total
51
51
  bar_length = opts.fetch(:bar_length, 40)
metadata CHANGED
@@ -1,27 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color-console
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
5
- prerelease:
4
+ version: 0.3.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Adam Gardiner
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-05-28 00:00:00.000000000 Z
11
+ date: 2020-02-02 00:00:00.000000000 Z
13
12
  dependencies: []
14
- description: ! " ColorConsole supports cross-platform (ANSI and Windows) colored
15
- text output to the console.\n It also provides useful methods for building
16
- command-line interfaces that provide status\n messages and progress bars.\n"
13
+ description: |2
14
+ ColorConsole supports cross-platform (ANSI and Windows) colored text output to the console.
15
+ It also provides useful methods for building command-line interfaces that provide status
16
+ messages and progress bars.
17
17
  email: adam.b.gardiner@gmail.com
18
18
  executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
- - README.md
23
22
  - LICENSE
23
+ - README.md
24
24
  - lib/color-console.rb
25
+ - lib/color_console.rb
25
26
  - lib/color_console/console.rb
26
27
  - lib/color_console/java_util_logger.rb
27
28
  - lib/color_console/log4r_logger.rb
@@ -31,30 +32,28 @@ files:
31
32
  - lib/color_console/platform/windows_fiddle.rb
32
33
  - lib/color_console/progress.rb
33
34
  - lib/color_console/table.rb
34
- - lib/color_console.rb
35
35
  homepage: https://github.com/agardiner/color-console
36
36
  licenses: []
37
+ metadata: {}
37
38
  post_install_message:
38
39
  rdoc_options: []
39
40
  require_paths:
40
41
  - lib
41
42
  required_ruby_version: !ruby/object:Gem::Requirement
42
- none: false
43
43
  requirements:
44
- - - ! '>='
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  required_rubygems_version: !ruby/object:Gem::Requirement
48
- none: false
49
48
  requirements:
50
- - - ! '>='
49
+ - - ">="
51
50
  - !ruby/object:Gem::Version
52
51
  version: '0'
53
52
  requirements: []
54
53
  rubyforge_project:
55
- rubygems_version: 1.8.21
54
+ rubygems_version: 2.5.2.3
56
55
  signing_key:
57
- specification_version: 3
56
+ specification_version: 4
58
57
  summary: ColorConsole is a cross-platform library for outputting colored text to the
59
58
  console
60
59
  test_files: []