console 1.29.2 → 1.30.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/console/capture.rb +26 -1
- data/lib/console/clock.rb +6 -1
- data/lib/console/compatible/logger.rb +30 -1
- data/lib/console/config.rb +93 -0
- data/lib/console/event/failure.rb +32 -3
- data/lib/console/event/generic.rb +14 -0
- data/lib/console/event/spawn.rb +38 -6
- data/lib/console/event.rb +6 -0
- data/lib/console/filter.rb +62 -2
- data/lib/console/format/safe.rb +35 -7
- data/lib/console/format.rb +3 -0
- data/lib/console/interface.rb +18 -10
- data/lib/console/logger.rb +22 -37
- data/lib/console/output/default.rb +11 -5
- data/lib/console/output/failure.rb +9 -2
- data/lib/console/output/null.rb +4 -1
- data/lib/console/output/sensitive.rb +41 -0
- data/lib/console/output/serialized.rb +26 -5
- data/lib/console/output/split.rb +11 -0
- data/lib/console/output/terminal.rb +66 -14
- data/lib/console/output/wrapper.rb +11 -0
- data/lib/console/output.rb +11 -0
- data/lib/console/progress.rb +55 -8
- data/lib/console/resolver.rb +18 -1
- data/lib/console/terminal/formatter/failure.rb +17 -5
- data/lib/console/terminal/formatter/progress.rb +15 -2
- data/lib/console/terminal/formatter/spawn.rb +15 -4
- data/lib/console/terminal/formatter.rb +16 -0
- data/lib/console/terminal/text.rb +60 -19
- data/lib/console/terminal/xterm.rb +16 -1
- data/lib/console/terminal.rb +6 -8
- data/lib/console/version.rb +1 -1
- data/lib/console/warn.rb +1 -1
- data/lib/console.rb +1 -0
- data/license.md +1 -1
- data/readme.md +19 -1
- data/releases.md +36 -1
- data.tar.gz.sig +0 -0
- metadata +5 -8
- metadata.gz.sig +0 -0
@@ -8,75 +8,116 @@ require "io/console"
|
|
8
8
|
module Console
|
9
9
|
# Styled terminal output.
|
10
10
|
module Terminal
|
11
|
+
# A simple text-based terminal output.
|
11
12
|
class Text
|
12
|
-
|
13
|
-
|
13
|
+
# Create a new text terminal output.
|
14
|
+
#
|
15
|
+
# @parameter stream [IO] The stream to write to.
|
16
|
+
def initialize(stream)
|
17
|
+
@stream = stream
|
14
18
|
@styles = {reset: self.reset}
|
15
19
|
end
|
16
20
|
|
21
|
+
# @attribute [IO] The stream to write to.
|
22
|
+
attr :stream
|
23
|
+
|
24
|
+
# Get the style associated with the given key.
|
25
|
+
#
|
26
|
+
# @parameter key [Symbol] The key to look up.
|
27
|
+
# @returns [String] The style associated with the key.
|
17
28
|
def [] key
|
18
29
|
@styles[key]
|
19
30
|
end
|
20
31
|
|
32
|
+
# Set the style associated with the given key.
|
33
|
+
#
|
34
|
+
# @parameter key [Symbol] The key to associate the style with.
|
35
|
+
# @parameter value [String] The style to associate with the key.
|
21
36
|
def []= key, value
|
22
37
|
@styles[key] = value
|
23
38
|
end
|
24
39
|
|
40
|
+
# @returns [Boolean] Whether the terminal supports colors.
|
25
41
|
def colors?
|
26
42
|
false
|
27
43
|
end
|
28
44
|
|
45
|
+
# @returns [Tuple(Integer, Integer)] The size of the terminal, or a default value of [24, 80].
|
46
|
+
def size
|
47
|
+
[24, 80]
|
48
|
+
end
|
49
|
+
|
50
|
+
# @returns [Integer] The width of the terminal.
|
29
51
|
def width
|
30
|
-
|
52
|
+
self.size.last
|
31
53
|
end
|
32
54
|
|
55
|
+
# Generate a style string for the given foreground, background, and attributes.
|
56
|
+
#
|
57
|
+
# @returns [String | Nil] The style string if colors are supported, otherwise nil.
|
33
58
|
def style(foreground, background = nil, *attributes)
|
34
59
|
end
|
35
60
|
|
61
|
+
# Generate a reset sequence.
|
62
|
+
#
|
63
|
+
# @returns [String | Nil] The reset sequence if colors are supported, otherwise nil.
|
36
64
|
def reset
|
37
65
|
end
|
38
66
|
|
67
|
+
# Write the given arguments to the output stream using the given style. The reset sequence is automatically appended.
|
68
|
+
#
|
69
|
+
# @parameter arguments [Array] The arguments to write.
|
70
|
+
# @parameter style [Symbol] The style to apply.
|
39
71
|
def write(*arguments, style: nil)
|
40
72
|
if style and prefix = self[style]
|
41
|
-
@
|
42
|
-
@
|
43
|
-
@
|
73
|
+
@stream.write(prefix)
|
74
|
+
@stream.write(*arguments)
|
75
|
+
@stream.write(self.reset)
|
44
76
|
else
|
45
|
-
@
|
77
|
+
@stream.write(*arguments)
|
46
78
|
end
|
47
79
|
end
|
48
80
|
|
81
|
+
# Write the given arguments to the output stream using the given style. The reset sequence is automatically appended.
|
82
|
+
#
|
83
|
+
# @parameter arguments [Array] The arguments to write, each on a new line.
|
84
|
+
# @parameter style [Symbol] The style to apply.
|
49
85
|
def puts(*arguments, style: nil)
|
50
86
|
if style and prefix = self[style]
|
51
|
-
@
|
52
|
-
@
|
53
|
-
@
|
87
|
+
@stream.write(prefix)
|
88
|
+
@stream.puts(*arguments)
|
89
|
+
@stream.write(self.reset)
|
54
90
|
else
|
55
|
-
@
|
91
|
+
@stream.puts(*arguments)
|
56
92
|
end
|
57
93
|
end
|
58
94
|
|
59
|
-
# Print
|
60
|
-
#
|
61
|
-
# When the argument is a
|
62
|
-
# When the argument is
|
95
|
+
# Print rich text to the output stream.
|
96
|
+
#
|
97
|
+
# - When the argument is a symbol, look up the style and inject it into the output stream.
|
98
|
+
# - When the argument is a proc/lambda, call it with self as the argument.
|
99
|
+
# - When the argument is anything else, write it directly to the output.
|
100
|
+
#
|
101
|
+
# @parameter arguments [Array] The arguments to print.
|
63
102
|
def print(*arguments)
|
64
103
|
arguments.each do |argument|
|
65
104
|
case argument
|
66
105
|
when Symbol
|
67
|
-
@
|
106
|
+
@stream.write(self[argument])
|
68
107
|
when Proc
|
69
108
|
argument.call(self)
|
70
109
|
else
|
71
|
-
@
|
110
|
+
@stream.write(argument)
|
72
111
|
end
|
73
112
|
end
|
74
113
|
end
|
75
114
|
|
76
|
-
# Print
|
115
|
+
# Print rich text to the output stream, followed by the reset sequence and a newline.
|
116
|
+
#
|
117
|
+
# @parameter arguments [Array] The arguments to print.
|
77
118
|
def print_line(*arguments)
|
78
119
|
print(*arguments)
|
79
|
-
@
|
120
|
+
@stream.puts(self.reset)
|
80
121
|
end
|
81
122
|
end
|
82
123
|
end
|
@@ -10,7 +10,9 @@ require_relative "text"
|
|
10
10
|
module Console
|
11
11
|
# Styled terminal output.
|
12
12
|
module Terminal
|
13
|
+
# XTerm style terminal output.
|
13
14
|
class XTerm < Text
|
15
|
+
# XTerm color codes.
|
14
16
|
COLORS = {
|
15
17
|
black: 0,
|
16
18
|
red: 1,
|
@@ -23,6 +25,7 @@ module Console
|
|
23
25
|
default: 9,
|
24
26
|
}.freeze
|
25
27
|
|
28
|
+
# XTerm attribute codes.
|
26
29
|
ATTRIBUTES = {
|
27
30
|
normal: 0,
|
28
31
|
bold: 1,
|
@@ -35,21 +38,30 @@ module Console
|
|
35
38
|
hidden: 8,
|
36
39
|
}.freeze
|
37
40
|
|
41
|
+
# Whether the terminal supports colors.
|
38
42
|
def colors?
|
39
43
|
true
|
40
44
|
end
|
41
45
|
|
46
|
+
# The size of the terminal.
|
42
47
|
def size
|
43
|
-
@
|
48
|
+
@stream.winsize
|
44
49
|
rescue Errno::ENOTTY
|
45
50
|
# Fake it...
|
46
51
|
[24, 80]
|
47
52
|
end
|
48
53
|
|
54
|
+
# The width of the terminal.
|
49
55
|
def width
|
50
56
|
size.last
|
51
57
|
end
|
52
58
|
|
59
|
+
# Apply the given style to the output.
|
60
|
+
#
|
61
|
+
# @parameter foreground [Symbol] The foreground color.
|
62
|
+
# @parameter background [Symbol] The background color.
|
63
|
+
# @parameter attributes [Array(Symbol)] The attributes to apply.
|
64
|
+
# @returns [String] The style code.
|
53
65
|
def style(foreground, background = nil, *attributes)
|
54
66
|
tokens = []
|
55
67
|
|
@@ -68,6 +80,9 @@ module Console
|
|
68
80
|
return "\e[#{tokens.join(';')}m"
|
69
81
|
end
|
70
82
|
|
83
|
+
# Reset the style.
|
84
|
+
#
|
85
|
+
# @returns [String] The reset code.
|
71
86
|
def reset
|
72
87
|
"\e[0m"
|
73
88
|
end
|
data/lib/console/terminal.rb
CHANGED
@@ -5,18 +5,16 @@
|
|
5
5
|
|
6
6
|
require_relative "terminal/text"
|
7
7
|
require_relative "terminal/xterm"
|
8
|
-
|
9
|
-
require_relative "terminal/formatter/progress"
|
10
|
-
require_relative "terminal/formatter/failure"
|
11
|
-
require_relative "terminal/formatter/spawn"
|
8
|
+
require_relative "terminal/formatter"
|
12
9
|
|
13
10
|
module Console
|
14
11
|
module Terminal
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
# Create a new terminal output for the given stream.
|
13
|
+
def self.for(stream)
|
14
|
+
if stream.tty?
|
15
|
+
XTerm.new(stream)
|
18
16
|
else
|
19
|
-
Text.new(
|
17
|
+
Text.new(stream)
|
20
18
|
end
|
21
19
|
end
|
22
20
|
end
|
data/lib/console/version.rb
CHANGED
data/lib/console/warn.rb
CHANGED
data/lib/console.rb
CHANGED
data/license.md
CHANGED
data/readme.md
CHANGED
@@ -24,6 +24,8 @@ Please see the [project documentation](https://socketry.github.io/console/) for
|
|
24
24
|
|
25
25
|
- [Command Line](https://socketry.github.io/console/guides/command-line/index) - This guide explains how the `console` gem can be controlled using environment variables.
|
26
26
|
|
27
|
+
- [Configuration](https://socketry.github.io/console/guides/configuration/index) - This guide explains how to implement per-project configuration for the `console` gem.
|
28
|
+
|
27
29
|
- [Integration](https://socketry.github.io/console/guides/integration/index) - This guide explains how to integrate the `console` output into different systems.
|
28
30
|
|
29
31
|
- [Events](https://socketry.github.io/console/guides/events/index) - This guide explains how to log structured events with a well-defined schema.
|
@@ -32,11 +34,27 @@ Please see the [project documentation](https://socketry.github.io/console/) for
|
|
32
34
|
|
33
35
|
Please see the [project releases](https://socketry.github.io/console/releases/index) for all releases.
|
34
36
|
|
37
|
+
### v1.30.0
|
38
|
+
|
39
|
+
- [Introduce `Console::Config` for fine grained configuration.](https://socketry.github.io/console/releases/index#introduce-console::config-for-fine-grained-configuration.)
|
40
|
+
|
41
|
+
### v1.29.3
|
42
|
+
|
43
|
+
- Serialized output now uses `IO#write` with a single string to reduce the chance of interleaved output.
|
44
|
+
|
45
|
+
### v1.29.2
|
46
|
+
|
47
|
+
- Always return `nil` from `Console::Filter` logging methods.
|
48
|
+
|
49
|
+
### v1.29.1
|
50
|
+
|
51
|
+
- Fix logging `exception:` keyword argument when the value was not an exception.
|
52
|
+
|
35
53
|
### v1.29.0
|
36
54
|
|
37
55
|
- Don't make `Kernel#warn` redirection to `Console.warn` the default behavior, you must `require 'console/warn'` to enable it.
|
38
56
|
- Remove deprecated `Console::Logger#failure`.
|
39
|
-
- [Consistent
|
57
|
+
- [Consistent handling of exceptions.](https://socketry.github.io/console/releases/index#consistent-handling-of-exceptions.)
|
40
58
|
|
41
59
|
### v1.28.0
|
42
60
|
|
data/releases.md
CHANGED
@@ -1,11 +1,46 @@
|
|
1
1
|
# Releases
|
2
2
|
|
3
|
+
## v1.30.0
|
4
|
+
|
5
|
+
### Introduce `Console::Config` for fine grained configuration.
|
6
|
+
|
7
|
+
Introduced a new explicit configuration interface via config/console.rb to enhance logging setup in complex applications. This update gives the application code an opportunity to load files if required and control aspects such as log level, output, and more. Users can override default behaviors (e.g., make\_output, make\_logger, and log\_level) for improved customization.
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
# config/console.rb
|
11
|
+
def log_level(env = ENV)
|
12
|
+
# Set a custom log level, e.g., force debug mode:
|
13
|
+
:debug
|
14
|
+
end
|
15
|
+
|
16
|
+
def make_logger(output = $stderr, env = ENV, **options)
|
17
|
+
# Custom logger configuration with verbose output:
|
18
|
+
options[:verbose] = true
|
19
|
+
|
20
|
+
Logger.new(output, **options)
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
This approach provides a standard way to hook into the log setup process, allowing tailored adjustments for reliable and customizable logging behavior.
|
25
|
+
|
26
|
+
## v1.29.3
|
27
|
+
|
28
|
+
- Serialized output now uses `IO#write` with a single string to reduce the chance of interleaved output.
|
29
|
+
|
30
|
+
## v1.29.2
|
31
|
+
|
32
|
+
- Always return `nil` from `Console::Filter` logging methods.
|
33
|
+
|
34
|
+
## v1.29.1
|
35
|
+
|
36
|
+
- Fix logging `exception:` keyword argument when the value was not an exception.
|
37
|
+
|
3
38
|
## v1.29.0
|
4
39
|
|
5
40
|
- Don't make `Kernel#warn` redirection to `Console.warn` the default behavior, you must `require 'console/warn'` to enable it.
|
6
41
|
- Remove deprecated `Console::Logger#failure`.
|
7
42
|
|
8
|
-
### Consistent
|
43
|
+
### Consistent handling of exceptions.
|
9
44
|
|
10
45
|
`Console.call` and all wrapper methods will now consistently handle exceptions that are the last positional argument or keyword argument. This means that the following code will work as expected:
|
11
46
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: console
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.30.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -15,7 +15,6 @@ authors:
|
|
15
15
|
- Olle Jonsson
|
16
16
|
- Patrik Wenger
|
17
17
|
- William T. Nelson
|
18
|
-
autorequire:
|
19
18
|
bindir: bin
|
20
19
|
cert_chain:
|
21
20
|
- |
|
@@ -47,7 +46,7 @@ cert_chain:
|
|
47
46
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
48
47
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
49
48
|
-----END CERTIFICATE-----
|
50
|
-
date:
|
49
|
+
date: 2025-03-07 00:00:00.000000000 Z
|
51
50
|
dependencies:
|
52
51
|
- !ruby/object:Gem::Dependency
|
53
52
|
name: fiber-annotation
|
@@ -91,8 +90,6 @@ dependencies:
|
|
91
90
|
- - ">="
|
92
91
|
- !ruby/object:Gem::Version
|
93
92
|
version: '0'
|
94
|
-
description:
|
95
|
-
email:
|
96
93
|
executables: []
|
97
94
|
extensions: []
|
98
95
|
extra_rdoc_files: []
|
@@ -103,6 +100,7 @@ files:
|
|
103
100
|
- lib/console/capture.rb
|
104
101
|
- lib/console/clock.rb
|
105
102
|
- lib/console/compatible/logger.rb
|
103
|
+
- lib/console/config.rb
|
106
104
|
- lib/console/event.rb
|
107
105
|
- lib/console/event/failure.rb
|
108
106
|
- lib/console/event/generic.rb
|
@@ -124,6 +122,7 @@ files:
|
|
124
122
|
- lib/console/progress.rb
|
125
123
|
- lib/console/resolver.rb
|
126
124
|
- lib/console/terminal.rb
|
125
|
+
- lib/console/terminal/formatter.rb
|
127
126
|
- lib/console/terminal/formatter/failure.rb
|
128
127
|
- lib/console/terminal/formatter/progress.rb
|
129
128
|
- lib/console/terminal/formatter/spawn.rb
|
@@ -139,7 +138,6 @@ licenses:
|
|
139
138
|
- MIT
|
140
139
|
metadata:
|
141
140
|
documentation_uri: https://socketry.github.io/console/
|
142
|
-
post_install_message:
|
143
141
|
rdoc_options: []
|
144
142
|
require_paths:
|
145
143
|
- lib
|
@@ -154,8 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
152
|
- !ruby/object:Gem::Version
|
155
153
|
version: '0'
|
156
154
|
requirements: []
|
157
|
-
rubygems_version: 3.
|
158
|
-
signing_key:
|
155
|
+
rubygems_version: 3.6.2
|
159
156
|
specification_version: 4
|
160
157
|
summary: Beautiful logging for Ruby.
|
161
158
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|