Debian Codegraph @

xpty/conpty.go

raw
1 package xpty
2
3 import (
4 "os/exec"
5
6 "github.com/charmbracelet/x/conpty"
7 )
8
9 // ConPty is a Windows console pty.
10 type ConPty struct {
11 *conpty.ConPty
12 }
13
14 var _ Pty = &ConPty{}
15
16 // NewConPty creates a new ConPty.
17 func NewConPty(width, height int, opts ...PtyOption) (*ConPty, error) {
18 var opt Options
19 for _, o := range opts {
20 o(opt)
21 }
22
23 c, err := conpty.New(width, height, opt.Flags)
24 if err != nil {
25 return nil, err //nolint:wrapcheck
26 }
27
28 return &ConPty{c}, nil
29 }
30
31 // Name returns the name of the ConPty.
32 func (c *ConPty) Name() string {
33 return "windows-pty"
34 }
35
36 // Start starts a command on the ConPty.
37 // This is a wrapper around conpty.Spawn.
38 func (c *ConPty) Start(cmd *exec.Cmd) error {
39 return c.start(cmd)
40 }