libtmux 0.1.0.alpha.2 → 0.1.0.alpha.3

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.
@@ -5,6 +5,7 @@ require_relative "process"
5
5
  require_relative "metadata"
6
6
  require_relative "entity"
7
7
  require_relative "tmux_version"
8
+ require_relative "native_guard"
8
9
 
9
10
  module LibTmux
10
11
  # Connects to an existing endpoint. Closing retires clients, never the daemon.
@@ -168,6 +169,7 @@ module LibTmux
168
169
  @pin = Internal::SocketIdentity.new(@endpoint)
169
170
  begin
170
171
  @release = Internal::TmuxVersion.connected(@pin.command_prefix) { |argv| @executor.run(argv, timeout: version_timeout, discard_stdout: true) }
172
+ @pin.record_release(@release)
171
173
  argv, marker = Internal::TmuxVersion.fence_check_argv
172
174
  Internal::TmuxVersion.verify_fence(@executor.run(@pin.command_prefix + argv, timeout: version_timeout), marker)
173
175
  rescue Exception
@@ -181,19 +183,14 @@ module LibTmux
181
183
  @release.text
182
184
  end
183
185
 
186
+ # True when the checked daemon accepts control clients (tmux 3.7 and newer).
187
+ def supports_control?
188
+ Internal::Capabilities.capability("control-mode").available?(@release)
189
+ end
190
+
184
191
  # Raw tmux arguments retain tmux's separators and format semantics.
185
192
  def run(argv, input: "".b, timeout: 5.0, cancel: nil)
186
- ensure_owner
187
- started = monotonic
188
- validate_argv(argv)
189
- raise ArgumentError, "raw commands cannot override endpoint flags" if argv.first.start_with?("-")
190
- raise ArgumentError, "timeout must be finite" unless timeout.is_a?(Numeric) && timeout.finite?
191
- perform_request(cancel: cancel) do |view|
192
- fence, marker = Internal::TmuxVersion.fence(@release)
193
- result = @executor.run(@pin.command_prefix + fence + argv, input: input,
194
- timeout: timeout - (monotonic - started), cancel: view)
195
- Internal::TmuxVersion.check_fence(result, marker, @release)
196
- end
193
+ dispatch(argv, input: input, timeout: timeout, cancel: cancel)
197
194
  end
198
195
 
199
196
  def close
@@ -506,8 +503,25 @@ module LibTmux
506
503
  end
507
504
  end
508
505
 
509
- def execute_typed(arguments, **options)
510
- result = run(encode_arguments(arguments), **options)
506
+ # Library operations that repair exact tmux 3.7's break-pane say so here.
507
+ def dispatch(argv, input: "".b, timeout: 5.0, cancel: nil, repaired_break: false)
508
+ ensure_owner
509
+ started = monotonic
510
+ validate_argv(argv)
511
+ raise ArgumentError, "raw commands cannot override endpoint flags" if argv.first.start_with?("-")
512
+ raise ArgumentError, "timeout must be finite" unless timeout.is_a?(Numeric) && timeout.finite?
513
+ Internal::NativeGuard.check(argv, @release, repaired_break: repaired_break)
514
+ perform_request(cancel: cancel) do |view|
515
+ fence, marker = Internal::TmuxVersion.fence(@release)
516
+ result = @executor.run(@pin.command_prefix + fence + argv, input: input,
517
+ timeout: timeout - (monotonic - started), cancel: view)
518
+ Internal::TmuxVersion.check_fence(result, marker, @release)
519
+ end
520
+ end
521
+
522
+ def execute_typed(arguments, repaired_break: false, **options)
523
+ arguments = encode_arguments(arguments)
524
+ result = repaired_break ? dispatch(arguments, repaired_break: true, **options) : run(arguments, **options)
511
525
  raise CommandError.new(result: result, phase: :command) unless result.success?
512
526
 
513
527
  result
@@ -523,6 +537,12 @@ module LibTmux
523
537
  unless name.is_a?(String) && !name.empty? && !name.include?("\0")
524
538
  raise ArgumentError, "name must be a nonempty String without NUL"
525
539
  end
540
+ # Exact tmux 3.7 rejects these in session and window names, so the
541
+ # refusal comes before any effect.
542
+ if Internal::Capabilities.workaround("name-separators-rejected").applies?(@release) && name.match?(/[:.]/)
543
+ raise UnsupportedFeatureError.new("tmux 3.7 rejects ':' and '.' in session and window names",
544
+ phase: :admission, delivery: :not_sent)
545
+ end
526
546
  name.gsub("#", "##")
527
547
  end
528
548
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "libtmux/errors"
4
+ require "libtmux/capabilities"
4
5
  require "securerandom"
5
6
 
6
7
  module LibTmux
@@ -12,6 +13,7 @@ module LibTmux
12
13
  # then fenced against that exact text.
13
14
  module TmuxVersion
14
15
  MINIMUM = "3.3a"
16
+ CONTROL_MINIMUM = Internal::Capabilities.capability("control-mode").since
15
17
  # The forms tmux has reported: X.Y, X.Y plus a patch letter, X.Y-rc and
16
18
  # X.Y-rcN candidates, and next-X.Y development builds. Anything else,
17
19
  # including master and openbsd-*, is not a release number. The candidate
@@ -44,6 +46,12 @@ module LibTmux
44
46
  Release = Data.define(:text, :key) do
