thor-osc7501 0.1.0 → 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: 1774a0a472abc4cc8b707ce62db5fbd78d5e31fb59e1e5816e567df2396c3c4d
4
- data.tar.gz: 0a8045f44d2890953f16bfd6964b71d5c337f40849e46a6c3c86f97f844ad7af
3
+ metadata.gz: 3b98d12d8cfe517ea8abe1f5f01fb176cfcd8d89505caaf9a766052584f2bbea
4
+ data.tar.gz: 36a5076f89aaa5b60e243049a082fa0c83f0a1878d868a5bcd8b743ff1ff3d63
5
5
  SHA512:
6
- metadata.gz: c008b9a3fee66fc44c1504b3a59658eba18f75ee636caa16852d0338f8b6d7a9f8b97c2923334ebbb724f6d370212d17c10549c36a4c1dfdbbbfeb8b6e609580
7
- data.tar.gz: a2f005c1e85162b0fefceae918fe4276d73062bf6a41986ace8c1a02e077d7ce9eb58543afe5b957383bc4eed31ec84446c355b03983151bec36e95e66553a97
6
+ metadata.gz: 80bf844d8d288cc99ece41456ae5809a660d35e731216f6ce6e1305225555fe9cee62b4eb6f0eeedf99ad2f01eb8824af5fba4dca5a66b6e000db19591f5eaaa
7
+ data.tar.gz: b8caba8a8ac56eebb11c19c34049340154a7de1e16e814db6b48bdb8794f608f0ad2f4fff5083e0db8ecf3c4d90d20b5d0c3339c97004ea45c1491c94e233f68
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.2.0 - 2026-11-15
6
+
7
+ - Show the current command in the terminal title \(\#1\) ([8fd4c10](https://github.com/cosgroveb/thor-osc7501/commit/8fd4c108313aaed11531fa82f87a81f1d3b51139))
8
+
5
9
  ## 0.1.0 - 2026-11-13
6
10
 
7
11
  - init ([8d8fc45](https://github.com/cosgroveb/thor-osc7501/commit/8d8fc45f2577583c4e60d32ed7dcc3a047ddd7e1))
data/README.md CHANGED
@@ -49,10 +49,16 @@ values never imply success or failure.
49
49
  | `THOR_OSC7501=off` | Disable Thor reporting. |
50
50
  | any other value | Raise `ArgumentError`. |
51
51
 
52
+ Reporting also sets the terminal title. While one command runs, the title is
53
+ `thor › <command>`. While several commands run in parallel, it is
54
+ `thor › <n> active commands`. The title returns to `thor` after the last
55
+ command, on completion, and on error or stop.
56
+
52
57
  Reporting IO failures disable reporting without replacing the command's own
53
58
  exception or result. Messages are sanitized to a single plain-text line and
54
- capped at 2048 decoded UTF-8 bytes. The ordinary terminal prompt is
55
- unchanged.
59
+ capped at 2048 decoded UTF-8 bytes. Window titles are sanitized the same way
60
+ and capped at 512 bytes including the `thor › ` prefix. The ordinary terminal
61
+ prompt is unchanged.
56
62
 
57
63
  ## Boundaries
58
64
 
@@ -114,9 +114,10 @@ class Thor
114
114
  active = active_commands
115
115
  return if active.empty?
116
116
  if active.size == 1
117
- @writer.emit(state: 'working', msg: active.first.last)
117
+ @writer.emit(state: 'working', msg: active.first.last, window_title: active.first.last)
118
118
  else
119
- @writer.emit(state: 'working', msg: "#{active.size} active commands")
119
+ @writer.emit(state: 'working', msg: "#{active.size} active commands",
120
+ window_title: "#{active.size} active commands")
120
121
  end
121
122
  end
122
123
 
@@ -4,6 +4,6 @@
4
4
  class Thor
5
5
  module OSC7501
6
6
  #: String
7
- VERSION = '0.1.0'
7
+ VERSION = '0.2.0'
8
8
  end
9
9
  end
@@ -6,6 +6,9 @@ class Thor
6
6
  # Encodes status records onto an output stream following the family
7
7
  # writer contract. Private to the adapter.
8
8
  class Writer # :nodoc: all
9
+ TITLE_BYTE_LIMIT = 512
10
+ TITLE_PREFIX = 'thor'
11
+
9
12
  # @rbs @output: IO | StringIO
10
13
  # @rbs @enabled: bool
11
14
 
@@ -19,13 +22,17 @@ class Thor
19
22
  @enabled = false
20
23
  end
21
24
 
22
- #: (state: String, msg: String, ?kind: String?) -> nil
23
- def emit(state:, msg:, kind: nil)
25
+ #: (state: String, msg: String, ?kind: String?, ?window_title: String?) -> nil
26
+ def emit(state:, msg:, kind: nil, window_title: nil)
24
27
  return nil unless @enabled
25
28
 
29
+ # Compose only after sanitizing the name so binary input cannot mix encodings.
30
+ name = window_title && sanitize(window_title, TITLE_BYTE_LIMIT)
31
+ title = name && !name.empty? && sanitize(TITLE_PREFIX + ' › ' + name, TITLE_BYTE_LIMIT)
32
+ @output.write("\e]2;#{title || TITLE_PREFIX}\e\\")
26
33
  fields = ['app=thor', 'title=VGhvcg==', "state=#{state}"]
27
34
  fields << "kind=#{kind}" if kind
28
- fields << "msg=#{encode(msg, 2048)}"
35
+ fields << "msg=#{[sanitize(msg, 2048)].pack('m0')}"
29
36
  @output.write("\e]7501;#{fields.join(':')}\e\\")
30
37
  @output.flush if @output.respond_to?(:flush)
31
38
  nil
@@ -43,18 +50,17 @@ class Thor
43
50
  end
44
51
 
45
52
  #: (String, Integer) -> String
46
- def encode(text, byte_limit)
53
+ def sanitize(text, byte_limit)
47
54
  input = text.to_s.byteslice(0, sanitization_byte_limit(byte_limit)) #: String
48
55
  plain = input.encode('UTF-8', invalid: :replace, undef: :replace)
49
56
  plain = plain.gsub(/\e\[[0-9;?]*[ -\/]*[@-~]/, '')
50
57
  plain = plain.gsub(/[\u0000-\u001F\u007F-\u009F]/, ' ')
51
58
  clean = plain.gsub(/\s+/, ' ').strip
52
59
  bytes = 0
53
- bounded = clean.each_char.take_while do |char|
60
+ clean.each_char.take_while do |char|
54
61
  bytes += char.bytesize
55
62
  bytes <= byte_limit
56
63
  end.join
57
- [bounded].pack('m0')
58
64
  end
59
65
 
60
66
  # Bound sanitization work with 50% headroom for removed formatting.
@@ -5,6 +5,11 @@ class Thor
5
5
  # Encodes status records onto an output stream following the family
6
6
  # writer contract. Private to the adapter.
7
7
  class Writer
8
+ # :nodoc: all
9
+ TITLE_BYTE_LIMIT: ::Integer
10
+
11
+ TITLE_PREFIX: ::String
12
+
8
13
  @output: IO | StringIO
9
14
 
10
15
  @enabled: bool
@@ -12,8 +17,8 @@ class Thor
12
17
  # : (IO | StringIO output, mode: String) -> void
13
18
  def initialize: (IO | StringIO output, mode: String) -> void
14
19
 
15
- # : (state: String, msg: String, ?kind: String?) -> nil
16
- def emit: (state: String, msg: String, ?kind: String?) -> nil
20
+ # : (state: String, msg: String, ?kind: String?, ?window_title: String?) -> nil
21
+ def emit: (state: String, msg: String, ?kind: String?, ?window_title: String?) -> nil
17
22
 
18
23
  private
19
24
 
@@ -21,7 +26,7 @@ class Thor
21
26
  def automatic_output?: () -> bool
22
27
 
23
28
  # : (String, Integer) -> String
24
- def encode: (String, Integer) -> String
29
+ def sanitize: (String, Integer) -> String
25
30
 
26
31
  # Bound sanitization work with 50% headroom for removed formatting.
27
32
  # : (Integer) -> Integer
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thor-osc7501
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Cosgrove