Skip to content

Commit

Permalink
feat: go runtime abort on Ctrl+\
Browse files Browse the repository at this point in the history
  • Loading branch information
knz committed Oct 7, 2022
1 parent 230ace4 commit 6185a24
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
10 changes: 10 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,13 @@ func WithoutJobControl() ProgramOption {
p.disableSuspendOnCtrlZ = true
}
}

// WithoutGoStandardAbort disables support for sending SIGQUIT
// to the process (and generating a goroutine dump) when
// Ctrl+\ is pressed. By default, Ctrl+\ causes SIGQUIT to be
// emitted, this is a standard Go feature.
func WithoutGoStandardAbort() ProgramOption {
return func(p *Program) {
p.disableGoStandardAbort = true
}
}
17 changes: 16 additions & 1 deletion tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ type Program struct {
// (suspend process).
disableSuspendOnCtrlZ bool

// disableGoStandardAbort removes direct bubbletea support for Ctrl+\
// (SIGQUIT / goroutine dump).
disableGoStandardAbort bool

ignoreSignals bool

killc chan bool
Expand Down Expand Up @@ -419,10 +423,21 @@ func (p *Program) StartReturningModel() (Model, error) {
}()

case KeyMsg:
if !p.disableSuspendOnCtrlZ && msg.Type == KeyCtrlZ && !msg.Alt {
if !p.disableSuspendOnCtrlZ && !msg.Alt && msg.Type == KeyCtrlZ {
cmds <- Suspend()
continue
}
if !p.disableGoStandardAbort && !msg.Alt && msg.Type == KeyCtrlBackslash {
cmds <- Exec(fnAsCommand(func() {
pr, err := os.FindProcess(os.Getpid())
if err != nil {
// No-op.
return
}
_ = pr.Signal(syscall.SIGQUIT)
}), nil)
continue
}

case suspendMsg:
if canSuspendProcess {
Expand Down

0 comments on commit 6185a24

Please sign in to comment.