rspec-osc7501 0.1.3 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd41d289a0bf23e97697865b61a02cbab47a71deac877207f2299897f952277a
4
- data.tar.gz: 23f1e885b80df344e008650a4f7d65d65fd64c596167245fa6ca6c2ad5dd7012
3
+ metadata.gz: dc8ed02d50f444325bceda0da3e2869c521dbb408372b396885b08785b44d745
4
+ data.tar.gz: fb25dbd7f8514b7158ad1df53fcbe475c5fe60a64d7abe52112a195cec6587a9
5
5
  SHA512:
6
- metadata.gz: f65c332e6b8124872674ee477733e7243b777f4a80b642ecac99bbed183e15a9a8a15a8a8a40f1c7652cc1ec7f1bf7acc61871a4af8e85d2bbcc82b82c4a1771
7
- data.tar.gz: ff9ca548aa836cdf585d1ef2d931b8a3e980f90b6b951f9bef4d57286fef76ad887aad2bf7f30d59976637b5d42e3465cd61ba9ce8a768b53036678849549c64
6
+ metadata.gz: 37828c01adc781fe4db020940367a3c6cf025b5ed80ece6be88aa2569f7b2e8946f5f549f4351bcd22f8e6d87d1ff1d19285d94c708b4a7eb409d8cf95a87888
7
+ data.tar.gz: fea1242eeeaa665355fa4375106861b4541cee64ced98c794ae3b15cbb7afe028134502f106aea7efcc12230ddc6aeced65bb5bda0a2da2905ce3f3cade5f657
data/ACCESSIBILITY.md CHANGED
@@ -15,12 +15,12 @@ RSPEC_OSC7501=off bundle exec rspec --format documentation --no-color
15
15
  `--no-color` disables RSpec's text colors. `RSPEC_OSC7501=off` disables this
16
16
  gem's status records, even when your RSpec configuration selects the formatter.
17
17
 
18
- By default, the formatter sends no status records to pipes, files, or terminals
19
- with `TERM=dumb`. `RSPEC_OSC7501=force` overrides those defaults.
18
+ By default, the formatter sends no status records to redirected streams or to
19
+ terminals with `TERM=dumb`. `RSPEC_OSC7501=force` overrides those defaults.
20
20
 
21
21
  ## Environments and limits
22
22
 
23
- The gem supports MRI Ruby 3.3 or newer and RSpec Core 3.12 through 3.x.
23
+ The gem targets MRI Ruby 2.1 or newer and RSpec Core 3.6 or newer.
24
24
  Terminal status requires an OSC 7501-capable terminal. The formatter checks
25
25
  for a TTY and honors `TERM=dumb` but does not detect OSC support.
26
26
 
@@ -31,6 +31,6 @@ but your screen reader may need other settings.
31
31
  ## Report a barrier
32
32
 
