console 1.29.3 → 1.30.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/console/capture.rb +27 -2
- data/lib/console/clock.rb +7 -2
- data/lib/console/compatible/logger.rb +31 -2
- data/lib/console/config.rb +93 -0
- data/lib/console/event/failure.rb +33 -4
- data/lib/console/event/generic.rb +15 -1
- data/lib/console/event/spawn.rb +39 -7
- data/lib/console/event.rb +7 -1
- data/lib/console/filter.rb +63 -3
- data/lib/console/format/safe.rb +36 -8
- data/lib/console/format.rb +4 -1
- data/lib/console/interface.rb +17 -9
- data/lib/console/logger.rb +23 -38
- data/lib/console/output/default.rb +12 -6
- data/lib/console/output/failure.rb +8 -1
- data/lib/console/output/null.rb +5 -2
- data/lib/console/output/sensitive.rb +42 -1
- data/lib/console/output/serialized.rb +25 -4
- data/lib/console/output/split.rb +12 -1
- data/lib/console/output/terminal.rb +67 -15
- data/lib/console/output/wrapper.rb +12 -1
- data/lib/console/output.rb +12 -1
- data/lib/console/progress.rb +56 -9
- data/lib/console/resolver.rb +19 -2
- data/lib/console/terminal/formatter/failure.rb +18 -6
- data/lib/console/terminal/formatter/progress.rb +16 -3
- data/lib/console/terminal/formatter/spawn.rb +16 -5
- data/lib/console/terminal/formatter.rb +16 -0
- data/lib/console/terminal/text.rb +61 -20
- data/lib/console/terminal/xterm.rb +17 -2
- data/lib/console/terminal.rb +7 -9
- data/lib/console/version.rb +2 -2
- data/lib/console/warn.rb +2 -2
- data/lib/console.rb +2 -1
- data/license.md +1 -0
- data/readme.md +7 -1
- data/releases.md +24 -1
- data.tar.gz.sig +4 -3
- metadata +5 -2
- metadata.gz.sig +0 -0
@@ -1,36 +1,47 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2019-
|
4
|
+
# Copyright, 2019-2025, by Samuel Williams.
|
5
5
|
|
6
6
|
module Console
|
7
7
|
module Terminal
|
8
8
|
module Formatter
|
9
|
-
# Format spawn
|
9
|
+
# Format a spawn event, including the command and arguments.
|
10
10
|
class Spawn
|
11
|
+
# The key used to identify this formatter.
|
11
12
|
KEY = :spawn
|
12
13
|
|
14
|
+
# Create a new spawn formatter.
|
15
|
+
#
|
16
|
+
# @param terminal [Terminal::Text] The terminal to use for formatting.
|
13
17
|
def initialize(terminal)
|
14
18
|
@terminal = terminal
|
15
19
|
@terminal[:spawn_command] ||= @terminal.style(:blue, nil, :bold)
|
16
20
|
end
|
17
21
|
|
18
|
-
|
22
|
+
# Format the given event.
|
23
|
+
#
|
24
|
+
# @parameter event [Hash] The event to format.
|
25
|
+
# @parameter stream [IO] The stream to write the formatted event to.
|
26
|
+
# @parameter verbose [Boolean] Whether to include additional information.
|
27
|
+
# @parameter width [Integer] The width of the progress bar.
|
28
|
+
def format(event, stream, verbose: false, width: 80)
|
19
29
|
environment, arguments, options = event.values_at(:environment, :arguments, :options)
|
20
30
|
|
21
31
|
arguments = arguments.flatten.collect(&:to_s)
|
22
32
|
|
23
|
-
|
33
|
+
stream.puts "#{@terminal[:spawn_command]}#{arguments.join(' ')}#{@terminal.reset}#{chdir_string(options)}"
|
24
34
|
|
25
35
|
if verbose and environment
|
26
36
|
environment.each do |key, value|
|
27
|
-
|
37
|
+
stream.puts "export #{key}=#{value}"
|
28
38
|
end
|
29
39
|
end
|
30
40
|
end
|
31
41
|
|
32
42
|
private
|
33
43
|
|
44
|
+
# Generate a string to represent the working directory.
|
34
45
|
def chdir_string(options)
|
35
46
|
if options and chdir = options[:chdir]
|
36
47
|
" in #{chdir}"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2025, by Samuel Williams.
|
5
|
+
|
6
|
+
require_relative "formatter/progress"
|
7
|
+
require_relative "formatter/failure"
|
8
|
+
require_relative "formatter/spawn"
|
9
|
+
|
10
|
+
module Console
|
11
|
+
module Terminal
|
12
|
+
# Formatters for various types of events.
|
13
|
+
module Formatter
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,82 +1,123 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2019-
|
4
|
+
# Copyright, 2019-2025, by Samuel Williams.
|
5
5
|
|
6
6
|
require "io/console"
|
7
7
|
|
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
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2019-
|
4
|
+
# Copyright, 2019-2025, by Samuel Williams.
|
5
5
|
|
6
6
|
require "io/console"
|
7
7
|
|
@@ -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
@@ -1,22 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2019-
|
4
|
+
# Copyright, 2019-2025, by Samuel Williams.
|
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
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2024, by Samuel Williams.
|
4
|
+
# Copyright, 2024-2025, by Samuel Williams.
|
5
5
|
|
6
6
|
require_relative "logger"
|
7
7
|
|
@@ -22,7 +22,7 @@ module Console
|
|
22
22
|
fiber.console_warn = true
|
23
23
|
message.chomp!
|
24
24
|
|
25
|
-
Console::
|
25
|
+
Console::Interface.instance.warn(message, **options)
|
26
26
|
ensure
|
27
27
|
fiber.console_warn = false
|
28
28
|
end
|
data/lib/console.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2019-
|
4
|
+
# Copyright, 2019-2025, by Samuel Williams.
|
5
5
|
# Copyright, 2019, by Bryan Powell.
|
6
6
|
# Copyright, 2020, by Michael Adams.
|
7
7
|
# Copyright, 2021, by Cédric Boutillier.
|
@@ -9,6 +9,7 @@
|
|
9
9
|
require_relative "console/version"
|
10
10
|
require_relative "console/interface"
|
11
11
|
|
12
|
+
# @namespace
|
12
13
|
module Console
|
13
14
|
Console.extend(Interface)
|
14
15
|
end
|
data/license.md
CHANGED
@@ -11,6 +11,7 @@ Copyright, 2022, by Anton Sozontov.
|
|
11
11
|
Copyright, 2022, by William T. Nelson.
|
12
12
|
Copyright, 2023, by Felix Yan.
|
13
13
|
Copyright, 2024, by Patrik Wenger.
|
14
|
+
Copyright, 2025, by Shigeru Nakajima.
|
14
15
|
|
15
16
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
16
17
|
of this software and associated documentation files (the "Software"), to deal
|
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,6 +34,10 @@ 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
|
+
|
35
41
|
### v1.29.3
|
36
42
|
|
37
43
|
- Serialized output now uses `IO#write` with a single string to reduce the chance of interleaved output.
|
@@ -48,7 +54,7 @@ Please see the [project releases](https://socketry.github.io/console/releases/in
|
|
48
54
|
|
49
55
|
- Don't make `Kernel#warn` redirection to `Console.warn` the default behavior, you must `require 'console/warn'` to enable it.
|
50
56
|
- Remove deprecated `Console::Logger#failure`.
|
51
|
-
- [Consistent
|
57
|
+
- [Consistent handling of exceptions.](https://socketry.github.io/console/releases/index#consistent-handling-of-exceptions.)
|
52
58
|
|
53
59
|
### v1.28.0
|
54
60
|
|
data/releases.md
CHANGED
@@ -1,5 +1,28 @@
|
|
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
|
+
|
3
26
|
## v1.29.3
|
4
27
|
|
5
28
|
- Serialized output now uses `IO#write` with a single string to reduce the chance of interleaved output.
|
@@ -17,7 +40,7 @@
|
|
17
40
|
- Don't make `Kernel#warn` redirection to `Console.warn` the default behavior, you must `require 'console/warn'` to enable it.
|
18
41
|
- Remove deprecated `Console::Logger#failure`.
|
19
42
|
|
20
|
-
### Consistent
|
43
|
+
### Consistent handling of exceptions.
|
21
44
|
|
22
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:
|
23
46
|
|
data.tar.gz.sig
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
�����2D���4*�����]q�>�C]u����Ռ=Op�lr�R�&h�����O&V�N5(_!�ﷰ��
|
2
|
+
���g�Ѳ�����
|
3
|
+
A��Cfh\.51<���yN���%2?l�^�Ħ��a�[���8O�5��Tj���yB_QO�̜�G�Q%����ޥ~��:q�����VиsZ��^j�P>�]���G��p�B���<�J6���ǁk�{ͨ�}I]��;����9X��fI�
|
4
|
+
q���e=�jG-5�(F���~tЍ,�iЇR^��\�d��=�5/�Q��j���>���jp�W^V)$�`Z`=z$�����>p��cG-lg+��0�f&�SDx����D9�\�1�zrD�n"2=(ޒ�c��T�
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -14,6 +14,7 @@ authors:
|
|
14
14
|
- Felix Yan
|
15
15
|
- Olle Jonsson
|
16
16
|
- Patrik Wenger
|
17
|
+
- Shigeru Nakajima
|
17
18
|
- William T. Nelson
|
18
19
|
bindir: bin
|
19
20
|
cert_chain:
|
@@ -46,7 +47,7 @@ cert_chain:
|
|
46
47
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
47
48
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
48
49
|
-----END CERTIFICATE-----
|
49
|
-
date: 2025-
|
50
|
+
date: 2025-03-09 00:00:00.000000000 Z
|
50
51
|
dependencies:
|
51
52
|
- !ruby/object:Gem::Dependency
|
52
53
|
name: fiber-annotation
|
@@ -100,6 +101,7 @@ files:
|
|
100
101
|
- lib/console/capture.rb
|
101
102
|
- lib/console/clock.rb
|
102
103
|
- lib/console/compatible/logger.rb
|
104
|
+
- lib/console/config.rb
|
103
105
|
- lib/console/event.rb
|
104
106
|
- lib/console/event/failure.rb
|
105
107
|
- lib/console/event/generic.rb
|
@@ -121,6 +123,7 @@ files:
|
|
121
123
|
- lib/console/progress.rb
|
122
124
|
- lib/console/resolver.rb
|
123
125
|
- lib/console/terminal.rb
|
126
|
+
- lib/console/terminal/formatter.rb
|
124
127
|
- lib/console/terminal/formatter/failure.rb
|
125
128
|
- lib/console/terminal/formatter/progress.rb
|
126
129
|
- lib/console/terminal/formatter/spawn.rb
|
metadata.gz.sig
CHANGED
Binary file
|