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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/console/capture.rb +26 -1
  4. data/lib/console/clock.rb +6 -1
  5. data/lib/console/compatible/logger.rb +30 -1
  6. data/lib/console/config.rb +93 -0
  7. data/lib/console/event/failure.rb +32 -3
  8. data/lib/console/event/generic.rb +14 -0
  9. data/lib/console/event/spawn.rb +38 -6
  10. data/lib/console/event.rb +6 -0
  11. data/lib/console/filter.rb +62 -2
  12. data/lib/console/format/safe.rb +35 -7
  13. data/lib/console/format.rb +3 -0
  14. data/lib/console/interface.rb +18 -10
  15. data/lib/console/logger.rb +22 -37
  16. data/lib/console/output/default.rb +11 -5
  17. data/lib/console/output/failure.rb +9 -2
  18. data/lib/console/output/null.rb +4 -1
  19. data/lib/console/output/sensitive.rb +41 -0
  20. data/lib/console/output/serialized.rb +26 -5
  21. data/lib/console/output/split.rb +11 -0
  22. data/lib/console/output/terminal.rb +66 -14
  23. data/lib/console/output/wrapper.rb +11 -0
  24. data/lib/console/output.rb +11 -0
  25. data/lib/console/progress.rb +55 -8
  26. data/lib/console/resolver.rb +18 -1
  27. data/lib/console/terminal/formatter/failure.rb +17 -5
  28. data/lib/console/terminal/formatter/progress.rb +15 -2
  29. data/lib/console/terminal/formatter/spawn.rb +15 -4
  30. data/lib/console/terminal/formatter.rb +16 -0
  31. data/lib/console/terminal/text.rb +60 -19
  32. data/lib/console/terminal/xterm.rb +16 -1
  33. data/lib/console/terminal.rb +6 -8
  34. data/lib/console/version.rb +1 -1
  35. data/lib/console/warn.rb +1 -1
  36. data/lib/console.rb +1 -0
  37. data/license.md +1 -1
  38. data/readme.md +19 -1
  39. data/releases.md +36 -1
  40. data.tar.gz.sig +0 -0
  41. metadata +5 -8
  42. 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
- def initialize(output)
13
- @output = output
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
- 80
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
- @output.write(prefix)
42
- @output.write(*arguments)
43
- @output.write(self.reset)
73
+ @stream.write(prefix)
74
+ @stream.write(*arguments)
75
+ @stream.write(self.reset)
44
76
  else
45
- @output.write(*arguments)
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
- @output.write(prefix)
52
- @output.puts(*arguments)
53
- @output.write(self.reset)
87
+ @stream.write(prefix)
88
+ @stream.puts(*arguments)
89
+ @stream.write(self.reset)
54
90
  else
55
- @output.puts(*arguments)
91
+ @stream.puts(*arguments)
56
92
  end
57
93
  end
58
94
 
59
- # Print out the given arguments.
60
- # When the argument is a symbol, look up the style and inject it into the output stream.
61
- # When the argument is a proc/lambda, call it with self as the argument.
62
- # When the argument is anything else, write it directly to the output.
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
- @output.write(self[argument])
106
+ @stream.write(self[argument])
68
107
  when Proc
69
108
  argument.call(self)
70
109
  else
71
- @output.write(argument)
110
+ @stream.write(argument)
72
111
  end
73
112
  end
74
113
  end
75
114
 
76
- # Print out the arguments as per {#print}, followed by the reset sequence and a newline.
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
- @output.puts(self.reset)
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
- @output.winsize
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
@@ -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
- def self.for(io)
16
- if io.tty?
17
- XTerm.new(io)
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(io)
17
+ Text.new(stream)
20
18
  end
21
19
  end
22
20
  end
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
6
  module Console
7
- VERSION = "1.29.2"
7
+ VERSION = "1.30.0"
8
8
  end
data/lib/console/warn.rb CHANGED
@@ -22,7 +22,7 @@ module Console
22
22
  fiber.console_warn = true
23
23
  message.chomp!
24
24
 
25
- Console::Logger.instance.warn(message, **options)
25
+ Console::Interface.instance.warn(message, **options)
26
26
  ensure
27
27
  fiber.console_warn = false
28
28
  end
data/lib/console.rb CHANGED
@@ -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
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2019-2024, by Samuel Williams.
3
+ Copyright, 2019-2025, by Samuel Williams.
4
4
  Copyright, 2019-2021, by Bryan Powell.
5
5
  Copyright, 2019, by Cyril Roelandt.
6
6
  Copyright, 2020, by Olle Jonsson.
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 Handling of Exceptions](https://socketry.github.io/console/releases/index#consistent-handling-of-exceptions)
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 Handling of Exceptions
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.29.2
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: 2024-12-09 00:00:00.000000000 Z
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.5.22
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