Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 692a24f

Browse files
committed
Add basic TTY support
- Lacks at least window resize functionality
1 parent 65aa696 commit 692a24f

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Diff for: cmd/coder/shell.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"context"
55
"io"
66
"os"
7+
"os/exec"
78

9+
"github.com/mattn/go-isatty"
810
"github.com/spf13/pflag"
911
"go.coder.com/cli"
1012
"go.coder.com/flog"
@@ -25,6 +27,18 @@ func (cmd *shellCmd) Spec() cli.CommandSpec {
2527
}
2628
}
2729

30+
func enableTerminal() {
31+
out, err := exec.Command("stty", "-f", "/dev/tty",
32+
// Send
33+
"cbreak",
34+
"-echo",
35+
"intr", "undef",
36+
).CombinedOutput()
37+
if err != nil {
38+
flog.Fatal("configure tty: %v %q", err, out)
39+
}
40+
}
41+
2842
func (cmd *shellCmd) Run(fl *pflag.FlagSet) {
2943
if len(fl.Args()) < 2 {
3044
exitUsage(fl)
@@ -40,10 +54,15 @@ func (cmd *shellCmd) Run(fl *pflag.FlagSet) {
4054
env = findEnv(entClient, envName)
4155
)
4256

57+
tty := isatty.IsTerminal(os.Stdout.Fd())
58+
if tty {
59+
enableTerminal()
60+
}
61+
4362
conn, err := entClient.DialWush(
4463
env,
4564
&client.WushOptions{
46-
TTY: false,
65+
TTY: tty,
4766
Stdin: true,
4867
}, command, args...)
4968
if err != nil {

0 commit comments

Comments
 (0)