File: conpty.go

package info (click to toggle)
golang-github-charmbracelet-x 0.0~git20240809.9ab0ca0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,004 kB
  • sloc: sh: 55; makefile: 5
file content (40 lines) | stat: -rw-r--r-- 741 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package xpty

import (
	"os/exec"

	"github.com/charmbracelet/x/conpty"
)

// ConPty is a Windows console pty.
type ConPty struct {
	*conpty.ConPty
}

var _ Pty = &ConPty{}

// NewConPty creates a new ConPty.
func NewConPty(width, height int, opts ...PtyOption) (*ConPty, error) {
	var opt Options
	for _, o := range opts {
		o(opt)
	}

	c, err := conpty.New(width, height, opt.Flags)
	if err != nil {
		return nil, err
	}

	return &ConPty{c}, nil
}

// Name returns the name of the ConPty.
func (c *ConPty) Name() string {
	return "windows-pty"
}

// Start starts a command on the ConPty.
// This is a wrapper around conpty.Spawn.
func (c *ConPty) Start(cmd *exec.Cmd) error {
	return c.start(cmd)
}