pty_compat 1.0.0 → 2.0.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: ce2fec7856c5d46fb0b88e0f0ecc86828593ae8eb0ee1559c7778b35607902a1
4
- data.tar.gz: 5dcaaf25e175c108f3fb04cf74a8b4ae0c03b898afea3dbb0b40be14547d4edc
3
+ metadata.gz: 605c5beef7aef4410452b3aa58901922af3b6160e45f94d837e01723802478a7
4
+ data.tar.gz: ba36e3cd17a5b253060555391edd07ba57ebd2fc0661c765151e384409b30623
5
5
  SHA512:
6
- metadata.gz: f3411c48494e354226b1d8178e845d4912648648a03d5a54017583bbc9fb0adbbbf4c90d52d7a4ed70aa1b692e158621f0ac1529bd2a320e6e42dc870a4183a1
7
- data.tar.gz: 1e9e6956e34c4cdba26db42f3e9e2d1499829a6fe3d3298c2e7cae3763915dd4c4667889b2f3e03c61abeacd1af25e37997a8f056a1143dd6a59691bf2d27034
6
+ metadata.gz: 93fe06ab67bff3a137640e554711b9c724c7887f1fbf0750982d52f37552d038271c4dd9a60a676eac0a1f991e7178ad04f99281f1c95b9f8ed17be4b3670088
7
+ data.tar.gz: aaca962bad94df726007215f39a3663ce0449a44285cdb528330c182a452c5e71d6c58d5f2274108a6d5938097f37a99f8602d02a84fcf493d9fe0bfab833de9
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
- # [v0.0.1](https://github.com/Muriel-Salvan/pty_compat/compare/...v0.0.1) (2026-06-29 12:55:30)
1
+ # [v2.0.0](https://github.com/Muriel-Salvan/pty_compat/compare/v1.0.0...v2.0.0) (2026-07-01 08:19:49)
2
+
3
+ ### Breaking changes
4
+
5
+ * [[breaking] refactor!: replace `PTY.last_status` with `Process::Status.wait`](https://github.com/Muriel-Salvan/pty_compat/commit/eb0a772a4576e24a4b269525472d5a596913f0c8)
6
+
7
+ # [v1.0.0](https://github.com/Muriel-Salvan/pty_compat/compare/...v0.0.1) (2026-06-29 12:55:30)
2
8
 
3
9
  ### Patches
4
10
 
data/README.md CHANGED
@@ -73,7 +73,7 @@ PTY.spawn('ping', '-c', '3', 'example.com') do |reader, writer, pid|
73
73
  end
74
74
 
75
75
  # Retrieve the exit status portably
76
- status = PTY.last_status
76
+ status = Process::Status.wait
77
77
  ```
78
78
 
79
79
  ## Requirements
@@ -84,7 +84,7 @@ status = PTY.last_status
84
84
  ## Features
85
85
 
86
86
  - **Zero-config drop-in.** A single `require` replaces `PTY.spawn` on Windows — no configuration, no platform checks, no conditional logic.
87
- - **Portable exit status.** Use `PTY.last_status` to retrieve the exit code on any platform instead of relying on `$?`.
87
+ - **Portable exit status.** Use `Process::Status.wait` to retrieve the exit code on any platform.
88
88
  - **Non-block & block forms.** Supports both `PTY.spawn(command, args...) -> [reader, writer, pid]` and `PTY.spawn(command, args...) { |reader, writer, pid| ... }` forms.
89
89
  - **Windows support.** Leverages Microsoft's [`node-pty`](https://github.com/microsoft/node-pty) to provide a proper PTY on Windows, where Ruby's native `PTY` is unavailable.
90
90
  - **Lightweight.** The Ruby codebase is minimal, delegating the heavy lifting to a well-maintained native module.
@@ -113,16 +113,16 @@ Spawns a new process attached to a pseudo-terminal.
113
113
 
114
114
  **Block form** yields `reader`, `writer`, and `pid` to the given block, and automatically closes the IOs after the block returns.
115
115
 
116
- ### `PTY.last_status -> Process::Status | nil`
116
+ ### `Process::Status.wait -> Process::Status | nil`
117
117
 
118
118
  Returns the exit status of the last spawned process.
119
119
 
120
- - On platforms with native `PTY`, mirrors `$?`.
120
+ - On platforms with native `PTY`, uses the default `Process::Status.wait`.
121
121
  - On the fallback path, returns a `Process::Status` constructed from the exit code captured by the `node-pty` bridge.
122
122
  - Returns `nil` if no process has been spawned yet or if the last spawn failed.
123
123
 
124
124
  > [!TIP]
125
- > Prefer `PTY.last_status` over `$?` for portable code that runs on both Windows and Unix.
125
+ > Use `Process::Status.wait` for portable code that runs on both Windows and Unix.
126
126
 
127
127
  ## Documentation
128
128
 
@@ -149,10 +149,6 @@ Returns the exit status of the last spawned process.
149
149
  └──────────────┘
150
150
  ```
151
151
 
152
- ### `PTY.last_status`
153
-
154
- On platforms with native `PTY`, `PTY.last_status` returns `$?` (`Process::Status`). On the fallback path, the bridge captures the exit code and exposes it through the same method. Prefer this over `$?` for portable code.
155
-
156
152
  ### Why not a pure Ruby PTY?
157
153
 
158
154
  Alternative approaches rely on platform-specific C extensions that are painful to compile on Windows, or expose an incomplete `PTY` interface. `pty_compat` delegates the heavy lifting to [`node-pty`](https://github.com/microsoft/node-pty), a well-maintained native module by Microsoft that supports Windows, macOS, and Linux. This keeps the Ruby code small and the platform coverage broad.
@@ -32,10 +32,10 @@ module PtyCompat
32
32
  end
33
33
  end
34
34
 
35
- # @return [Process::Status] Last process status
36
- def last_status
37
- @last_wait_thr.value
38
- end
35
+ # @!group Internal
36
+
37
+ # @return [Process::Waiter] The last process waiter
38
+ attr_reader :last_wait_thr
39
39
 
40
40
  private
41
41
 
@@ -1,17 +1,5 @@
1
1
  require 'English'
2
2
 
3
- # Augment PTY module with last_status
4
- module PTY
5
- # @!group Public API
6
-
7
- # @return [Process::Status] Last process status.
8
- # Use this instead of $? as some workaround methods don't set $? properly and we can't modify this variable.
9
- def self.last_status
10
- # Default implementation
11
- $CHILD_STATUS
12
- end
13
- end
14
-
15
3
  begin
16
4
  require 'pty'
17
5
  rescue LoadError => e
@@ -22,5 +10,14 @@ rescue LoadError => e
22
10
  prepend PtyCompat::NodePty
23
11
  end
24
12
  end
13
+
14
+ module Process
15
+ class Status
16
+ class << self
17
+ # Fallback on getting process status from POpen3
18
+ prepend PtyCompat::ProcessStatusFromPopen3
19
+ end
20
+ end
21
+ end
25
22
  end
26
23
  end
@@ -0,0 +1,18 @@
1
+ module PtyCompat
2
+ # Provide a similar interface as the Process::Status.wait one that can return the PoOpen3 last process status,
3
+ # so that it works the same as Ruby's native PTY interface.
4
+ module ProcessStatusFromPopen3
5
+ # Wait for the last pid to end and return the corresponding Process Status.
6
+ #
7
+ # @param pid [Integer] PID to wait for
8
+ # @param flags [Integer] Flags
9
+ # @return [Process::Status] Corresponding process status
10
+ def wait(pid = -1, flags = 0)
11
+ if pid == -1 && flags.zero? && PTY.last_wait_thr
12
+ PTY.last_wait_thr.value
13
+ else
14
+ super
15
+ end
16
+ end
17
+ end
18
+ end
@@ -2,5 +2,5 @@ module PtyCompat
2
2
  # @!group Public API
3
3
 
4
4
  # Gem version
5
- VERSION = '1.0.0'
5
+ VERSION = '2.0.0'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pty_compat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Muriel Salvan
@@ -35,6 +35,7 @@ files:
35
35
  - lib/pty_compat/assets/node_pty_bridge.js
36
36
  - lib/pty_compat/node_pty.rb
37
37
  - lib/pty_compat/patches/pty.rb
38
+ - lib/pty_compat/process_status_from_popen3.rb
38
39
  - lib/pty_compat/version.rb
39
40
  homepage: https://github.com/Muriel-Salvan/pty_compat
40
41
  licenses: