Skip to content

Commit a9473e9

Browse files
committed
Suspend and Resume on TSTP and CONT signals #361
ctrl-z (SIGTSTP) doesn't work with Spring, and it corrupts the terminal as mentioned by @casper in Issue #361: > the spring server is somehow attached to the PTY of the shell the solution is to: > trap SIGTSTP and tell the server to disengage from the PTY > before the client process is suspended
1 parent c034d2d commit a9473e9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Fix binstubs not being replaced when their quoting style was changed (#534)
44
* Preserve comments right after the shebang line which might include magic comments such as `frozen_string_literal: true'
55
* Fix binstub failures when Bundler's `BUNDLE_APP_CONFIG` environment variable is present (#545)
6+
* Properly suspend and resume on ctrl-z TSTP and CONT (#361)
67

78
## 2.0.2
89

lib/spring/client/run.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ def run_command(client, application)
161161
if pid && !pid.empty?
162162
log "got pid: #{pid}"
163163

164+
suspend_resume_on_tstp_cont(pid)
165+
164166
forward_signals(application)
165167
status = application.read.to_i
166168

@@ -181,6 +183,18 @@ def queue_signals
181183
end
182184
end
183185

186+
def suspend_resume_on_tstp_cont(pid)
187+
trap("TSTP") {
188+
log "suspended"
189+
Process.kill("STOP", pid.to_i)
190+
Process.kill("STOP", Process.pid)
191+
}
192+
trap("CONT") {
193+
log "resumed"
194+
Process.kill("CONT", pid.to_i)
195+
}
196+
end
197+
184198
def forward_signals(application)
185199
@signal_queue.each { |sig| kill sig, application }
186200

0 commit comments

Comments
 (0)