Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: CI

# yamllint disable-line rule:truthy
on:
check_run:
types:
- rerequested
- requested_action
pull_request: {}
push:
branches:
- master
tags:
- v*

env:
GO111MODULE: "on"

defaults:
run:
# NOTE: when testing on windows, we may need non-cygwin environment
# so we need to change shell when doing actual testing on windows
shell: bash

jobs:
unit-test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
go:
- 1.13.x
- 1.14.x
- 1.15.x
os:
- ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}

- name: Lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.33

- name: Ensure tidy gomod
run: |
go mod download -x
go mod tidy
if ! git diff --exit-code
then
echo "go mod not tidy"
exit 1
fi

- name: Test crossbuild
run: |
sh test_crosscompile.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
_go*
_test*
_obj
.idea
77 changes: 77 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
run:
deadline: 5m
tests: true
modules-download-mode: readonly

output:
format: colored-line-number
print-issued-lines: true
print-linter-name: true
sort-results: true

linters:
disable-all: true
enable:
- golint
- errcheck
- misspell
- deadcode
- govet
- typecheck
- lll
- megacheck
- varcheck
- unconvert
- bodyclose
- scopelint
- goimports
- ineffassign
- gofmt
- maligned
- goconst
- gocyclo
- unparam
- structcheck
- staticcheck
- gocritic

linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0
misspell:
locale: US
unused:
check-exported: false
gocyclo:
min-complexity: 30
goimports:
local-prefixes: github.com/creack/pty
lll:
line-length: 120
# tab width in spaces. Default to 1.
tab-width: 4
maligned:
suggest-new: true

issues:
exclude-rules:
- path: _test\.go
linters:
- gocyclo
- errcheck
- dupl
- gosec
- maligned
- lll
- scopelint
- goconst

- path: kubehelper
linters:
- lll

- text: "commentFormatting: put a space between `//` and comment text"
linters:
- gocritic
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pty

Pty is a Go package for using unix pseudo-terminals.
Pty is a Go package for using unix pseudo-terminals and windows ConPty.

## Install

Expand Down
32 changes: 30 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,42 @@ package pty

import (
"errors"
"os"
"io"
)

// ErrUnsupported is returned if a function is not
// available on the current platform.
var ErrUnsupported = errors.New("unsupported")

// Opens a pty and its corresponding tty.
func Open() (pty, tty *os.File, err error) {
func Open() (Pty, Tty, error) {
return open()
}

type (
FdHolder interface {
Fd() uintptr
}

// Pty for terminal control in current process
// for unix systems, the real type is *os.File
// for windows, the real type is a *WindowsPty for ConPTY handle
Pty interface {
// Fd intended to resize Tty of child process in current process
FdHolder

// string writer is used to identify Pty and Tty
io.StringWriter
io.ReadWriteCloser
}

// Tty for data i/o in child process
// for unix systems, the real type is *os.File
// for windows, the real type is a *WindowsTty, which is a combination of two pipe file
Tty interface {
// Fd only intended for manual InheritSize from Pty
FdHolder

io.ReadWriteCloser
}
)
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ module github.com/creack/pty

go 1.13

require golang.org/x/sys v0.0.0-20201119102817-f84b799fce68
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
9 changes: 5 additions & 4 deletions ioctl_solaris.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package pty

import (
"golang.org/x/sys/unix"
"unsafe"

"golang.org/x/sys/unix"
)

const (
// see /usr/include/sys/stropts.h
I_PUSH = uintptr((int32('S')<<8 | 002))
I_STR = uintptr((int32('S')<<8 | 010))
I_FIND = uintptr((int32('S')<<8 | 013))
I_PUSH = uintptr((int32('S')<<8 | 002))
I_STR = uintptr((int32('S')<<8 | 010))
I_FIND = uintptr((int32('S')<<8 | 013))
// see /usr/include/sys/ptms.h
ISPTM = (int32('P') << 8) | 1
UNLKPT = (int32('P') << 8) | 2
Expand Down
2 changes: 1 addition & 1 deletion pty_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func open() (pty, tty *os.File, err error) {
return nil, nil, err
}

if err := unlockpt(p); err != nil {
if err = unlockpt(p); err != nil {
return nil, nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion pty_unsupported.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !linux,!darwin,!freebsd,!dragonfly,!openbsd,!solaris
// +build !linux,!darwin,!freebsd,!dragonfly,!openbsd,!solaris,!windows

package pty

Expand Down
Loading