Skip to content

Commit

Permalink
refactor: rename type
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Sep 22, 2023
1 parent c09e44d commit 35e7e62
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (c *Cmd) start() error {
if !ok {
return ErrInvalidCommand
}
pty, ok := c.pty.(*PosixPty)
pty, ok := c.pty.(*UnixPty)
if !ok {
return ErrInvalidCommand
}
Expand Down
32 changes: 16 additions & 16 deletions pty_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import (
"golang.org/x/sys/unix"
)

// PosixPty is a POSIX compliant pseudo-terminal.
// UnixPty is a POSIX compliant Unix pseudo-terminal.
// See: https://pubs.opengroup.org/onlinepubs/9699919799/
type PosixPty struct {
type UnixPty struct {
master, slave *os.File
closed bool
}

var _ Pty = &PosixPty{}
var _ Pty = &UnixPty{}

// Close implements Pty.
func (p *PosixPty) Close() error {
func (p *UnixPty) Close() error {
if p.closed {
return nil
}
Expand All @@ -34,7 +34,7 @@ func (p *PosixPty) Close() error {
}

// Command implements Pty.
func (p *PosixPty) Command(name string, args ...string) *Cmd {
func (p *UnixPty) Command(name string, args ...string) *Cmd {
cmd := exec.Command(name, args...)
c := &Cmd{
pty: p,
Expand All @@ -47,7 +47,7 @@ func (p *PosixPty) Command(name string, args ...string) *Cmd {
}

// CommandContext implements Pty.
func (p *PosixPty) CommandContext(ctx context.Context, name string, args ...string) *Cmd {
func (p *UnixPty) CommandContext(ctx context.Context, name string, args ...string) *Cmd {
cmd := exec.CommandContext(ctx, name, args...)
c := p.Command(name, args...)
c.ctx = ctx
Expand All @@ -58,16 +58,16 @@ func (p *PosixPty) CommandContext(ctx context.Context, name string, args ...stri
}

// Name implements Pty.
func (p *PosixPty) Name() string {
func (p *UnixPty) Name() string {
return p.slave.Name()
}

// Read implements Pty.
func (p *PosixPty) Read(b []byte) (n int, err error) {
func (p *UnixPty) Read(b []byte) (n int, err error) {
return p.master.Read(b)
}

func (p *PosixPty) Control(f func(fd uintptr)) error {
func (p *UnixPty) Control(f func(fd uintptr)) error {
conn, err := p.master.SyscallConn()
if err != nil {
return err
Expand All @@ -76,20 +76,20 @@ func (p *PosixPty) Control(f func(fd uintptr)) error {
}

// Master returns the pseudo-terminal master end (pty).
func (p *PosixPty) Master() *os.File {
func (p *UnixPty) Master() *os.File {
return p.master
}

// Slave returns the pseudo-terminal slave end (tty).
func (p *PosixPty) Slave() *os.File {
func (p *UnixPty) Slave() *os.File {
return p.slave
}

// Winsize represents the terminal window size.
type Winsize = unix.Winsize

// SetWinsize sets the pseudo-terminal window size.
func (p *PosixPty) SetWinsize(ws *Winsize) error {
func (p *UnixPty) SetWinsize(ws *Winsize) error {
var ctrlErr error
if err := p.Control(func(fd uintptr) {
ctrlErr = unix.IoctlSetWinsize(int(fd), unix.TIOCSWINSZ, ws)
Expand All @@ -101,20 +101,20 @@ func (p *PosixPty) SetWinsize(ws *Winsize) error {
}

// Resize implements Pty.
func (p *PosixPty) Resize(width int, height int) error {
func (p *UnixPty) Resize(width int, height int) error {
return p.SetWinsize(&Winsize{
Row: uint16(height),
Col: uint16(width),
})
}

// Write implements Pty.
func (p *PosixPty) Write(b []byte) (n int, err error) {
func (p *UnixPty) Write(b []byte) (n int, err error) {
return p.master.Write(b)
}

// Fd implements Pty.
func (p *PosixPty) Fd() uintptr {
func (p *UnixPty) Fd() uintptr {
return p.master.Fd()
}

Expand All @@ -124,7 +124,7 @@ func newPty() (Pty, error) {
return nil, err
}

return &PosixPty{
return &UnixPty{
master: master,
slave: slave,
}, nil
Expand Down

0 comments on commit 35e7e62

Please sign in to comment.