Merge pull request #179 from bnema/fix/issue-178-terminal-title-prefix
fix(daemon): avoid duplicate terminal title prefixes
2 files · +7 -2
M internal/usecase/daemon/pane_titles.go +5 -1
| @@ -24,7 +24,11 @@ type paneTitleState struct { | |||
| 24 | 24 | ||
| 25 | 25 | func formatPaneTitle(processName, terminalTitle, fallback string) string { | |
| 26 | 26 | if processName != "" && terminalTitle != "" { | |
| 27 | - | return processName + ": " + terminalTitle | |
| 27 | + | prefix := processName + ": " | |
| 28 | + | if strings.HasPrefix(terminalTitle, prefix) { | |
| 29 | + | return terminalTitle | |
| 30 | + | } | |
| 31 | + | return prefix + terminalTitle | |
| 28 | 32 | } | |
| 29 | 33 | if processName != "" { | |
| 30 | 34 | return processName | |
| @@ -24,7 +24,11 @@ type paneTitleState struct { | |||||
| 24 | 24 | ||||
| 25 | func formatPaneTitle(processName, terminalTitle, fallback string) string { | 25 | func formatPaneTitle(processName, terminalTitle, fallback string) string { | ||
| 26 | if processName != "" && terminalTitle != "" { | 26 | if processName != "" && terminalTitle != "" { | ||
| 27 | - | return processName + ": " + terminalTitle | 27 | + | prefix := processName + ": " |
| 28 | + | if strings.HasPrefix(terminalTitle, prefix) { | |||
| 29 | + | return terminalTitle | |||
| 30 | + | } | |||
| 31 | + | return prefix + terminalTitle | |||
| 28 | } | 32 | } | ||
| 29 | if processName != "" { | 33 | if processName != "" { | ||
| 30 | return processName | 34 | return processName | ||
M internal/usecase/daemon/pane_titles_test.go +2 -1
| @@ -16,7 +16,8 @@ func TestFormatPaneTitle(t *testing.T) { | |||
| 16 | 16 | tests := []struct { | |
| 17 | 17 | name, process, terminal, fallback, want string | |
| 18 | 18 | }{ | |
| 19 | - | {name: "process and terminal", process: "nvim", terminal: "project/main.go", fallback: "sh", want: "nvim: project/main.go"}, | |
| 19 | + | {name: "process prepends non-prefixed terminal title", process: "nvim", terminal: "project/main.go", fallback: "sh", want: "nvim: project/main.go"}, | |
| 20 | + | {name: "process does not duplicate its terminal-title prefix", process: "zot", terminal: "zot: session title", fallback: "sh", want: "zot: session title"}, | |
| 20 | 21 | {name: "process only", process: "nvim", fallback: "sh", want: "nvim"}, | |
| 21 | 22 | {name: "terminal only", terminal: "project/main.go", fallback: "sh", want: "project/main.go"}, | |
| 22 | 23 | {name: "fallback", fallback: "fish", want: "fish"}, | |
| @@ -16,7 +16,8 @@ func TestFormatPaneTitle(t *testing.T) { | |||||
| 16 | tests := []struct { | 16 | tests := []struct { | ||
| 17 | name, process, terminal, fallback, want string | 17 | name, process, terminal, fallback, want string | ||
| 18 | }{ | 18 | }{ | ||
| 19 | - | {name: "process and terminal", process: "nvim", terminal: "project/main.go", fallback: "sh", want: "nvim: project/main.go"}, | 19 | + | {name: "process prepends non-prefixed terminal title", process: "nvim", terminal: "project/main.go", fallback: "sh", want: "nvim: project/main.go"}, |
| 20 | + | {name: "process does not duplicate its terminal-title prefix", process: "zot", terminal: "zot: session title", fallback: "sh", want: "zot: session title"}, | |||
| 20 | {name: "process only", process: "nvim", fallback: "sh", want: "nvim"}, | 21 | {name: "process only", process: "nvim", fallback: "sh", want: "nvim"}, | ||
| 21 | {name: "terminal only", terminal: "project/main.go", fallback: "sh", want: "project/main.go"}, | 22 | {name: "terminal only", terminal: "project/main.go", fallback: "sh", want: "project/main.go"}, | ||
| 22 | {name: "fallback", fallback: "fish", want: "fish"}, | 23 | {name: "fallback", fallback: "fish", want: "fish"}, | ||