go-isatty - isatty for golang.

Overview

go-isatty

Godoc Reference Codecov Coverage Status Go Report Card

isatty for golang

Usage

package main

import (
	"fmt"
	"github.com/mattn/go-isatty"
	"os"
)

func main() {
	if isatty.IsTerminal(os.Stdout.Fd()) {
		fmt.Println("Is Terminal")
	} else if isatty.IsCygwinTerminal(os.Stdout.Fd()) {
		fmt.Println("Is Cygwin/MSYS2 Terminal")
	} else {
		fmt.Println("Is Not Terminal")
	}
}

Installation

$ go get github.com/mattn/go-isatty

License

MIT

Author

Yasuhiro Matsumoto (a.k.a mattn)

Thanks

Comments
  • Termux Android cannot find

    Termux Android cannot find "golang.org/x/sys/unix"

    On Termux Android, the lib depends to go-issaty is failing. It cannot find golang.org/x/sys/unix. I might relate to https://github.com/mattn/go-isatty/pull/28?

    opened by uudashr 10
  • Enable go modules

    Enable go modules

    Go modules are becoming a de-facto standard in the Go community and adding go.mod files with metadata helps projects which may consume this repository as a dependency in deciding how to pin transitive dependencies and how to resolve conflicts.

    This is a result of the following commands:

    go mod init
    go get ./...
    go mod tidy
    

    in a clean Go 1.11.5 environment.

    opened by radeksimko 8
  • Interactive mode or not

    Interactive mode or not

    This is a feature request. Is it possible to determine if the go code is running in interactive mode or not? So that we can decide if we need to use the options / flag or interactive with end user for options.

    opened by stantonxu 8
  • Update go.sum after golang.org/x/sys update

    Update go.sum after golang.org/x/sys update

    PR #66 updated the golang.org/x/sys dependency in go.mod but didn't update go.sum. This leads to the following error on running go.test.sh:

    go: golang.org/x/[email protected]: missing go.sum entry; to add it:
    	go mod download golang.org/x/sys
    go: golang.org/x/[email protected]: missing go.sum entry; to add it:
    	go mod download golang.org/x/sys
    

    Fix this by running go mod download golang.org/x/sys && go mod tidy to update and clean up go.sum.

    opened by tklauser 6
  • Terminal is not detected when redirecting the output from the shell

    Terminal is not detected when redirecting the output from the shell

    When executing a golang app while redirecting the output from the shell (./app > /tmp/my.log), IsTerminal() returns false even though the app is run from a terminal. Is there any reason for that?

    opened by asticode 6
  • IntelliJ console

    IntelliJ console

    Although the windows IsTerminal correctly detected when it is in a Windows terminal, it doesn't detect if it is in an IntelliJ terminal. Would this be possible to add? I honestly have no idea :(

    Thanks!

    opened by pliu 6
  • undefined: unix.IoctlGetTermios

    undefined: unix.IoctlGetTermios

    I'm trying to build a project that uses "golang:1.13.10-alpine" docker image inside of Amazon-kubernetes enviroment, but there is an error:

    vendor/github.com/mattn/go-isatty/isatty_tcgets.go:10:12: undefined: unix.IoctlGetTermios

    Any thoughts?

    opened by Ramzec 5
  • Update x/sys to support Risc-V

    Update x/sys to support Risc-V

    Updating projects using libraries that were recently updated to support Risc-V architecture.

    Go upstream work is tracked on: golang/go#27532

    Risc-V software support tracker on https://github.com/carlosedp/riscv-bringup

    Signed-off-by: CarlosEDP [email protected]

    opened by carlosedp 5
  • Missing method

    Missing method

    After you have added separate source for android builds, gin is failing because cannot find IsCygwinTerminal for android build.

    ../../gin-gonic/gin/logger.go:201:67: undefined: isatty.IsCygwinTerminal
    
    opened by elgatito 5
  • use golang.org/x/sys/unix for IsTerminal on Linux

    use golang.org/x/sys/unix for IsTerminal on Linux

    Use the unix.IoctlGetTermios to implement IsTerminal on Linux. This allows to drop the special case for ppc64x and makes go-isatty support all GOARCHes that golang.org/x/sys/unix supports for Linux. Also this no longer requires to use ithe frozen syscall package.

    opened by tklauser 5
  • please tag and version this project

    please tag and version this project

    Hello,

    Can you please tag and version this project?

    I am the Debian Maintainer for go-isatty and versioning would help Debian keep up with development.

    opened by aviau 4
  • Check that TCGETS is indeed the way to go

    Check that TCGETS is indeed the way to go

    Please check if TCGETS is appropriate here: https://github.com/mattn/go-isatty/blob/13e91bf4058fb93d5629deb7b2e3763ec8f4fdf8/isatty_tcgets.go#L11 See https://git.musl-libc.org/cgit/musl/patch/?id=2de85a985654d2c944931267645d9a0686242dfe for details.

    opened by szakharchenko 0
  • Adjust build tags to allow building on tinygo; for #73.

    Adjust build tags to allow building on tinygo; for #73.

    Passes "tinygo test" on macos and linux. Passes cross test to windows from macos, i.e. "GOOS=windows tinygo test -c; wine64 go-isatty.test".

    Had to adjust the build tags on isatty_others.go to avoid multiple definition link failure on

    $ GOOS=windows tinygo test
    
    opened by dkegel-fastly 1
  • Incompatible with tinygo?

    Incompatible with tinygo?

    Evidently zerolog 0.27 added colorization on windows by pulling in mattn/go-colorable, which in turn pulls in go-isatty. Great! Except that now zerolog can't be used with tinygo (on macos, at least, and possibly other operating systems).

    At least part of the problem can be traced to go-isatty:

    $ tinygo test
    # golang.org/x/sys/unix
    ../../go/pkg/mod/golang.org/x/[email protected]/unix/syscall_unix.go:466:17: Exec not declared by package syscall
    FAIL
    
    opened by dkegel-fastly 1
  • IsCygwinTerminal doesn't work on Cygwin

    IsCygwinTerminal doesn't work on Cygwin

    👋🏻

    I have the following example, which when run on a Windows 10 VM with Cygwin configured it doesn't actually report anything other than "Is Terminal", when I would expect both that and "Is Cygwin/MSYS2 Terminal" to be displayed.

    package main
    
    import (
    	"fmt"
    	"os"
    
    	"github.com/mattn/go-isatty"
    )
    
    func main() {
    	if isatty.IsTerminal(os.Stdout.Fd()) {
    		fmt.Println("Is Terminal")
    	}
    	if isatty.IsCygwinTerminal(os.Stdout.Fd()) {
    		fmt.Println("Is Cygwin/MSYS2 Terminal")
    	}
    }
    

    Let me know if you need any more information.

    Thanks!

    opened by Integralist 0
  • Is there a way to detect a TTY?

    Is there a way to detect a TTY?

    Hi @mattn ,

    I'm using your library to use or not coloration for my logger. It helps me having colors locally, and better syntax for third-party tools to look at logs (in a cluster...).

    Your library is great with runtime except when using tests (go test ...). Do you have a solution to detect a real terminal is behind the command?

    I can implement on my own something to force during tests by setting an environment variable, but curious to know your thoughts on this 😄

    Thank you,

    EDIT: some reading https://github.com/constabulary/gb/issues/472

    Librairies that can help formatting "test metadata":

    • https://github.com/rakyll/gotest
    • https://github.com/kyoh86/richgo
    opened by sneko 0
  • feature request: detect Windows Terminal

    feature request: detect Windows Terminal

    Hey! I really like your library and I will be using it for my module for detecting 8 bit color support for Windows Console. As this module also supports Cygwin, can you also add detection for Windows Terminal as it is entirely different from Windows Console.

    Thanks!

    opened by Delta456 15
