pkg / term Goto Github PK
View Code? Open in Web Editor NEWPackage term manages POSIX terminals.
License: BSD 2-Clause "Simplified" License
Package term manages POSIX terminals.
License: BSD 2-Clause "Simplified" License
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]
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
..............\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
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!
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.
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.
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"
Hello,
In according to https://golang.org/pkg/syscall:
Deprecated: this package is locked down. Callers should use the
corresponding package in the golang.org/x/sys repository instead.
In my point of view, we have to update.
Please clarify your point of view.
# 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
I want to use Sourcegraph code search and code review with term. A project maintainer needs to enable it to set up a webhook so the code is up-to-date there.
Could you please enable term on @sourcegraph by going to https://sourcegraph.com/github.com/pkg/term and clicking on Settings? (It should only take 15 seconds.)
Thank you!
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.
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!
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.
On OS X, only the callout device (/dev/cu.*
) is supported at the moment, since callin device (/dev/tty*
) typically requires either:
O_NONBLOCK
and setting CLOCAL
to indicate that hw handshaking should be ignoredCLOCAL 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.
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
}
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.
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
Not sure if this is the appropriate place for such a function, but it would be good to have this helper function included in this package.
mips64le termios doesn't has Ispeed and Ospeed
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]
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.
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.
$ 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)
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
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
Python's tty module has a convenient setraw
function that puts the serial port in raw mode. It would be great if term
had a similar function in its high-level interface. Thanks!
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.
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.
Available() delegates to TIocinq, which is stubbed out as a no-op.
https://github.com/pkg/term/blob/master/termios/termios_bsd.go#L81
Has anyone done evaluated what it would take to get it to work?
Seems like you might at least be able to do a select() call on the descriptor, to check if there's any data in the buffer (returning 1 or 0 would at least be marginally better than returning 0 all the time)
../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
Do mind publishing a new release soonish with FreeBSD build fixes? #61
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"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.