45
47
  include Comparable
46
48
 
49
+ # True only for the numbered release itself, not a patch letter,
50
+ # candidate or development build of it.
51
+ def exactly?(major, minor)
52
+ key == [major, minor, 0, STABLE]
53
+ end
54
+
47
55
  def <=>(other)
48
56
  key <=> other.key if other.is_a?(Release)
49
57
  end
@@ -83,6 +91,16 @@ module LibTmux
83
91
  "tmux #{MINIMUM} or newer is required; #{REMEDY}", phase: :admission, expected: EXPECTED)
84
92
  end
85
93
 
94
+ # Control clients crash tmux servers older than 3.7 while they attach.
95
+ def require_control(release)
96
+ raise UnsupportedFeatureError.new("control connections need a version-checked server", phase: :admission) unless release
97
+
98
+ return release unless (release <=> parse(CONTROL_MINIMUM)).negative?
99
+
100
+ raise UnsupportedFeatureError.new("control connections require tmux #{CONTROL_MINIMUM} or newer " \
101
+ "(connected version #{release.text})", phase: :admission, delivery: :not_sent)
102
+ end
103
+
86
104
  # Reads the daemon behind +prefix+. The block runs the argv and returns a
87
105
  # CommandResult. Unlike display-message, run-shell -C fires no after-*
88
106
  # hook and no command-error hook: tmux parses the expanded string after
@@ -125,6 +143,25 @@ module LibTmux
125
143
  raise not_sent(error), cause: nil
126
144
  end
127
145
 
146
+ # Reads daemon values through the probe's error text, which fires no
147
+ # hook, unlike display-message. tmux reports only the first unparseable
148
+ # word, so the fields expand to one comma-joined word.
149
+ def identity_argv(fields)
150
+ marker = "libtmux-identity-#{SecureRandom.hex(16)}-"
151
+ [[PROBE_COMMAND, "-C", marker + fields.map { |field| "\#{#{field}}" }.join(",")], marker]
152
+ end
153
+
154
+ def parse_identity(result, marker, count)
155
+ stderr = result.stderr.b
156
+ match = /\Aunknown command: #{Regexp.escape(marker.b)}([^\n ]*)\n\z/n.match(stderr)
157
+ values = match && match[1].split(",", -1)
158
+ unless !result.success? && result.stdout.empty? && values && values.length == count
159
+ raise ProtocolError.new("tmux did not report the requested identity", delivery: :observed, phase: :decode)
160
+ end
161
+
162
+ values.map(&:freeze)
163
+ end
164
+
128
165
  # Leading commands for one dispatch. A daemon that no longer reports
129
166
  # +release+ fails the if-shell condition and reaches the private marker,
130
167
  # which tmux rejects before the commands that follow.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LibTmux
4
- VERSION = "0.1.0.alpha.2"
4
+ VERSION = "0.1.0.alpha.3"
5
5
  end
data/sig/libtmux.rbs CHANGED
@@ -157,6 +157,7 @@ module LibTmux
157
157
  | (?endpoint: Endpoint?, ?socket_path: String?, ?socket_name: String?, ?executable: String, ?max_requests: Integer, ?max_controls: Integer, ?close_timeout: Numeric, ?version_timeout: Numeric) -> Server
158
158
  def initialize: (?endpoint: Endpoint?, ?socket_path: String?, ?socket_name: String?, ?executable: String, ?max_requests: Integer, ?max_controls: Integer, ?close_timeout: Numeric, ?version_timeout: Numeric) -> void
159
159
  def tmux_version: () -> String
160
+ def supports_control?: () -> bool
160
161
  def run: (Array[String], ?input: String, ?timeout: Numeric, ?cancel: untyped) -> CommandResult
161
162
  def close: () -> nil
162
163
  def diagnostics: () -> {admitted_requests: Integer, reserved_process_slots: Integer, control_connections: Integer, closed: bool, limits: {max_requests: Integer, max_controls: Integer, close_timeout: Numeric}}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libtmux
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.alpha.2
4
+ version: 0.1.0.alpha.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - libtmux contributors
@@ -90,6 +90,7 @@ files:
90
90
  - assets/logo.png
91
91
  - assets/logo.svg
92
92
  - lib/libtmux.rb
93
+ - lib/libtmux/capabilities.rb
93
94
  - lib/libtmux/capture.rb
94
95
  - lib/libtmux/catalog.rb
95
96
  - lib/libtmux/child.rb
@@ -100,6 +101,7 @@ files:
100
101
  - lib/libtmux/errors.rb
101
102
  - lib/libtmux/group.rb
102
103
  - lib/libtmux/metadata.rb
104
+ - lib/libtmux/native_guard.rb
103
105
  - lib/libtmux/operations.rb
104
106
  - lib/libtmux/options.rb
105
107
  - lib/libtmux/owned.rb
@@ -129,7 +131,7 @@ licenses:
129
131
  - MIT
130
132
  metadata:
131
133
  source_code_uri: https://github.com/libtmux/libtmux-ruby
132
- documentation_uri: https://libtmux.org/en/ruby/v0.1.0.alpha.2/
134
+ documentation_uri: https://libtmux.org/en/ruby/v0.1.0.alpha.3/
133
135
  rdoc_options: []
134
136
  require_paths:
135
137
  - lib