Skip to content

Commit 6427e70

Browse files
committed
make the terminal width and height configurable
1 parent 9bb9028 commit 6427e70

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

cmd/server/server.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ var (
2323
port int
2424
printOpenAPI bool
2525
chatBasePath string
26+
termWidth uint16
27+
termHeight uint16
2628
)
2729

2830
type AgentType = msgfmt.AgentType
@@ -78,11 +80,24 @@ func runServer(ctx context.Context, logger *slog.Logger, argsToPass []string) er
7880
if err != nil {
7981
return xerrors.Errorf("failed to parse agent type: %w", err)
8082
}
83+
84+
if termWidth < 10 {
85+
return xerrors.Errorf("term width must be at least 10")
86+
}
87+
if termHeight < 10 {
88+
return xerrors.Errorf("term height must be at least 10")
89+
}
90+
8191
var process *termexec.Process
8292
if printOpenAPI {
8393
process = nil
8494
} else {
85-
process, err = httpapi.SetupProcess(ctx, agent, argsToPass[1:]...)
95+
process, err = httpapi.SetupProcess(ctx, httpapi.SetupProcessConfig{
96+
Program: agent,
97+
ProgramArgs: argsToPass[1:],
98+
TerminalWidth: termWidth,
99+
TerminalHeight: termHeight,
100+
})
86101
if err != nil {
87102
return xerrors.Errorf("failed to setup process: %w", err)
88103
}
@@ -139,4 +154,6 @@ func init() {
139154
ServerCmd.Flags().IntVarP(&port, "port", "p", 3284, "Port to run the server on")
140155
ServerCmd.Flags().BoolVarP(&printOpenAPI, "print-openapi", "P", false, "Print the OpenAPI schema to stdout and exit")
141156
ServerCmd.Flags().StringVarP(&chatBasePath, "chat-base-path", "c", "/chat", "Base path for assets and routes used in the static files of the chat interface")
157+
ServerCmd.Flags().Uint16VarP(&termWidth, "term-width", "W", 80, "Width of the emulated terminal")
158+
ServerCmd.Flags().Uint16VarP(&termHeight, "term-height", "H", 1000, "Height of the emulated terminal")
142159
}

lib/httpapi/setup.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,23 @@ import (
1313
"github.com/coder/agentapi/lib/termexec"
1414
)
1515

16-
func SetupProcess(ctx context.Context, program string, programArgs ...string) (*termexec.Process, error) {
16+
type SetupProcessConfig struct {
17+
Program string
18+
ProgramArgs []string
19+
TerminalWidth uint16
20+
TerminalHeight uint16
21+
}
22+
23+
func SetupProcess(ctx context.Context, config SetupProcessConfig) (*termexec.Process, error) {
1724
logger := logctx.From(ctx)
1825

19-
logger.Info(fmt.Sprintf("Running: %s %s", program, strings.Join(programArgs, " ")))
26+
logger.Info(fmt.Sprintf("Running: %s %s", config.Program, strings.Join(config.ProgramArgs, " ")))
2027

2128
process, err := termexec.StartProcess(ctx, termexec.StartProcessConfig{
22-
Program: program,
23-
Args: programArgs,
24-
TerminalWidth: 80,
25-
TerminalHeight: 1000,
29+
Program: config.Program,
30+
Args: config.ProgramArgs,
31+
TerminalWidth: config.TerminalWidth,
32+
TerminalHeight: config.TerminalHeight,
2633
})
2734
if err != nil {
2835
logger.Error(fmt.Sprintf("Error starting process: %v", err))

0 commit comments

Comments
 (0)