33
33
  Open an [issue](https://github.com/cosgroveb/rspec-osc7501/issues) describing what
34
- you tried, what prevented you from using it, and what would help. Include your
35
- terminal, operating system, and assistive technology versions when relevant.
34
+ you tried and what would help. Include your terminal and assistive
35
+ technology versions when relevant.
36
36
  You do not need to disclose a disability or other medical information.
data/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.2.0 - 2026-11-15
6
+
7
+ - Tighten repo prose and code comments ([ad3fb64](https://github.com/cosgroveb/rspec-osc7501/commit/ad3fb64399f0b72783551d8bd42eb5dfe0116e07))
8
+ - Restore README install group and run context ([a043720](https://github.com/cosgroveb/rspec-osc7501/commit/a043720de24775d7b76bfcc6fcbf22cab5773469))
9
+ - Add version policy and release script usability fixes ([26257be](https://github.com/cosgroveb/rspec-osc7501/commit/26257be86d020c8ddb855c79efdf1ad27d1a8da5))
10
+ - Show the current example in the terminal title \(\#20\) ([f751207](https://github.com/cosgroveb/rspec-osc7501/commit/f7512077e22b463ad068f091de2ef5512f09739b))
11
+
12
+ ## 0.1.4 - 2026-11-11
13
+
14
+ - Allow newer RSpec versions and test RSpec 4 ([a3f8f5d](https://github.com/cosgroveb/rspec-osc7501/commit/a3f8f5decaf8d27328dd9dcc14536b8b8f4a35cb))
15
+ - Configure local Ruby and OSC spec reporting ([495f6be](https://github.com/cosgroveb/rspec-osc7501/commit/495f6be57799835da5ceddddd23e44a1cee4ca9d))
16
+ - Add managed RSpec child reporting \(\#13\) ([7e6d4c1](https://github.com/cosgroveb/rspec-osc7501/commit/7e6d4c15d8e210da0ff9cf90ecf05248d1863b5e))
17
+
5
18
  ## 0.1.3 - 2026-11-10
6
19
 
7
20
  - Support Ruby 2.1 and RSpec 3.6 ([5afb73d](https://github.com/cosgroveb/rspec-osc7501/commit/5afb73d1ededebcafbcb81096e6bb024f791a46c))
data/CONTRIBUTING.md CHANGED
@@ -3,10 +3,10 @@
3
3
  Follow the [code of conduct](CODE_OF_CONDUCT.md). Report vulnerabilities through
4
4
  the private channel in [SECURITY.md](SECURITY.md).
5
5
 
6
- AI-assisted contributions are welcome. Before requesting review, understand
7
- the changes, run relevant checks, and verify claims in code, documentation,
8
- and reports. State what you tested and what remains uncertain. Be prepared to
9
- explain your choices and address feedback. When using an agent to help answer
6
+ I welcome AI-assisted contributions. Before requesting review, understand
7
+ the changes and verify the claims in the affected code and docs. Run the
8
+ relevant checks. State what you tested and what remains uncertain. Be prepared to
9
+ explain your choices and address feedback. If you use an agent to help answer
10
10
  a reviewer, check the answer and send only what is relevant.
11
11
 
12
12
  Use MRI Ruby 3.3 or newer for development tooling. Install actionlint 1.7.12 on your PATH, then run all checks:
@@ -29,7 +29,7 @@ defined order because their interrupt and fail-fast cases depend on sequence.
29
29
 
30
30
  Keep runtime dependencies limited to `rspec-core`. Cover formatter behavior with
31
31
  specs and lifecycle changes with real RSpec subprocesses. Check RSpec 3.6 through
32
- 3.13 when changing early-stop detection.
32
+ 3.13 and the RSpec 4 preview when changing early-stop detection.
33
33
 
34
34
  Build the gem and documentation:
35
35
 
@@ -46,7 +46,7 @@ passing and failing suites without loading the checkout's library.
46
46
 
47
47
  ## Runtime compatibility
48
48
 
49
- The gem supports MRI Ruby 2.1 or newer and RSpec Core 3.6 through 3.x.
49
+ The gem targets MRI Ruby 2.1 or newer and RSpec Core 3.6 or newer.
50
50
  Use `Gemfile.compat` to test the formatter without modern lint, release or RDoc
51
51
  dependencies. On Ruby 2.1, install Bundler 1.17.3 first. Set the RSpec version
52
52
  before resolving dependencies:
@@ -65,13 +65,14 @@ Remove `Gemfile.compat.lock` before changing RSpec versions. Keep it out of comm
65
65
  The compatibility bundle pins diff-lcs 1.3 so test dependencies install on Ruby 2.1.
66
66
  CI checks the oldest Ruby against both RSpec endpoints, the oldest RSpec on modern
67
67
  Ruby, and the Debian Bullseye and Bookworm version families. These jobs run the
68
- formatter suite and installed-gem smoke checks. Modern jobs also test release
69
- automation, lint and documentation.
68
+ formatter suite and installed-gem smoke checks. The main development job also
69
+ runs lint and documentation checks.
70
+ CI also checks RSpec 4.0.0.beta1 on Ruby 4.0.
70
71
 
71
72
  Compatibility checks use available patch releases within each Ruby series.
72
73
  Supporting an older runtime does not extend its upstream security maintenance.
73
- Unset `BUNDLE_GEMFILE`, `RSPEC_MINOR` and `RSPEC_CORE_VERSION` before returning to
74
- the modern development bundle.
74
+ Unset `BUNDLE_GEMFILE`, `RSPEC_MINOR`, `RSPEC_CORE_VERSION` and `RSPEC_VERSION`
75
+ before returning to the modern development bundle.
75
76
 
76
77
  Update usage or behavior documentation for user-visible changes. Write commit
77
78
  subjects that describe the change, because release notes use those subjects.
@@ -86,7 +87,7 @@ stable version greater than the current release:
86
87
  gh workflow run release.yml --ref main -f version=NEW_VERSION
87
88
  ```
88
89
 
89
- The workflow captures `main`, updates `VERSION`, and generates CHANGELOG bullets
90
+ The workflow captures `main` and updates `VERSION`. It generates CHANGELOG bullets
90
91
  from non-merge commit subjects since the previous release tag. It preserves
91
92
  older changelog sections and uses the same notes for the GitHub Release.
92
93
  Versions must use `major.minor.patch` without a `v` prefix or prerelease suffix.
@@ -94,8 +95,8 @@ A new version must exceed the current version and include new commits.
94
95
 
95
96
  The full CI matrix tests the prepared release commit before the workflow pushes
96
97
  it and its tag together. If `main` advances during testing, the workflow stops.
97
- After the push, it publishes to RubyGems, then creates the GitHub Release. No
98
- intermediate approval is required.
98
+ After the push, it publishes to RubyGems, then creates the GitHub Release
99
+ without waiting for approval.
99
100
 
100
101
  If a release fails, inspect its logs and rerun the same version. If its tag
101
102
  already exists, the workflow tests and resumes that tagged release instead of
data/README.md CHANGED
@@ -1,15 +1,11 @@
1
1
  # rspec-osc7501
2
2
 
3
- Report RSpec suite activity, progress and results to terminals that support
3
+ Report RSpec suite progress and results to terminals that support
4
4
  [OSC 7501](https://www.superlogical.com/rex/docs/build/program-status).
5
- Use the formatter alongside RSpec's progress or documentation formatter.
6
-
7
- Requires MRI Ruby 2.1 or newer and `rspec-core >= 3.6, < 4`.
5
+ Requires MRI Ruby 2.1 or newer and `rspec-core >= 3.6`.
8
6
 
9
7
  ## Install
10
8
 
11
- Add the gem to your Gemfile:
12
-
13
9
  ```ruby
14
10
  group :test do
15
11
  gem "rspec"
@@ -17,32 +13,20 @@ group :test do
17
13
  end
18
14
  ```
19
15
 
20
- Run `bundle install`.
21
-
22
- ## Run
23
-
24
- Run your specs in a terminal that supports OSC 7501:
16
+ ## Run your specs in a terminal that supports OSC 7501:
25
17
 
26
18
  ```sh
27
19
  bundle exec rspec --require rspec/osc7501 \
28
20
  --format progress --format RSpec::OSC7501::Formatter
29
21
  ```
30
22
 
31
- Keep `--format progress` to see RSpec's dots, failures and summary. The OSC
32
- formatter reports completed examples and the final suite result through terminal
33
- status records. Requiring `rspec/osc7501` registers the formatter without selecting
34
- it.
35
-
36
- To check the emitted records without terminal support, force output through a
37
- pipe:
23
+ Keep `--format progress` to see RSpec's dots and summary. Requiring
24
+ `rspec/osc7501` registers the formatter without selecting it.
38
25
 
39
- ```sh
40
- RSPEC_OSC7501=force bundle exec rspec --require rspec/osc7501 \
41
- --format progress --format RSpec::OSC7501::Formatter | cat -v
42
- ```
43
-
44
- Look for `^[]7501;` records alongside RSpec output. A normal completed run ends
45
- with a `state=done` or `state=error` record.
26
+ Reporting also sets the terminal title. While examples run, the title is
27
+ `rspec › <current example>`. The title returns to `rspec` on completion,
28
+ failure, and interruption. Titles are sanitized and capped at 512 bytes
29
+ including the `rspec › ` prefix.
46
30
 
47
31
  ## Configure
48
32
 
@@ -51,22 +35,10 @@ with a `state=done` or `state=error` record.
51
35
  | `RSPEC_OSC7501` | `auto` emits to a TTY unless `TERM=dumb`, `off` disables output, `force` overrides both checks | `auto` |
52
36
  | `RSPEC_OSC7501_TITLE` | Title for the suite's status records | `RSpec` |
53
37
 
54
- The formatter uses the output stream RSpec assigns, including `--out`. Default
55
- mode emits nothing to redirected streams. Use one reporting RSpec process per
56
- terminal. Concurrent processes overwrite the same status record.
57
-
58
- Early stops report `idle` unless failure conditions take precedence. Termination
59
- that bypasses formatter callbacks can leave the last status in place. See
60
- [behavior and limits](doc/behavior.rdoc) for classification details.
61
-
62
38
  ## Documentation
63
39
 
64
40
  - [Usage recipes](doc/usage.rdoc): persistent configuration and output routing.
65
- - [Behavior and reference](doc/behavior.rdoc): progress, terminal states and limits.
66
- - [Contributing](CONTRIBUTING.md): development and verification commands.
67
- - [Accessibility](ACCESSIBILITY.md): text output and reporting barriers.
68
- - [Security policy](SECURITY.md): supported releases and private reporting.
69
- - [Code of conduct](CODE_OF_CONDUCT.md): participation and conduct reports.
70
- - [Changelog](CHANGELOG.md).
41
+ - [Behavior and limits](doc/behavior.rdoc): terminal states and concurrency.
42
+ - [Contributing](CONTRIBUTING.md), [accessibility](ACCESSIBILITY.md), [security](SECURITY.md), [code of conduct](CODE_OF_CONDUCT.md), [changelog](CHANGELOG.md)
71
43
 
72
44
  Licensed under [Apache License 2.0](LICENSE).
data/SECURITY.md CHANGED
@@ -11,8 +11,9 @@ Older releases do not receive security backports.
11
11
  Use [GitHub private vulnerability reporting](https://github.com/cosgroveb/rspec-osc7501/security/advisories/new).
12
12
  Do not disclose vulnerabilities in public issues or pull requests.
13
13
 
14
- Include the affected gem, Ruby, and RSpec versions, steps or a small example
15
- that reproduces the problem, and the impact. Include terminal and tmux versions
14
+ Include the affected gem and RSpec versions you are running. Add your Ruby
15
+ version, plus steps or a small example that reproduces the problem, and
16
+ describe the impact. Include terminal and tmux versions
16
17
  when relevant. Remove credentials and unrelated private data from examples.
17
18
 
18
19
  I review reports and coordinate a fix and public disclosure with the reporter.
data/doc/behavior.rdoc CHANGED
@@ -22,8 +22,25 @@ Settings apply when RSpec constructs the formatter.
22
22
 
23
23
  Other mode values raise ArgumentError. A supporting terminal determines how to
24
24
  display status. The formatter sends no capability query and reads no stdin.
25
- Use one reporting RSpec process per terminal. Concurrent processes replace the
26
- same root status record, without worker aggregation.
25
+ Without a child ID, concurrent processes replace the same root status record.
26
+ Managed invocations use separate named records without worker aggregation.
27
+
28
+ == Managed child context
29
+
30
+ <tt>RSPEC_OSC7501_ID</tt> selects a named record. Omit it for standalone root
31
+ behavior. IDs contain one to eight slash-separated ASCII segments using
32
+ <tt>A-Z a-z 0-9 _ . + -</tt>. Each segment allows 1 to 32 bytes and the whole ID
33
+ allows at most 128 bytes. An empty or invalid ID silences OSC output rather than
34
+ writing to the root record. It leaves ordinary output and exit status unchanged.
35
+
36
+ The optional <tt>rspec/osc7501/managed</tt> preload selects OSC only with valid
37
+ context and without <tt>RSPEC_OSC7501=off</tt>. It waits for RSpec's configured
38
+ formatters, preserves its default formatter, and adds OSC only when none exists.
39
+ An existing OSC selection keeps its output stream. The preload isolates RSpec's
40
+ private formatter-loader seam to the configured instance.
41
+
42
+ Managed child records remain after completion. Parent tools report their own
43
+ outcomes. A successful suite summary does not establish later process success.
27
44
 
28
45
  == Progress and outcomes
29
46
 
@@ -70,7 +87,7 @@ exit hook.
70
87
 
71
88
  == Wire format
72
89
 
73
- Each frame addresses the root record, repeats <tt>app=rspec</tt>, title, and
90
+ Each frame addresses the root record unless a valid child ID is supplied, repeats <tt>app=rspec</tt>, title, and
74
91
  message, and ends with ST (ESC followed by a backslash). The formatter writes each
75
92
  frame in one call and sends no clear-on-close record.
76
93
 
@@ -80,6 +97,11 @@ replaces invalid encoding, and truncates on character boundaries. Decoded titles
80
97
  are at most 192 bytes, decoded messages at most 2048 bytes, and frames at most
81
98
  4096 bytes.
82
99
 
100
+ Each status update is preceded by an OSC 2 window title: <tt>rspec › example</tt>
101
+ while an example runs, the bare prefix <tt>rspec</tt> otherwise. Window titles are
102
+ sanitized like messages, truncated on character boundaries, and at most 512 bytes
103
+ including the prefix.
104
+
83
105
  Before sanitization, the formatter keeps at most 288 input bytes for titles and
84
106
  3072 for messages. This bounds sanitization work with 50% headroom for stripped
85
107
  controls. Control-heavy input can produce shorter output. A character split by
@@ -90,7 +112,8 @@ instance. Other exceptions propagate.
90
112
 
91
113
  == Compatibility
92
114
 
93
- The gem requires Ruby >= 2.1 and <tt>rspec-core</tt> >= 3.6, < 4. MRI is the
94
- supported Ruby engine. Other engines and RSpec 4 are unverified. Runtime
115
+ The gem requires Ruby >= 2.1 and <tt>rspec-core</tt> >= 3.6. MRI is the
116
+ supported Ruby engine. CI also checks RSpec 4.0.0.beta1 on Ruby 4.0.
117
+ Other engines are unverified. Runtime
95
118
  compatibility does not extend upstream security maintenance for older Ruby versions.
96
119
  Development tools use modern Ruby, as described in CONTRIBUTING.md.
data/doc/usage.rdoc CHANGED
@@ -52,3 +52,19 @@ is <tt>RSpec</tt>.
52
52
 
53
53
  Set <tt>RSPEC_OSC7501=off</tt> to disable frames without changing the formatter
54
54
  configuration. See {Behavior}[rdoc-ref:doc/behavior.rdoc] for settings and limits.
55
+
56
+ == Run through Rake (optional)
57
+
58
+ Install <tt>rake-osc7501</tt> alongside this gem and load the RSpec task class
59
+ before the integration in your Rakefile:
60
+
61
+ require 'rspec/core/rake_task'
62
+ require 'rake/osc7501'
63
+ RSpec::Core::RakeTask.new(:spec)
64
+
65
+ Run <tt>bundle exec rake spec</tt>. Rake assigns a child record and preloads
66
+ <tt>rspec/osc7501/managed</tt>. Existing formatter choices and their destinations
67
+ remain intact. Without an explicit formatter, ordinary progress remains visible.
68
+ Use <tt>RAKE_OSC7501=off</tt> to disable the parent's automatic activation or
69
+ <tt>RSPEC_OSC7501=off</tt> to silence the child. Child results remain after Rake
70
+ finishes, including a failed child tolerated with <tt>fail_on_error = false</tt>.
@@ -5,7 +5,7 @@ require 'English'
5
5
  module RSpec
6
6
  # Reports RSpec suite status through OSC 7501 terminal records.
7
7
  module OSC7501
8
- # RSpec formatter for suite activity, progress, and final results.
8
+ # RSpec formatter for suite progress and final results.
9
9
  # Select alongside an ordinary formatter to retain RSpec's text output.
10
10
  class Formatter
11
11
  RSpec::Core::Formatters.register self, :start, :example_started, :example_passed,
@@ -16,7 +16,7 @@ module RSpec
16
16
  # The optional +clock+ callable returns monotonic seconds for throttling.
17
17
  def initialize(output, clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) })
18
18
  @writer = Writer.new(output, mode: ENV.fetch('RSPEC_OSC7501', 'auto'),
19
- title: ENV.fetch('RSPEC_OSC7501_TITLE', 'RSpec'))
19
+ title: ENV.fetch('RSPEC_OSC7501_TITLE', 'RSpec'), id: ENV['RSPEC_OSC7501_ID'])
20
20
  @clock = clock
21
21
  @started = false
22
22
  @summarized = false
@@ -61,7 +61,7 @@ module RSpec
61
61
  update
62
62
  end
63
63
 
64
- # Emits the final state, counts, and duration from RSpec's summary.
64
+ # Emits the final state and counts from RSpec's summary.
65
65
  # Final output bypasses throttling and omits progress.
66
66
  def dump_summary(notification)
67
67
  active_exception = $ERROR_INFO
@@ -92,7 +92,7 @@ module RSpec
92
92
  message += ", #{@failed} failures" if @failed > 0
93
93
  message += ", #{@pending} pending" if @pending > 0
94
94
  message += ": #{@current}" if @current
95
- @writer.emit(state: 'working', msg: message, progress: progress)
95
+ @writer.emit(state: 'working', msg: message, progress: progress, window_title: @current)
96
96
  @last_update = now
97
97
  end
98
98
 
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../osc7501'
4
+
5
+ module RSpec
6
+ module OSC7501
7
+ # Installs an additive formatter when a managed child ID is present.
8
+ module Managed
9
+ # Isolate RSpec's private formatter-loader seam to this configuration.
10
+ module Loader # :nodoc: all
11
+ def setup_default(output_stream, deprecation_stream)
12
+ super
13
+ add Formatter, output_stream unless formatters.any? { |formatter| formatter.is_a?(Formatter) }
14
+ end
15
+ end
16
+
17
+ def self.install!(configuration = RSpec.configuration)
18
+ return false unless Writer.valid_id?(ENV['RSPEC_OSC7501_ID'])
19
+ return false if ENV['RSPEC_OSC7501'] == 'off'
20
+
21
+ loader = configuration.send(:formatter_loader)
22
+ return false if loader.is_a?(Loader)
23
+
24
+ loader.singleton_class.prepend(Loader)
25
+ true
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ RSpec::OSC7501::Managed.install!
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module OSC7501
5
- VERSION = '0.1.3'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
@@ -3,20 +3,32 @@
3
3
  module RSpec
4
4
  module OSC7501
5
5
  class Writer # :nodoc: all
6
- def initialize(output, mode:, title:)
6
+ TITLE_BYTE_LIMIT = 512
7
+ TITLE_PREFIX = 'rspec'
8
+
9
+ def self.valid_id?(id)
10
+ id.is_a?(String) && id.ascii_only? && id.bytesize <= 128 &&
11
+ !!(id =~ %r{\A[A-Za-z0-9_.+-]{1,32}(?:/[A-Za-z0-9_.+-]{1,32}){0,7}\z})
12
+ end
13
+
14
+ def initialize(output, mode:, title:, id: nil)
7
15
  raise ArgumentError, 'RSPEC_OSC7501 must be auto, off, or force' unless %w[auto off force].include?(mode)
8
16
 
9
17
  @output = output
10
- @enabled = mode == 'force' || (mode == 'auto' && automatic_output?)
11
- @title = encode(title, 192) if @enabled
18
+ @id = id
19
+ @enabled = (id.nil? || self.class.valid_id?(id)) &&
20
+ output_enabled?(mode)
21
+ @title = [sanitize(title, 192)].pack('m0') if @enabled
12
22
  rescue IOError, SystemCallError
13
23
  @enabled = false
14
24
  end
15
25
 
16
- def emit(state:, msg:, progress: nil)
26
+ def emit(state:, msg:, progress: nil, window_title: nil)
17
27
  return unless @enabled
18
28
 
19
- fields = ['app=rspec', "title=#{@title}", "state=#{state}", "msg=#{encode(msg, 2048)}"]
29
+ write_window_title(window_title)
30
+ fields = ['app=rspec', "title=#{@title}", "state=#{state}", "msg=#{[sanitize(msg, 2048)].pack('m0')}"]
31
+ fields << "id=#{@id}" if @id
20
32
  fields << "progress=#{[[progress.to_i, 0].max, 100].min}" if state == 'working' && !progress.nil?
21
33
  @output.write("\e]7501;#{fields.join(':')}\e\\")
22
34
  @output.flush if @output.respond_to?(:flush)
@@ -26,19 +38,29 @@ module RSpec
26
38
 
27
39
  private
28
40
 
41
+ # Compose only after sanitizing the name so binary input cannot mix encodings.
42
+ def write_window_title(name_input)
43
+ name = name_input && sanitize(name_input, TITLE_BYTE_LIMIT)
44
+ title = name && !name.empty? && sanitize(TITLE_PREFIX + " › #{name}", TITLE_BYTE_LIMIT)
45
+ @output.write("\e]2;#{title || TITLE_PREFIX}\e\\")
46
+ end
47
+
48
+ def output_enabled?(mode)
49
+ mode == 'force' || (mode == 'auto' && automatic_output?)
50
+ end
51
+
29
52
  def automatic_output?
30
53
  ENV['TERM'] != 'dumb' && @output.respond_to?(:tty?) && @output.tty?
31
54
  end
32
55
 
33
- def encode(text, byte_limit)
56
+ def sanitize(text, byte_limit)
34
57
  input = text.to_s.byteslice(0, sanitization_byte_limit(byte_limit))
35
58
  clean = input.encode('UTF-8', invalid: :replace, undef: :replace).gsub(/[\u0000-\u001F\u007F-\u009F]/, '')
36
59
  bytes = 0
37
- bounded = clean.each_char.take_while do |char|
60
+ clean.each_char.take_while do |char|
38
61
  bytes += char.bytesize
39
62
  bytes <= byte_limit
40
63
  end.join
41
- [bounded].pack('m0')
42
64
  end
43
65
 
44
66
  # Bound sanitization work with 50% headroom for stripped controls.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-osc7501
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Cosgrove
@@ -16,9 +16,6 @@ dependencies:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
18
  version: '3.6'
19
- - - "<"
20
- - !ruby/object:Gem::Version
21
- version: '4'
22
19
  type: :runtime
23
20
  prerelease: false
24
21
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,9 +23,6 @@ dependencies:
26
23
  - - ">="
27
24
  - !ruby/object:Gem::Version
28
25
  version: '3.6'
29
- - - "<"
30
- - !ruby/object:Gem::Version
31
- version: '4'
32
26
  description: Reports RSpec suite progress and outcomes through OSC 7501.
33
27
  email:
34
28
  - cosgroveb@users.noreply.github.com
@@ -47,6 +41,7 @@ files:
47
41
  - doc/usage.rdoc
48
42
  - lib/rspec/osc7501.rb
49
43
  - lib/rspec/osc7501/formatter.rb
44
+ - lib/rspec/osc7501/managed.rb
50
45
  - lib/rspec/osc7501/version.rb
51
46
  - lib/rspec/osc7501/writer.rb
52
47
  homepage: https://github.com/cosgroveb/rspec-osc7501