GithubHelp home page GithubHelp logo

term's People

Contributors

aitjcize avatar andy-js avatar attilafueloep avatar davecheney avatar domluna avatar dugoisd avatar dumbbell avatar gdamore avatar haraldnordgren avatar jdeppe-pivotal avatar kivikakk avatar lelandbatey avatar leonklingele avatar liamstask avatar mewmew avatar mndrix avatar msiegen avatar ssgelm avatar stephan57160 avatar stuartpearlmancomcast avatar timotto avatar tklauser avatar twpayne avatar zserge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

term's Issues

Unable to obtain underlying error causing short write.

Unable to obtain underlying error causing short write. If the syscall.Write() fails due to an error, the code examines the returned length which is very likely to be less than what was intended to be written and returns io.ErShortWrite.

In my case, the USB serial device was removed and I need to know that the fd is bad, so I can take the appropriate action.

func (t *Term) Write(b []byte) (int, error) {
n, e := syscall.Write(t.fd, b)
if n < 0 {
n = 0
}
if n != len(b) {
return n, io.ErrShortWrite
}
if e != nil {
return n, &os.PathError{"write", t.name, e}
}
return n, nil
}

FD leak in open()

The code of term.Open() does not close the FD, in case of error:

// Open opens an asynchronous communications port.
func Open(name string, options ...func(*Term) error) (*Term, error) {
	fd, e := unix.Open(name, unix.O_NOCTTY|unix.O_CLOEXEC|unix.O_NDELAY|unix.O_RDWR, 0666)
	if e != nil {
		// FD not opened, so, we don't care.
		return nil, &os.PathError{
			Op:   "open",
			Path: name,
			Err:  e,
		}
	}

	orig, err := termios.Tcgetattr(uintptr(fd))
	if err != nil {
		// FD opened, but not closed.
		return nil, err
	}
	t := Term{name: name, fd: fd, orig: *orig}
	if err := t.SetOption(options...); err != nil {
		// FD open, but not closed.
		return nil, err
	}
	
	// FD opened, but not closed if SetNonblock() fails.
	return &t, unix.SetNonblock(t.fd, false)
}

Leak may happen, when the supposed TERM file is not a TERM.

Git tags

Could you to add git tags to the releases? To be able to know when is safe to update the library (seeing whether the change has been at major or minor version).
Thanks!

termios package does not compile under OpenBSD, NetBSD or DragonflyBSD

The termios/pty_bsd.go build tags build the file for FreeBSD, NetBSD and OpenBSD, but two of the syscall constants that it refers to (syscall.SYS_POSIX_OPENPT and syscall.TIOCGPTN) are only defined for FreeBSD if you grep the syscall package source.

In addition to this, the BSD variant files are missing build tags for DragonflyBSD.

term: need windows support

16b2e60 make term/termios a noop under windows, but the higher level term package is still POSIX specific.

