mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-24 19:39:16 +02:00
Add support for suspending LazyGit with Ctrl+Z on Unix systems (#4757)
## ✨ Add Ctrl+Z suspend support for LazyGit on Unix-like systems ### 📝 Summary This PR adds support for suspending LazyGit when the user presses `Ctrl+Z`, making it behave like common CLI tools (e.g., Vim, less, htop): * Pressing `Ctrl+Z` sends a `SIGTSTP` signal to suspend LazyGit. * After resuming with `fg`, LazyGit redraws and continues working without hanging. * During suspension, background routines are paused to avoid running while LazyGit is stopped. ### ✅ Motivation Make LazyGit feel more native on Unix-like systems by supporting standard terminal suspend/resume (Ctrl+Z / fg) behavior. Closes #3906
This commit is contained in:
@@ -517,6 +517,7 @@ keybinding:
|
||||
universal:
|
||||
quit: q
|
||||
quit-alt1: <c-c>
|
||||
suspendApp: <c-z>
|
||||
return: <esc>
|
||||
quitWithoutChangingDirectory: Q
|
||||
togglePanel: <tab>
|
||||
@@ -583,7 +584,7 @@ keybinding:
|
||||
nextScreenMode: +
|
||||
prevScreenMode: _
|
||||
undo: z
|
||||
redo: <c-z>
|
||||
redo: Z
|
||||
filteringMenu: <c-s>
|
||||
diffingMenu: W
|
||||
diffingMenu-alt: <c-e>
|
||||
|
@@ -30,9 +30,10 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
|
||||
| `` W `` | View diffing options | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
|
||||
| `` <c-e> `` | View diffing options | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
|
||||
| `` q `` | Quit | |
|
||||
| `` <c-z> `` | Suspend the application | |
|
||||
| `` <c-w> `` | Toggle whitespace | Toggle whether or not whitespace changes are shown in the diff view.<br><br>The default can be changed in the config file with the key 'git.ignoreWhitespaceInDiffView'. |
|
||||
| `` z `` | Undo | The reflog will be used to determine what git command to run to undo the last git command. This does not include changes to the working tree; only commits are taken into consideration. |
|
||||
| `` <c-z> `` | Redo | The reflog will be used to determine what git command to run to redo the last git command. This does not include changes to the working tree; only commits are taken into consideration. |
|
||||
| `` Z `` | Redo | The reflog will be used to determine what git command to run to redo the last git command. This does not include changes to the working tree; only commits are taken into consideration. |
|
||||
|
||||
## List panel navigation
|
||||
|
||||
|
@@ -30,9 +30,10 @@ _凡例:`<c-b>` はctrl+b、`<a-b>` はalt+b、`B` はshift+bを意味
|
||||
| `` W `` | 差分オプションを表示 | 2つのrefの差分に関連するオプションを表示します(例:選択したrefとの差分表示、差分を取るrefの入力、差分方向の反転など)。 |
|
||||
| `` <c-e> `` | 差分オプションを表示 | 2つのrefの差分に関連するオプションを表示します(例:選択したrefとの差分表示、差分を取るrefの入力、差分方向の反転など)。 |
|
||||
| `` q `` | 終了 | |
|
||||
| `` <c-z> `` | Suspend the application | |
|
||||
| `` <c-w> `` | 空白表示の切り替え | Toggle whether or not whitespace changes are shown in the diff view.<br><br>The default can be changed in the config file with the key 'git.ignoreWhitespaceInDiffView'. |
|
||||
| `` z `` | 元に戻す | 最後のgitコマンドを元に戻すために実行するgitコマンドを決定するためにreflogが使用されます。これにはワーキングツリーへの変更は含まれません。コミットのみが考慮されます。 |
|
||||
| `` <c-z> `` | やり直す | 最後のgitコマンドをやり直すために実行するgitコマンドを決定するためにreflogが使用されます。これにはワーキングツリーへの変更は含まれません。コミットのみが考慮されます。 |
|
||||
| `` Z `` | やり直す | 最後のgitコマンドをやり直すために実行するgitコマンドを決定するためにreflogが使用されます。これにはワーキングツリーへの変更は含まれません。コミットのみが考慮されます。 |
|
||||
|
||||
## リストパネルのナビゲーション
|
||||
|
||||
|
@@ -30,9 +30,10 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
|
||||
| `` W `` | Diff 메뉴 열기 | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
|
||||
| `` <c-e> `` | Diff 메뉴 열기 | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
|
||||
| `` q `` | 종료 | |
|
||||
| `` <c-z> `` | Suspend the application | |
|
||||
| `` <c-w> `` | 공백문자를 Diff 뷰에서 표시 여부 전환 | Toggle whether or not whitespace changes are shown in the diff view.<br><br>The default can be changed in the config file with the key 'git.ignoreWhitespaceInDiffView'. |
|
||||
| `` z `` | 되돌리기 (reflog) (실험적) | The reflog will be used to determine what git command to run to undo the last git command. This does not include changes to the working tree; only commits are taken into consideration. |
|
||||
| `` <c-z> `` | 다시 실행 (reflog) (실험적) | The reflog will be used to determine what git command to run to redo the last git command. This does not include changes to the working tree; only commits are taken into consideration. |
|
||||
| `` Z `` | 다시 실행 (reflog) (실험적) | The reflog will be used to determine what git command to run to redo the last git command. This does not include changes to the working tree; only commits are taken into consideration. |
|
||||
|
||||
## List panel navigation
|
||||
|
||||
|
@@ -30,9 +30,10 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
|
||||
| `` W `` | Open diff menu | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
|
||||
| `` <c-e> `` | Open diff menu | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
|
||||
| `` q `` | Quit | |
|
||||
| `` <c-z> `` | Suspend the application | |
|
||||
| `` <c-w> `` | Toggle whitespace | Toggle whether or not whitespace changes are shown in the diff view.<br><br>The default can be changed in the config file with the key 'git.ignoreWhitespaceInDiffView'. |
|
||||
| `` z `` | Ongedaan maken (via reflog) (experimenteel) | The reflog will be used to determine what git command to run to undo the last git command. This does not include changes to the working tree; only commits are taken into consideration. |
|
||||
| `` <c-z> `` | Redo (via reflog) (experimenteel) | The reflog will be used to determine what git command to run to redo the last git command. This does not include changes to the working tree; only commits are taken into consideration. |
|
||||
| `` Z `` | Redo (via reflog) (experimenteel) | The reflog will be used to determine what git command to run to redo the last git command. This does not include changes to the working tree; only commits are taken into consideration. |
|
||||
|
||||
## Lijstpaneel navigatie
|
||||
|
||||
|
@@ -30,9 +30,10 @@ _Legenda: `<c-b>` oznacza ctrl+b, `<a-b>` oznacza alt+b, `B` oznacza shift+b_
|
||||
| `` W `` | Pokaż opcje różnicowania | Pokaż opcje dotyczące różnicowania dwóch refów, np. różnicowanie względem wybranego refa, wprowadzanie refa do różnicowania i odwracanie kierunku różnic. |
|
||||
| `` <c-e> `` | Pokaż opcje różnicowania | Pokaż opcje dotyczące różnicowania dwóch refów, np. różnicowanie względem wybranego refa, wprowadzanie refa do różnicowania i odwracanie kierunku różnic. |
|
||||
| `` q `` | Wyjdź | |
|
||||
| `` <c-z> `` | Suspend the application | |
|
||||
| `` <c-w> `` | Przełącz białe znaki | Toggle whether or not whitespace changes are shown in the diff view.<br><br>The default can be changed in the config file with the key 'git.ignoreWhitespaceInDiffView'. |
|
||||
| `` z `` | Cofnij | Dziennik reflog zostanie użyty do określenia, jakie polecenie git należy uruchomić, aby cofnąć ostatnie polecenie git. Nie obejmuje to zmian w drzewie roboczym; brane są pod uwagę tylko commity. |
|
||||
| `` <c-z> `` | Ponów | Dziennik reflog zostanie użyty do określenia, jakie polecenie git należy uruchomić, aby ponowić ostatnie polecenie git. Nie obejmuje to zmian w drzewie roboczym; brane są pod uwagę tylko commity. |
|
||||
| `` Z `` | Ponów | Dziennik reflog zostanie użyty do określenia, jakie polecenie git należy uruchomić, aby ponowić ostatnie polecenie git. Nie obejmuje to zmian w drzewie roboczym; brane są pod uwagę tylko commity. |
|
||||
|
||||
## Nawigacja panelu listy
|
||||
|
||||
|
@@ -30,9 +30,10 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
|
||||
| `` W `` | View diffing options | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
|
||||
| `` <c-e> `` | View diffing options | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
|
||||
| `` q `` | Sair | |
|
||||
| `` <c-z> `` | Suspend the application | |
|
||||
| `` <c-w> `` | Toggle whitespace | Toggle whether or not whitespace changes are shown in the diff view.<br><br>The default can be changed in the config file with the key 'git.ignoreWhitespaceInDiffView'. |
|
||||
| `` z `` | Desfazer | O reflog será usado para determinar qual comando git para executar para desfazer o último comando git. Isto não inclui mudanças na árvore de trabalho; apenas compromissos são tidos em consideração. |
|
||||
| `` <c-z> `` | Refazer | O reflog será usado para determinar qual comando git para executar para refazer o último comando git. Isto não inclui mudanças na árvore de trabalho; apenas compromissos são tidos em consideração. |
|
||||
| `` Z `` | Refazer | O reflog será usado para determinar qual comando git para executar para refazer o último comando git. Isto não inclui mudanças na árvore de trabalho; apenas compromissos são tidos em consideração. |
|
||||
|
||||
## List panel navigation
|
||||
|
||||
|
@@ -30,9 +30,10 @@ _Связки клавиш_
|
||||
| `` W `` | Открыть меню сравнении | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
|
||||
| `` <c-e> `` | Открыть меню сравнении | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
|
||||
| `` q `` | Выйти | |
|
||||
| `` <c-z> `` | Suspend the application | |
|
||||
| `` <c-w> `` | Переключить отображение изменении пробелов в просмотрщике сравнении | Toggle whether or not whitespace changes are shown in the diff view.<br><br>The default can be changed in the config file with the key 'git.ignoreWhitespaceInDiffView'. |
|
||||
| `` z `` | Отменить (через reflog) (экспериментальный) | Журнал ссылок (reflog) будет использоваться для определения того, какую команду git запустить, чтобы отменить последнюю команду git. Сюда не входят изменения в рабочем дереве; учитываются только коммиты. |
|
||||
| `` <c-z> `` | Повторить (через reflog) (экспериментальный) | Журнал ссылок (reflog) будет использоваться для определения того, какую команду git нужно запустить, чтобы повторить последнюю команду git. Сюда не входят изменения в рабочем дереве; учитываются только коммиты. |
|
||||
| `` Z `` | Повторить (через reflog) (экспериментальный) | Журнал ссылок (reflog) будет использоваться для определения того, какую команду git нужно запустить, чтобы повторить последнюю команду git. Сюда не входят изменения в рабочем дереве; учитываются только коммиты. |
|
||||
|
||||
## Навигация по панели списка
|
||||
|
||||
|
@@ -30,9 +30,10 @@ _图例:`<c-b>` 意味着ctrl+b, `<a-b>意味着Alt+b, `B` 意味着shift+b_
|
||||
| `` W `` | 打开 diff 菜单 | 查看与比较两个引用相关的选项,例如与选定的 ref 进行比较,输入要比较的 ref,然后反转比较方向。 |
|
||||
| `` <c-e> `` | 打开 diff 菜单 | 查看与比较两个引用相关的选项,例如与选定的 ref 进行比较,输入要比较的 ref,然后反转比较方向。 |
|
||||
| `` q `` | 退出 | |
|
||||
| `` <c-z> `` | Suspend the application | |
|
||||
| `` <c-w> `` | 切换是否在差异视图中显示空白字符差异 | Toggle whether or not whitespace changes are shown in the diff view.<br><br>The default can be changed in the config file with the key 'git.ignoreWhitespaceInDiffView'. |
|
||||
| `` z `` | 撤销 | Reflog将用于确定运行哪个git命令来撤消最后一个git命令。这并不包括对工作树的更改,只考虑提交。 |
|
||||
| `` <c-z> `` | 重做 | Reflog将用于确定运行哪个git命令来重做上一个git命令。这并不包括对工作树的更改,只考虑提交。 |
|
||||
| `` Z `` | 重做 | Reflog将用于确定运行哪个git命令来重做上一个git命令。这并不包括对工作树的更改,只考虑提交。 |
|
||||
|
||||
## 列表面板导航
|
||||
|
||||
|
@@ -30,9 +30,10 @@ _說明:`<c-b>` 表示 Ctrl+B、`<a-b>` 表示 Alt+B,`B`表示 Shift+B
|
||||
| `` W `` | 開啟差異比較選單 | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
|
||||
| `` <c-e> `` | 開啟差異比較選單 | View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction. |
|
||||
| `` q `` | 結束 | |
|
||||
| `` <c-z> `` | Suspend the application | |
|
||||
| `` <c-w> `` | 切換是否在差異檢視中顯示空格變更 | Toggle whether or not whitespace changes are shown in the diff view.<br><br>The default can be changed in the config file with the key 'git.ignoreWhitespaceInDiffView'. |
|
||||
| `` z `` | 復原 | 將使用 reflog 確任 git 指令以復原。這不包括工作區更改;只考慮提交。 |
|
||||
| `` <c-z> `` | 取消復原 | 將使用 reflog 確任 git 指令以重作。這不包括工作區更改;只考慮提交。 |
|
||||
| `` Z `` | 取消復原 | 將使用 reflog 確任 git 指令以重作。這不包括工作區更改;只考慮提交。 |
|
||||
|
||||
## 移動
|
||||
|
||||
|
2
go.mod
2
go.mod
@@ -37,6 +37,7 @@ require (
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778
|
||||
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
|
||||
golang.org/x/sync v0.16.0
|
||||
golang.org/x/sys v0.34.0
|
||||
gopkg.in/ozeidan/fuzzy-patricia.v3 v3.0.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
@@ -77,7 +78,6 @@ require (
|
||||
github.com/xanzy/ssh-agent v0.3.3 // indirect
|
||||
golang.org/x/crypto v0.37.0 // indirect
|
||||
golang.org/x/net v0.39.0 // indirect
|
||||
golang.org/x/sys v0.34.0 // indirect
|
||||
golang.org/x/term v0.33.0 // indirect
|
||||
golang.org/x/text v0.27.0 // indirect
|
||||
gopkg.in/fsnotify.v1 v1.4.7 // indirect
|
||||
|
@@ -1,5 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package oscommands
|
||||
|
||||
|
@@ -1,6 +1,3 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package oscommands
|
||||
|
||||
import (
|
@@ -1,5 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package oscommands
|
||||
|
||||
|
@@ -1,5 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package oscommands
|
||||
|
||||
|
@@ -1,6 +1,3 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package oscommands
|
||||
|
||||
import (
|
||||
|
@@ -865,7 +865,7 @@ keybinding:
|
||||
nextScreenMode: +
|
||||
prevScreenMode: _
|
||||
undo: z
|
||||
redo: <c-z>
|
||||
redo: Z
|
||||
filteringMenu: <c-s>
|
||||
diffingMenu: W
|
||||
diffingMenu-alt: <c-e>
|
||||
|
@@ -1,5 +1,4 @@
|
||||
//go:build !windows && !linux
|
||||
// +build !windows,!linux
|
||||
|
||||
package config
|
||||
|
||||
|
@@ -390,6 +390,7 @@ type KeybindingConfig struct {
|
||||
type KeybindingUniversalConfig struct {
|
||||
Quit string `yaml:"quit"`
|
||||
QuitAlt1 string `yaml:"quit-alt1"`
|
||||
SuspendApp string `yaml:"suspendApp"`
|
||||
Return string `yaml:"return"`
|
||||
QuitWithoutChangingDirectory string `yaml:"quitWithoutChangingDirectory"`
|
||||
TogglePanel string `yaml:"togglePanel"`
|
||||
@@ -854,6 +855,7 @@ func GetDefaultConfig() *UserConfig {
|
||||
Universal: KeybindingUniversalConfig{
|
||||
Quit: "q",
|
||||
QuitAlt1: "<c-c>",
|
||||
SuspendApp: "<c-z>",
|
||||
Return: "<esc>",
|
||||
QuitWithoutChangingDirectory: "Q",
|
||||
TogglePanel: "<tab>",
|
||||
@@ -912,7 +914,7 @@ func GetDefaultConfig() *UserConfig {
|
||||
NextScreenMode: "+",
|
||||
PrevScreenMode: "_",
|
||||
Undo: "z",
|
||||
Redo: "<c-z>",
|
||||
Redo: "Z",
|
||||
FilteringMenu: "<c-s>",
|
||||
DiffingMenu: "W",
|
||||
DiffingMenuAlt: "<c-e>",
|
||||
|
@@ -109,6 +109,7 @@ func (gui *Gui) resetHelpersAndControllers() {
|
||||
AmendHelper: helpers.NewAmendHelper(helperCommon, gpgHelper),
|
||||
FixupHelper: helpers.NewFixupHelper(helperCommon),
|
||||
Commits: commitsHelper,
|
||||
SuspendResume: helpers.NewSuspendResumeHelper(helperCommon),
|
||||
Snake: helpers.NewSnakeHelper(helperCommon),
|
||||
Diff: diffHelper,
|
||||
Repos: reposHelper,
|
||||
|
@@ -123,6 +123,20 @@ func (self *GlobalController) GetKeybindings(opts types.KeybindingsOpts) []*type
|
||||
Modifier: gocui.ModNone,
|
||||
Handler: self.quitWithoutChangingDirectory,
|
||||
},
|
||||
{
|
||||
Key: opts.GetKey(opts.Config.Universal.SuspendApp),
|
||||
Modifier: gocui.ModNone,
|
||||
Handler: self.c.Helpers().SuspendResume.SuspendApp,
|
||||
Description: self.c.Tr.SuspendApp,
|
||||
GetDisabledReason: func() *types.DisabledReason {
|
||||
if !self.c.Helpers().SuspendResume.CanSuspendApp() {
|
||||
return &types.DisabledReason{
|
||||
Text: self.c.Tr.CannotSuspendApp,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Key: opts.GetKey(opts.Config.Universal.ToggleWhitespaceInDiffView),
|
||||
Handler: self.toggleWhitespace,
|
||||
|
@@ -35,6 +35,7 @@ type Helpers struct {
|
||||
AmendHelper *AmendHelper
|
||||
FixupHelper *FixupHelper
|
||||
Commits *CommitsHelper
|
||||
SuspendResume *SuspendResumeHelper
|
||||
Snake *SnakeHelper
|
||||
// lives in context package because our contexts need it to render to main
|
||||
Diff *DiffHelper
|
||||
|
59
pkg/gui/controllers/helpers/signal_handling.go
Normal file
59
pkg/gui/controllers/helpers/signal_handling.go
Normal file
@@ -0,0 +1,59 @@
|
||||
//go:build !windows
|
||||
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func canSuspendApp() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func sendStopSignal() error {
|
||||
return syscall.Kill(0, syscall.SIGSTOP)
|
||||
}
|
||||
|
||||
// setForegroundPgrp sets the current process group as the foreground process group
|
||||
// for the terminal, allowing the program to read input after resuming from suspension.
|
||||
func setForegroundPgrp() error {
|
||||
fd, err := unix.Open("/dev/tty", unix.O_RDWR, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer unix.Close(fd)
|
||||
|
||||
pgid := syscall.Getpgrp()
|
||||
|
||||
return unix.IoctlSetPointerInt(fd, unix.TIOCSPGRP, pgid)
|
||||
}
|
||||
|
||||
func handleResumeSignal(log *logrus.Entry, onResume func() error) {
|
||||
if err := setForegroundPgrp(); err != nil {
|
||||
log.Warning(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := onResume(); err != nil {
|
||||
log.Warning(err)
|
||||
}
|
||||
}
|
||||
|
||||
func installResumeSignalHandler(log *logrus.Entry, onResume func() error) {
|
||||
go func() {
|
||||
sigs := make(chan os.Signal, 1)
|
||||
signal.Notify(sigs, syscall.SIGCONT)
|
||||
|
||||
for sig := range sigs {
|
||||
switch sig {
|
||||
case syscall.SIGCONT:
|
||||
handleResumeSignal(log, onResume)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
16
pkg/gui/controllers/helpers/signal_handling_windows.go
Normal file
16
pkg/gui/controllers/helpers/signal_handling_windows.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func canSuspendApp() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func sendStopSignal() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func installResumeSignalHandler(log *logrus.Entry, onResume func() error) {
|
||||
}
|
31
pkg/gui/controllers/helpers/suspend_resume_helper.go
Normal file
31
pkg/gui/controllers/helpers/suspend_resume_helper.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package helpers
|
||||
|
||||
type SuspendResumeHelper struct {
|
||||
c *HelperCommon
|
||||
}
|
||||
|
||||
func NewSuspendResumeHelper(c *HelperCommon) *SuspendResumeHelper {
|
||||
return &SuspendResumeHelper{
|
||||
c: c,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SuspendResumeHelper) CanSuspendApp() bool {
|
||||
return canSuspendApp()
|
||||
}
|
||||
|
||||
func (s *SuspendResumeHelper) SuspendApp() error {
|
||||
if !canSuspendApp() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := s.c.Suspend(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return sendStopSignal()
|
||||
}
|
||||
|
||||
func (s *SuspendResumeHelper) InstallResumeSignalHandler() {
|
||||
installResumeSignalHandler(s.c.Log, s.c.Resume)
|
||||
}
|
@@ -848,6 +848,8 @@ func (gui *Gui) Run(startArgs appTypes.StartArgs) error {
|
||||
|
||||
gui.BackgroundRoutineMgr.startBackgroundRoutines()
|
||||
|
||||
gui.Helpers().SuspendResume.InstallResumeSignalHandler()
|
||||
|
||||
gui.c.Log.Info("starting main loop")
|
||||
|
||||
// setting here so we can use it in layout.go
|
||||
@@ -899,21 +901,36 @@ func (gui *Gui) runSubprocessWithSuspenseAndRefresh(subprocess *oscommands.CmdOb
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gui *Gui) suspend() error {
|
||||
if err := gui.g.Suspend(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
gui.BackgroundRoutineMgr.PauseBackgroundRefreshes(true)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gui *Gui) resume() error {
|
||||
if err := gui.g.Resume(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
gui.BackgroundRoutineMgr.PauseBackgroundRefreshes(false)
|
||||
return nil
|
||||
}
|
||||
|
||||
// returns whether command exited without error or not
|
||||
func (gui *Gui) runSubprocessWithSuspense(subprocess *oscommands.CmdObj) (bool, error) {
|
||||
gui.Mutexes.SubprocessMutex.Lock()
|
||||
defer gui.Mutexes.SubprocessMutex.Unlock()
|
||||
|
||||
if err := gui.g.Suspend(); err != nil {
|
||||
if err := gui.suspend(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
gui.BackgroundRoutineMgr.PauseBackgroundRefreshes(true)
|
||||
defer gui.BackgroundRoutineMgr.PauseBackgroundRefreshes(false)
|
||||
|
||||
cmdErr := gui.runSubprocess(subprocess)
|
||||
|
||||
if err := gui.g.Resume(); err != nil {
|
||||
if err := gui.resume(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
|
@@ -42,6 +42,14 @@ func (self *guiCommon) RunSubprocess(cmdObj *oscommands.CmdObj) (bool, error) {
|
||||
return self.gui.runSubprocessWithSuspense(cmdObj)
|
||||
}
|
||||
|
||||
func (self *guiCommon) Suspend() error {
|
||||
return self.gui.suspend()
|
||||
}
|
||||
|
||||
func (self *guiCommon) Resume() error {
|
||||
return self.gui.resume()
|
||||
}
|
||||
|
||||
func (self *guiCommon) Context() types.IContextMgr {
|
||||
return self.gui.State.ContextMgr
|
||||
}
|
||||
|
@@ -75,7 +75,6 @@ func (gui *Gui) keybindingOpts() types.KeybindingsOpts {
|
||||
}
|
||||
}
|
||||
|
||||
// renaming receiver to 'self' to aid refactoring. Will probably end up moving all Gui handlers to this pattern eventually.
|
||||
func (gui *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBinding) {
|
||||
opts := gui.c.KeybindingsOpts()
|
||||
|
||||
|
@@ -1,5 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package gui
|
||||
|
||||
|
@@ -1,6 +1,3 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package gui
|
||||
|
||||
import (
|
||||
|
@@ -56,6 +56,9 @@ type IGuiCommon interface {
|
||||
RunSubprocess(cmdObj *oscommands.CmdObj) (bool, error)
|
||||
RunSubprocessAndRefresh(*oscommands.CmdObj) error
|
||||
|
||||
Suspend() error
|
||||
Resume() error
|
||||
|
||||
Context() IContextMgr
|
||||
ContextForKey(key ContextKey) Context
|
||||
|
||||
|
@@ -382,6 +382,8 @@ type TranslationSet struct {
|
||||
ScrollUp string
|
||||
ScrollUpMainWindow string
|
||||
ScrollDownMainWindow string
|
||||
SuspendApp string
|
||||
CannotSuspendApp string
|
||||
AmendCommitTitle string
|
||||
AmendCommitPrompt string
|
||||
AmendCommitWithConflictsMenuPrompt string
|
||||
@@ -1456,6 +1458,8 @@ func EnglishTranslationSet() *TranslationSet {
|
||||
ScrollUp: "Scroll up",
|
||||
ScrollUpMainWindow: "Scroll up main window",
|
||||
ScrollDownMainWindow: "Scroll down main window",
|
||||
SuspendApp: "Suspend the application",
|
||||
CannotSuspendApp: "Suspending the application is not supported on Windows",
|
||||
AmendCommitTitle: "Amend commit",
|
||||
AmendCommitPrompt: "Are you sure you want to amend this commit with your staged files?",
|
||||
AmendCommitWithConflictsMenuPrompt: "WARNING: you are about to amend the last finished commit with your resolved conflicts. This is very unlikely to be what you want at this point. More likely, you simply want to continue the rebase instead.\n\nDo you still want to amend the previous commit?",
|
||||
@@ -2154,6 +2158,13 @@ git:
|
||||
|
||||
gui:
|
||||
useHunkModeInStagingView: false
|
||||
`,
|
||||
"0.55.0": `- The 'redo' command, which used to be bound to ctrl-z, is now bound to shift-Z instead. This is because ctrl-z is now used for suspending the application; it is a commonly known keybinding for that in the Linux world. If you want to revert this change, you can do so by adding the following to your config:
|
||||
|
||||
keybinding:
|
||||
universal:
|
||||
suspendApp: <disabled>
|
||||
redo: <c-z>
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package clients
|
||||
|
||||
|
@@ -1,5 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package tail
|
||||
|
||||
|
@@ -1,6 +1,3 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package tail
|
||||
|
||||
import (
|
||||
|
@@ -1217,6 +1217,10 @@
|
||||
"type": "string",
|
||||
"default": "\u003cc-c\u003e"
|
||||
},
|
||||
"suspendApp": {
|
||||
"type": "string",
|
||||
"default": "\u003cc-z\u003e"
|
||||
},
|
||||
"return": {
|
||||
"type": "string",
|
||||
"default": "\u003cesc\u003e"
|
||||
@@ -1458,7 +1462,7 @@
|
||||
},
|
||||
"redo": {
|
||||
"type": "string",
|
||||
"default": "\u003cc-z\u003e"
|
||||
"default": "Z"
|
||||
},
|
||||
"filteringMenu": {
|
||||
"type": "string",
|
||||
|
Reference in New Issue
Block a user