Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/types/gotypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,7 @@ declare global {
"term:bellindicator"?: boolean;
"term:osc52"?: string;
"term:durable"?: boolean;
"term:closeonlasttermclose"?: boolean;
"editor:minimapenabled"?: boolean;
"editor:stickyscrollenabled"?: boolean;
"editor:wordwrap"?: boolean;
Expand Down
52 changes: 50 additions & 2 deletions pkg/blockcontroller/shellcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,45 @@ func (union *ConnUnion) getRemoteInfoAndShellType(blockMeta waveobj.MetaMapType)
return nil
}

func isLastShellBlockInWorkspace(ctx context.Context, blockId string) bool {
tabId, err := wstore.DBFindTabForBlockId(ctx, blockId)
if err != nil || tabId == "" {
return false
}
workspaceId, err := wstore.DBFindWorkspaceForTabId(ctx, tabId)
if err != nil || workspaceId == "" {
return false
}
workspace, err := wstore.DBGet[*waveobj.Workspace](ctx, workspaceId)
if err != nil || workspace == nil {
return false
}
shellBlockCount := 0
for _, wsTabId := range workspace.TabIds {
tab, err := wstore.DBGet[*waveobj.Tab](ctx, wsTabId)
if err != nil {
return false
}
if tab == nil {
continue
}
for _, wsBlockId := range tab.BlockIds {
block, err := wstore.DBGet[*waveobj.Block](ctx, wsBlockId)
if err != nil {
return false
}
if block == nil {
continue
}
controller := block.Meta.GetString(waveobj.MetaKey_Controller, "")
if controller == BlockController_Shell || controller == BlockController_Cmd {
shellBlockCount++
}
}
}
return shellBlockCount == 1
}

func checkCloseOnExit(blockId string, exitCode int) {
ctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout)
defer cancelFn()
Expand All @@ -657,10 +696,19 @@ func checkCloseOnExit(blockId string, exitCode int) {
}
closeOnExit := blockData.Meta.GetBool(waveobj.MetaKey_CmdCloseOnExit, false)
closeOnExitForce := blockData.Meta.GetBool(waveobj.MetaKey_CmdCloseOnExitForce, false)
defaultDelayMs := 2000.0
if !closeOnExitForce && !(closeOnExit && exitCode == 0) {
return
// Check global setting: close when last terminal exits
settings := wconfig.GetWatcher().GetFullConfig().Settings
if !settings.TermCloseOnLastTermClose {
return
}
if !isLastShellBlockInWorkspace(ctx, blockId) {
return
}
defaultDelayMs = 0
}
delayMs := blockData.Meta.GetFloat(waveobj.MetaKey_CmdCloseOnExitDelay, 2000)
delayMs := blockData.Meta.GetFloat(waveobj.MetaKey_CmdCloseOnExitDelay, defaultDelayMs)
if delayMs < 0 {
delayMs = 0
}
Expand Down
1 change: 1 addition & 0 deletions pkg/wconfig/metaconsts.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const (
ConfigKey_TermBellIndicator = "term:bellindicator"
ConfigKey_TermOsc52 = "term:osc52"
ConfigKey_TermDurable = "term:durable"
ConfigKey_TermCloseOnLastTermClose = "term:closeonlasttermclose"

ConfigKey_EditorMinimapEnabled = "editor:minimapenabled"
ConfigKey_EditorStickyScrollEnabled = "editor:stickyscrollenabled"
Expand Down
1 change: 1 addition & 0 deletions pkg/wconfig/settingsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ type SettingsType struct {
TermBellIndicator *bool `json:"term:bellindicator,omitempty"`
TermOsc52 string `json:"term:osc52,omitempty" jsonschema:"enum=focus,enum=always"`
TermDurable *bool `json:"term:durable,omitempty"`
TermCloseOnLastTermClose bool `json:"term:closeonlasttermclose,omitempty"`

EditorMinimapEnabled bool `json:"editor:minimapenabled,omitempty"`
EditorStickyScrollEnabled bool `json:"editor:stickyscrollenabled,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions schema/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@
"term:durable": {
"type": "boolean"
},
"term:closeonlasttermclose": {
"type": "boolean"
},
"editor:minimapenabled": {
"type": "boolean"
},
Expand Down