Giter Site home page Giter Site logo

term's Introduction

term - utilities for dealing with terminals

Test GoDoc Go Report Card

term provides structures and helper functions to work with terminal (state, sizes).

Using term

package main

import (
	"log"
	"os"

	"github.com/moby/term"
)

func main() {
	fd := os.Stdin.Fd()
	if term.IsTerminal(fd) {
		ws, err := term.GetWinsize(fd)
		if err != nil {
			log.Fatalf("term.GetWinsize: %s", err)
		}
		log.Printf("%d:%d\n", ws.Height, ws.Width)
	}
}

Contributing

Want to hack on term? Docker's contributions guidelines apply.

Copyright and license

Code and documentation copyright 2015 Docker, inc. Code released under the Apache 2.0 license. Docs released under Creative commons.

term's People

Contributors

ahmetb avatar akihirosuda avatar brianm avatar calavera avatar cpuguy83 avatar creack avatar crosbymichael avatar dims avatar dnephin avatar jessfraz avatar jstarks avatar kolyshkin avatar lk4d4 avatar metaliveblog avatar mzdaniel avatar n4j avatar runcom avatar sachin-jayant-joshi avatar thajeztah avatar tianon avatar tiborvass avatar titanous avatar tklauser avatar tophj-ibm avatar unclejack avatar vbatts avatar vdemeester avatar vieux avatar yoheiueda avatar yongtang 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

Watchers

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

term's Issues

Compilation broken on windows/386

At

stdIn = windowsconsole.NewAnsiReader(windows.STD_INPUT_HANDLE)
and again in lines 80 and 86, the given standard values are used as an int in windows.NewAnsiReader/Writer. However, those values overflow an int if the int is 32-bit, because they're actually (from the x/sys/windows package) uints. As a result, compilation fails:

$ GOOS=windows GOARCH=386 go build .
# github.com/moby/term
./term_windows.go:74:39: constant 4294967286 overflows int
./term_windows.go:80:40: constant 4294967285 overflows int
./term_windows.go:86:40: constant 4294967284 overflows int

Ref: ory/dockertest#232

On git-bash.exe in windows stdout is no terminal?

On windows with git-bash.exe: The following reports false and true

fmt.Print(term.IsTerminal(os.Stdout.Fd()))
fmt.Print(term.IsTerminal(os.Stderr.Fd()))

Do you know why stdout is no terminal but stderr is?

Support building on "darwin" with golang.org/x/sys updated over 6fcdbc0bbc04dcd9e7dc145879ceaf9bf1c6ff03

golang/sys@6fcdbc0 has removed some "darwin" related code, so projects, which use higher versions of golang.org/x/sys can no longer be built for this platform.

Example:

cat <<EOF > go.mod
module foo

go 1.15

require (
        github.com/moby/term v0.0.0-20200611042045-63b9a826fb74
        golang.org/x/sys v0.0.0-20200828080924-6fcdbc0bbc04 // indirect
)
EOF

cat <<EOF > main.go
package main

import (
        "log"
        "os"

        "github.com/moby/term"
)

func main() {
        fd := os.Stdin.Fd()
        if term.IsTerminal(fd) {
                ws, err := term.GetWinsize(fd)
                if err != nil {
                        log.Fatalf("term.GetWinsize: %s", err)
                }
                log.Printf("%d:%d\n", ws.Height, ws.Width)
        }
}
EOF

GOOS=darwin go build

Results in:

# github.com/moby/term
../../../go/pkg/mod/github.com/moby/[email protected]/tc.go:13:28: undefined: unix.SYS_IOCTL
../../../go/pkg/mod/github.com/moby/[email protected]/tc.go:18:28: undefined: unix.SYS_IOCTL
../../../go/pkg/mod/github.com/moby/[email protected]/termios_bsd.go:24:31: undefined: unix.SYS_IOCTL
../../../go/pkg/mod/github.com/moby/[email protected]/termios_bsd.go:37:31: undefined: unix.SYS_IOCT

Note: the same now happens for older versions of github.com/docker/docker or github.com/moby/moby, but the latest master already depends on this code here.

Invalid Standard Handle Panic on Windows Server 2012

Hello!

Since PR #9 we receive the following panic with the moby/term package on a windows server 2012 within a powershell (it worked fine before that), when trying to call term.StdStreams():

panic: Invalid standard handle identifier: 4294967286

goroutine 1 [running]:
github.com/Azure/go-ansiterm/winterm.GetStdFile(0xfffffff6, 0x28, 0xf)
        C:/Users/Administrator/DevSpace/devspace/vendor/github.com/Azure/go-ansiterm/winterm/ansi.go:173 +0x1f6
github.com/moby/term/windows.NewAnsiReader(0xfffffff6, 0xc00000000f, 0x2110980)
        C:/Users/Administrator/DevSpace/devspace/vendor/github.com/moby/term/windows/ansi_reader.go:34 +0x36
github.com/moby/term.StdStreams(0x210ed20, 0xc0000d0000, 0x210ed60, 0xc0000d0008, 0x0, 0x0)
        C:/Users/Administrator/DevSpace/devspace/vendor/github.com/moby/term/term_windows.go:74 +0x1f8

Its essentially the same error as described in for-win. Maybe I'm mistaken, but I though the PR #9 would replace the github.com/Azure/go-ansiterm package completely, however it seems to be still used in windows/ansi_reader.go, which could cause this issue.

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.