Owner
mattn
Long-time Golang user&contributor, Google Dev Expert for Go, and author of many Go tools, Vim plugin author. Windows hacker C#/Java/C/C++
mattn
A really basic thread-safe progress bar for Golang applications

progressbar A very simple thread-safe progress bar which should work on every OS without problems. I needed a progressbar for croc and everything I tr

Zack 2.8k Sep 28, 2022
A tiny library for super simple Golang tables

Tabby A tiny library for super simple Golang tables Get Tabby go get github.com/cheynewallace/tabby Import Tabby import "github.com/cheynewallace/tabb

Cheyne Wallace 320 Sep 2, 2022
Golang terminal dashboard

termui termui is a cross-platform and fully-customizable terminal dashboard and widget library built on top of termbox-go. It is inspired by blessed-c

Zack Guo 12.1k Sep 22, 2022
go-isatty - TTY 环境判断

go-isatty isatty for golang Usage package main import ( "fmt" "github.com/mattn/go-isatty" "os" ) func main() { if isatty.IsTerminal(os.Stdout.F

mattn 643 Sep 26, 2022
[Crawler/Scraper for Golang]🕷A lightweight distributed friendly Golang crawler framework.一个轻量的分布式友好的 Golang 爬虫框架。

Goribot 一个分布式友好的轻量的 Golang 爬虫框架。 完整文档 | Document !! Warning !! Goribot 已经被迁移到 Gospider|github.com/zhshch2002/gospider。修复了一些调度问题并分离了网络请求部分到另一个仓库。此仓库会继续

null 208 Aug 26, 2022
Realize is the #1 Golang Task Runner which enhance your workflow by automating the most common tasks and using the best performing Golang live reloading.

#1 Golang live reload and task runner Content - ⭐️ Top Features - ???? Get started - ?? Config sample - ?? Commands List - ?? Support and Suggestions

Oxequa 4.3k Sep 21, 2022
golang feature toggle library - a library to help make golang feature toggling clean and easy

toggle supports env_variable backed toggling. It can also be updated via a pubsub interface (tested w/ redis) 2 engines for toggle backing are include

John Calabrese 24 Mar 29, 2022
Hprose 1.0 for Golang (Deprecated). Hprose 2.0 for Golang is here:

Hprose for Golang Introduction Installation Usage Http Server Http Client Synchronous Invoking Synchronous Exception Handling Asynchronous Invoking As

Hprose 137 Sep 22, 2022
graylog-golang is a full implementation for sending messages in GELF (Graylog Extended Log Format) from Go (Golang) to Graylog

graylog-golang is a full implementation for sending messages in GELF (Graylog Extended Log Format) from Go (Golang) to Graylog

Robert Kowalski 79 Aug 12, 2022
Realize is the #1 Golang Task Runner which enhance your workflow by automating the most common tasks and using the best performing Golang live reloading.

#1 Golang live reload and task runner Content - ⭐️ Top Features - ???? Get started - ?? Config sample - ?? Commands List - ?? Support and Suggestions

Oxequa 4.3k Sep 29, 2022
Golang Skeleton With Fully Managed Versions For Kick Start GoLang Project Development

Golang Skeleton With Fully Managed Versions For Kick Start GoLang Project Development There is no doubt that Golang’s good documentation and intellige

MindInventory 344 Sep 20, 2022
Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/rpc package.

Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/rpc package. The library allows you to call Go service methods from PHP with a minimal footprint, structures and []byte support.

Spiral Scout 1.1k Sep 22, 2022
Golang CS:GO external base. Development currently halted due to compiler/runtime Golang bugs.

gogo Golang CS:GO External cheat/base. Also, my first Golang project. Wait! Development momentarily halted due to compiler/runtime bugs. Disclaimer Th

cristei 2 Jun 25, 2022
golang 在线预览word,excel,pdf,MarkDown(Online Preview Word,Excel,PPT,PDF,Image by Golang)

Go View File 在线体验地址 http://39.97.98.75:8082/view/upload (不会经常更新,保留最基本的预览功能。服务器配置较低,如果出现链接超时请等待几秒刷新重试,或者换Chrome) 目前已经完成 docker部署 (不用为运行环境烦恼) Wor

CZC 71 Sep 19, 2022
memresolver is an in-memory golang resolver that allows to override current golang Lookup func literals

mem-resolver memresolver is an in-memory golang resolver that allows to override current golang Lookup func literals How to use it Create your custom

Antonio Ojea 4 Jun 23, 2022
Using the Golang search the Marvel Characters. This project is a web based golang application that shows the information of superheroes using Marvel api.

marvel-universe-web using the Golang search the Marvel Universe Characters About The Project This project is a web based golang application that shows

Burak KÖSE 2 Oct 10, 2021
A Golang REST API to handle users and posts for a simple instagram backend. Uses MongoDB as the database. Tested using golang-testing and Postman.

A Golang REST API to handle users and posts for a simple instagram backend. Uses MongoDB as the database. Tested using golang-testing and Postman.

Nitin Narayanan 1 Oct 10, 2021
packM 🧬 is fivem resource compiler for golang with the power of golang+typescript+webpack

packM ?? packM ?? is fivem resource compiler for golang ,typescript with the power of golang+typescript compiler+webpack

normalM 2 Jun 28, 2022
This is my first golang project. The main reason for its existence is the need for practice. I will be studying golang while writing this project

My first GoLang project Project Aim The goal of this project is to develop the most simple golang bot to learn how to work with this programming langu

F0rzend 6 Jan 7, 2022
Go (Golang) API REST with Gin FrameworkGo (Golang) API REST with Gin Framework

go-rest-api-aml-service Go (Golang) API REST with Gin Framework 1. Project Description Build REST APIs to support AML service with the support of exte

Tony Aizize 1 Nov 21, 2021