The plan is to add a new low level package for windows, term/win32 (just an example, please don't flame) and adjust the term package to use it depending on the host GOOS.

Consider releasing a semantic version of term so it can be used with go mod

Good morning. I've found this package to be quite robust for managing serial communications with some embedded systems work we are doing and would like to rely on it as a dependency.

We are using Go Modules and would appreciate it if you could release a tag with V0.1.0 or whatever version you feel is appropriate for now.

Setting odd parity

Greetings,
Not really an issue, but rather a question:
I would like to use the Term package to talk to a piece of legacy equipment that only supports odd parity. It is not apparent to me how one configures this setting within Term. Can anyone provide guidance?
Thanks in advance,
-Pete

termios does not build on Illumos/OpenIndiana

I try to build gitlab-runner in OpenIndiana. pkg/term included in gitlab-runner is too old and compilation failed.
I managed to replace the vendored x/sys/unix and pkg/term.
But now compilation fails with "...undefined: open_pty_master".
The function is available in pty_solaris.go but the file is not used when built.
When I change to the directory of termios and check which files will be built, I get
../termios# go list -f '{{.GoFiles}}'
[doc.go ioctl_solaris.go pty.go termios.go]
When I edit pty_solaris.go and comment out 'import "C"' pty_solaris.go is found by go list
../termios# go list -f '{{.GoFiles}}'
[doc.go ioctl_solaris.go pty.go pty_solaris.go termios.go]

Is this a problem of using cgo and conditional compilation?
Unfortunately I am a complete newbie concerning go and I have no clue what to do.

Similar problems
http://muscles.dragonflybsd.org/synth/logs/net___concourse-fly.log
fiam/idf_wmonitor#1
#27

/termios# go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="solaris"
GOOS="solaris"
GOPATH="/export/builds/oi-userland/components/sysutils/gitlab-runner/build/amd64/.gopath"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/golang/1.11"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/1.11/pkg/tool/solaris_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build206860015=/tmp/go-build -gno-record-gcc-switches"

termios does not build on mips64le

$ go get github.com/pkg/term

# github.com/pkg/term/termios
term/termios/termios_linux.go:78:61: attr.Ispeed undefined (type *syscall.Termios has no field or method Ispeed)
term/termios/termios_linux.go:81:61: attr.Ospeed undefined (type *syscall.Termios has no field or method Ospeed)

Please make new release including PR #54

Current release has a bug building on macOS.

##[error]../../../go/pkg/mod/github.com/pkg/[email protected]/termios/ioctl.go:8:30: undefined: unix.SYS_IOCTL

This error was introduced with 1cd1864#diff-55be90b78724feed63a53d4ea3212178 which was part of v1.0.0.

This issue later resolved with 8dfd1b8#diff-55be90b78724feed63a53d4ea3212178 which is part of #54

It would be very helpful to make a new release including this fix. Otherwise go modules catching v1.0.0 which failes on macOS.

add support for parity

Would it be possible to add parity support? I'm looking for a package which supports Windows, MacOS, and Linux and can handle RTS + DTR control as well as cofigutable parity. The latter preferably without closing/re-opening, which appears to match the way this package is already set up.

I could look into it, and try my hand at making this work on at least MacOS and Linux. Windows is a bit harder for me, although I will need to fully support that as well.

But my first questions are really: is there interest in adding this? could someone help with the Windows implementation?

Cheers,
-jcw

CSTOPB set for a serial port in OS X 10.6

My serial port, by default, has one stop bit. After opening it with term.Open, it is set to two.

In shell, stty -a -f /dev/cu.usbserial prints out the following cflags:

cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
-dtrflow -mdmbuf

However, once I open the port (with RawMode), CSTOPB seems set. I added a debug print for termios.Tcgetattr(uintptr(t.fd), &attr): 36608. CSTOPB is 1024 on my computer and is therefore set.

I do not understand serial communication enough to figure out whether the issue pops up in the initialization of the port or somewhere else.

undefined: open_pty_master Ptsname grantpt unlockpt

github.com/pkg/term/termios

..............\pkg\term\termios\pty.go:20:14: undefined: open_pty_master
..............\pkg\term\termios\pty.go:25:16: undefined: Ptsname
..............\pkg\term\termios\pty.go:30:8: undefined: grantpt
..............\pkg\term\termios\pty.go:35:8: undefined: unlockpt

pty not compatible with windows

github.com/pkg/term/termios

../go/src/github.com/pkg/term/termios/pty.go:20:14: undefined: open_pty_master
../go/src/github.com/pkg/term/termios/pty.go:25:16: undefined: Ptsname
../go/src/github.com/pkg/term/termios/pty.go:30:8: undefined: grantpt
../go/src/github.com/pkg/term/termios/pty.go:35:8: undefined: unlockpt

os x: callin device/tty support

On OS X, only the callout device (/dev/cu.*) is supported at the moment, since callin device (/dev/tty*) typically requires either:

  • hw handshaking
  • opening the device with O_NONBLOCK and setting CLOCAL to indicate that hw handshaking should be ignored

CLOCAL is set in setSpeed(), so I was hoping to understand whether this was intentional, or if adding O_NONBLOCK to the open flags would be acceptable?

Otherwise at the moment, syscall.Open() blocks indefinitely when passing in a callin device path.

termios/pty_freebsd.go:10:15: undefined: unix

The "o" project https://github.com/xyproto/o fails:

 github.com/pkg/term/termios
vendor/github.com/pkg/term/termios/pty_freebsd.go:10:15: undefined: unix
vendor/github.com/pkg/term/termios/pty_freebsd.go:19:22: undefined: unix
vendor/github.com/pkg/term/termios/pty_freebsd.go:24:19: undefined: unix
vendor/github.com/pkg/term/termios/pty_freebsd.go:33:19: undefined: unix
*** Error code 2

This is a regression between c3ffed2 and v1.1.0 (it was building fine in c3ffed2).

FreeBSD 12.2

api q's

I was curious whether the api for pkg term is intended to support more of the port settings (parity, stop bits, etc) - I don't currently see how to manipulate these currently, since the underlying syscall.Termios is not exported.

Relatedly, there appears to be no getter for speed/baud rate on a port, while there is a setter. Is this intentional, or is there an alternative? Thanks.

go test error in mips64le

mips64le termios doesn't has Ispeed and Ospeed

github.com/pkg/term/termios

termios/termios_linux.go:78:61: attr.Ispeed undefined (type *syscall.Termios has no field or method Ispeed)
termios/termios_linux.go:81:61: attr.Ospeed undefined (type *syscall.Termios has no field or method Ospeed)
FAIL github.com/pkg/term [build failed]

undefined unix

# github.com/pkg/term/termios
.go/pkg/mod/github.com/pkg/[email protected]/termios/pty_freebsd.go:10:15: undefined: unix
.go/pkg/mod/github.com/pkg/[email protected]/termios/pty_freebsd.go:19:22: undefined: unix
.go/pkg/mod/github.com/pkg/[email protected]/termios/pty_freebsd.go:24:19: undefined: unix
.go/pkg/mod/github.com/pkg/[email protected]/termios/pty_freebsd.go:33:19: undefined: unix

$ go version
go version go1.16.5 freebsd/amd64

FreeBSD 12.2

termios does not build on solaris

While building the latest release of influxdb, its term dependency causes the build to fail:

===> Building for influxdb-1.7.1
github.com/pkg/term/termios
# github.com/pkg/term/termios
/home/pbulk/build/databases/influxdb/work/src/github.com/pkg/term/termios/ioctl_solaris.go:6:38: cannot use int(request) (type int) as type uint in argument to unix.IoctlSetInt
/home/pbulk/build/databases/influxdb/work/src/github.com/pkg/term/termios/termios_solaris.go:34:25: cannot convert *termios (type unix.Termios) to type syscall.Termios
/home/pbulk/build/databases/influxdb/work/src/github.com/pkg/term/termios/termios_solaris.go:40:42: cannot use int(action) (type int) as type uint in argument to unix.IoctlSetTermios
/home/pbulk/build/databases/influxdb/work/src/github.com/pkg/term/termios/termios_solaris.go:40:67: cannot convert argp (type *syscall.Termios) to type *unix.Termios
/home/pbulk/build/databases/influxdb/work/src/github.com/pkg/term/termios/termios_solaris.go:80:31: cannot convert attr (type *syscall.Termios) to type *unix.Termios
/home/pbulk/build/databases/influxdb/work/src/github.com/pkg/term/termios/termios_solaris.go:86:31: cannot convert attr (type *syscall.Termios) to type *unix.Termios
/home/pbulk/build/databases/influxdb/work/src/github.com/pkg/term/termios/termios_solaris.go:93:31: cannot convert attr (type *syscall.Termios) to type *unix.Termios
/home/pbulk/build/databases/influxdb/work/src/github.com/pkg/term/termios/termios_solaris.go:99:31: cannot convert attr (type *syscall.Termios) to type *unix.Termios
*** Error code 2

I was able to fix up the uint cases, though I don't understand why the second argument to ioctl is taking uint when the underlying system call takes int. I see in #38 there are other concerns regarding the syscall package that I'm wondering is the cause for the other failures that I don't know how to fix.

I tried with go 1.11.2 and 1.10.5, both fail in the same way.

go vet issues

At rev b1f72af

u@x220 ~> go test github.com/pkg/term/...
# github.com/pkg/term/termios
goget/src/github.com/pkg/term/termios/termios_test.go:113: Fatal call has possible formatting directive %v
goget/src/github.com/pkg/term/termios/termios_test.go:126: Fatal call has possible formatting directive %v
ok  	github.com/pkg/term	0.002s
FAIL	github.com/pkg/term/termios [build failed]

Use term with epoll

We have an application which will open multiple serial ports ('real' serial ports like RS232 or USB CDC/ACM ones) simultaneously. It waits for the first arrival byte to decide which port is going to be selected exclusively for further communications. In the old C implementation, it uses non-blocking I/O to check all the open ports in a spinning loop, which is quite inefficient. Therefore, we would like to use epoll(7) to implement the functionality with the serial port APIs provided by the term package. However, the underlying file descriptor managed by Term, which is needed by epoll, is not exposed.

In summary, we need a way to use epoll or the similar to cooperate pkg/term.

Here is the proposed PR #20

Expose ability to modify arbitrary terminal attibutes via Term struct

Currently, if I use the github.com/pkg/term package, there is no mechanism to allow a developer to modify arbitrary attributes of a terminal managed by a Term struct. This is unfortunate, since the Term struct exposes some great functionality, and it would be awesome if there where a way to use the Term struct, but manually set the attributes I want.

Why Is SetOption Publicly Exported?

What's odd is that the Term struct does have a method, SetOption, which seems like it would allow a developer to make the manual changes one desires. But SetOption accepts functions which modify Term, but since Term has no exported fields, no function defined outside of this package can access any fields of Term, meaning no externally defined function can make use of SetOption. Since SetOption isn't useful outside of this package (at least as far as I can tell), why is it exported publicly?

I think the quickest change to get the functionality I'm describing would be to make the fields of Term public. Barring that, some other way of manually setting terminal attributes would be awesome!

LF/CR issue in rawmode

OS: Linux

After

     t, _ := term.Open("/dev/tty")
     defer t.Close()
     defer t.Restore()
     term.RawMode(t)

Any fmt.Printf("something ...\n") or fmt.Println() to stdio results LF only, without CR.
Have to print ending with "\n\r"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.