Skip to content

Commit 05914cb

Browse files
authored
fix: disable init() function in github/charmbracelet/bubbletea dependency (coder#15817)
- Fixes an issue where an init function causes writes to the terminal when using `agent-exec` which results in raw ansi characters being printed to the web terminal. - Was also causing significant latency in launching a web terminal
1 parent 202f7f7 commit 05914cb

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

cmd/coder/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"os"
66
_ "time/tzdata"
77

8+
tea "github.com/charmbracelet/bubbletea"
9+
810
"github.com/coder/coder/v2/agent/agentexec"
911
"github.com/coder/coder/v2/cli"
1012
)
@@ -15,6 +17,9 @@ func main() {
1517
_, _ = fmt.Fprintln(os.Stderr, err)
1618
os.Exit(1)
1719
}
20+
// This preserves backwards compatibility with an init function that is causing grief for
21+
// web terminals using agent-exec + screen. See https://github.com/coder/coder/pull/15817
22+
tea.InitTerminal()
1823
var rootCmd cli.RootCmd
1924
rootCmd.RunWithSubcommands(rootCmd.AGPL())
2025
}

enterprise/cmd/coder/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"os"
66
_ "time/tzdata"
77

8+
tea "github.com/charmbracelet/bubbletea"
9+
810
"github.com/coder/coder/v2/agent/agentexec"
911
entcli "github.com/coder/coder/v2/enterprise/cli"
1012
)
@@ -15,7 +17,9 @@ func main() {
1517
_, _ = fmt.Fprintln(os.Stderr, err)
1618
os.Exit(1)
1719
}
18-
20+
// This preserves backwards compatibility with an init function that is causing grief for
21+
// web terminals using agent-exec + screen. See https://github.com/coder/coder/pull/15817
22+
tea.InitTerminal()
1923
var rootCmd entcli.RootCmd
2024
rootCmd.RunWithSubcommands(rootCmd.EnterpriseSubcommands())
2125
}

go.mod

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ replace github.com/pkg/sftp => github.com/mafredri/sftp v1.13.6-0.20231212144145
6767
// which we use in the awsiamrds package.
6868
replace github.com/lib/pq => github.com/coder/pq v1.10.5-0.20240813183442-0c420cb5a048
6969

70+
// Removes an init() function that causes terminal sequences to be printed to the web terminal when
71+
// used in conjunction with agent-exec. See https://github.com/coder/coder/pull/15817
72+
replace github.com/charmbracelet/bubbletea => github.com/coder/bubbletea v1.2.2-0.20241212190825-007a1cdb2c41
73+
7074
require (
7175
cdr.dev/slog v1.6.2-0.20241112041820-0ec81e6e67bb
7276
cloud.google.com/go/compute/metadata v0.5.2
@@ -202,7 +206,7 @@ require go.uber.org/mock v0.5.0
202206
require (
203207
github.com/cespare/xxhash v1.1.0
204208
github.com/charmbracelet/bubbles v0.20.0
205-
github.com/charmbracelet/bubbletea v1.2.1
209+
github.com/charmbracelet/bubbletea v1.1.0
206210
github.com/charmbracelet/lipgloss v1.0.0
207211
github.com/coder/serpent v0.10.0
208212
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF
177177
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
178178
github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE=
179179
github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU=
180-
github.com/charmbracelet/bubbletea v1.2.1 h1:J041h57zculJKEKf/O2pS4edXGIz+V0YvojvfGXePIk=
181-
github.com/charmbracelet/bubbletea v1.2.1/go.mod h1:viLoDL7hG4njLJSKU2gw7kB3LSEmWsrM80rO1dBJWBI=
182180
github.com/charmbracelet/glamour v0.8.0 h1:tPrjL3aRcQbn++7t18wOpgLyl8wrOHUEDS7IZ68QtZs=
183181
github.com/charmbracelet/glamour v0.8.0/go.mod h1:ViRgmKkf3u5S7uakt2czJ272WSg2ZenlYEZXT2x7Bjw=
184182
github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg=
@@ -209,6 +207,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
209207
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
210208
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
211209
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
210+
github.com/coder/bubbletea v1.2.2-0.20241212190825-007a1cdb2c41 h1:SBN/DA63+ZHwuWwPHPYoCZ/KLAjHv5g4h2MS4f2/MTI=
211+
github.com/coder/bubbletea v1.2.2-0.20241212190825-007a1cdb2c41/go.mod h1:I9ULxr64UaOSUv7hcb3nX4kowodJCVS7vt7VVJk/kW4=
212212
github.com/coder/flog v1.1.0 h1:kbAes1ai8fIS5OeV+QAnKBQE22ty1jRF/mcAwHpLBa4=
213213
github.com/coder/flog v1.1.0/go.mod h1:UQlQvrkJBvnRGo69Le8E24Tcl5SJleAAR7gYEHzAmdQ=
214214
github.com/coder/glog v1.0.1-0.20220322161911-7365fe7f2cd1 h1:UqBrPWSYvRI2s5RtOul20JukUEpu4ip9u7biBL+ntgk=

0 commit comments

Comments
 (0)