go-colorable - Colorable writer for windows.

Overview

go-colorable

Build Status Codecov GoDoc Go Report Card

Colorable writer for windows.

For example, most of logger packages doesn't show colors on windows. (I know we can do it with ansicon. But I don't want.) This package is possible to handle escape sequence for ansi color on windows.

Too Bad!

So Good!

Usage

logrus.SetFormatter(&logrus.TextFormatter{ForceColors: true})
logrus.SetOutput(colorable.NewColorableStdout())

logrus.Info("succeeded")
logrus.Warn("not correct")
logrus.Error("something error")
logrus.Fatal("panic")

You can compile above code on non-windows OSs.

Installation

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

License

MIT

Author

Yasuhiro Matsumoto (a.k.a mattn)

Issues
  • Add a generic `NewColorable()` constructor

    Add a generic `NewColorable()` constructor

    The generic constructor accepts any os.File pointer. This is useful when this library is used to support a generic colorable writer stream whose destination (stdout, stderr, log file, etc.) is determined dynamically at runtime.

    Old constructors are kept for backwards compatibility.

    Will conflict with #10

    opened by mislav 18
  • Cross-compile dependency issue

    Cross-compile dependency issue

    There is a subtle problem with cross-compilation for windows under linux/darwin.

    1. go get github.com/mattn/go-colorable being run under linux/darwin skips dependencies in file colorable_windows.go, because of "_windows" prefix. This file though has one external dependency - 'github.com/mattn/isatty', which is ignored and isn't downloaded during go get.
    2. If user want to cross-compile package for windows, go build will return error as it has missing dependency: $ GOOS=windows go build github.com/mattn/go-colorable colorable_windows.go:13:2: cannot find package "github.com/mattn/go-isatty" in any of: /usr/local/go/src/github.com/mattn/go-isatty (from $GOROOT) /Users/divan/src/github.com/mattn/go-isatty (from $GOPATH)
    3. Being a general purpose library, it's imported from many more projects, gin-gonic among them. It ends with users confusion, when he tries to cross-compile package, which depends on go-colorable and it takes time to figure out this issue.

    My proposal is to import 'github.com/mattn/isatty' into colorable_others.go as well to allow go get resolve it as dependency regardless of which platform is used. + _ "github.com/mattn/go-isatty"

    opened by divan 10
  • Make buildable on Windows + goapp

    Make buildable on Windows + goapp

    Echo, a web framework for go uses go-colorable (To be exact, gommon depended by Echo uses go-colorable).

    When developing an application for Go on Google AppEngine with Echo and testing it on Windows, it causes following build failure:

    > goapp serve
    ...
    2017/03/12 10:49:49 go-app-builder: Failed parsing input: parser: bad import "syscall" in github.com\mattn\go-colorable\colorable_others.go from GOPATH
    

    This is caused as Go on Google AppEngine restricts importing syscall.

    This change make go-colorable use colorable_others.go also on Windows when built with appengine.

    opened by ikedam 6
  • Messed ANSI sequences in terminal output (Windows, cmd.exe, PowerShell) instead of colors

    Messed ANSI sequences in terminal output (Windows, cmd.exe, PowerShell) instead of colors

    This ticket originates in research done for epinio/epinio/issues/673, itself a follow up of epinio/epinio/issues/494

    The relevant setup is

    • Platform: Win 10 Home (Virtual Machine, Linux-hosted, VirtualBox)
    • Modules (grep 'fatih\|mattn' go.mod):
      • github.com/fatih/color v1.12.0
      • github.com/mattn/go-isatty v0.0.12
    • Sum Modules (grep 'fatih\|mattn' go.sum |grep -v go.mod):
      • github.com/fatih/color v1.12.0 h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc=
      • github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
      • github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
      • github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54= Without excluding go.mod lines I see a lot more versions for all the packages.

    Below a screenshot demonstrating the differences between a mingw bash (from git for windows) on one side, and cmd.exe and PowerShell on the other side: Screenshot

    While I originally thought that maybe the IsTerminal generates an incorrect result, disabling handling with the output from my last tests I now have to suspect an issue either here in go-colorable, or in its user, https://github.com/fatih/color, which is the actual package used by the epinio code. And I do not see how our use of the fatih/color would be incorrect.

    With regard to the version numbers, fatih/color is at 1.12.0, the latest release as of May 24 this year. Which in turn uses the latest tag 0.1.8 for go-colorable, as of Oct 3 last year.

    Any ideas where else to look for the issue ?

    opened by andreas-kupries 4
  • cannot find module providing package gopkg.in/mattn/go-colorable.v0

    cannot find module providing package gopkg.in/mattn/go-colorable.v0

    I've used Kubebuilder to generate a bunch of code for a Kubernetes custom resource controller. I'd like my custom resource controller to manage BOSH releases so I've got code similar to this to construct a BOSH Director client to pass to my reconciliation controller so it can use it to manage BOSH releases. After adding this code to some of the Kubebuilder-generated code, and running make generate from the Kubebuilder-generated Makefile, it fails when I run go fmt ./....

    $ go fmt ./...
    go: downloading gopkg.in/mattn/go-colorable.v0 v0.1.2
    go: downloading gopkg.in/mattn/go-isatty.v0 v0.0.8
    build github.com/amitkgupta/boshv3: cannot load gopkg.in/mattn/go-colorable.v0: cannot find module providing package gopkg.in/mattn/go-colorable.v0
    

    I'm not importing go-colorable directly anywhere in my code, my guess is some of the packages from github.com/cloudfoundry/bosh-cli that I'm importing have some recursive dependency on go-colorable, so I don't think I can solve this by modifying any import paths in my own code.

    Any pointers on how I might troubleshoot this? I saw #35 but none of the ideas there seemed to help.

    opened by Amit-PivotalLabs 4
  • Fix: 2K" does not erase characters at the bottom">

    Fix: "2K" does not erase characters at the bottom

    Before

    before

    After

    after

    Description

    csbi.window.top seems to become 1 or higher when scrolling down. csbi.window.top seems the number of hidden lines at the top. But FillConsoleOutputCharacterW()'s dwWriteCoord is a coordinate of terminal, not lines and cols. NOTE: I could not test when csbi.window.left is 1 or higher.

    opened by tyru 4
  • Aliases for save/restore cursor position

    Aliases for save/restore cursor position

    Beside ANSI codes <esc>[s (save cursor position) and <esc>[u (restore cursor position) there are also widely used DEC code: <esc>7 and <esc>8 which do mostly the same, but are preferred sometimes because <esc>[s and <esc>[u don't work in some terminals like VT100 and Mosh (See https://github.com/mobile-shell/mosh/issues/726)

    See also: "Some terminals require the DEC sequences ESC 7 / ESC 8 instead which is more widely supported." See https://en.wikipedia.org/wiki/ANSI_escape_code#Examples

    See also: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#span-idsimplecursorpositioningspanspan-idsimplecursorpositioningspanspan-idsimplecursorpositioningspansimple-cursor-positioning

    https://vt100.net/docs/vt100-ug/chapter3.html#DECSC

    Can you add such an alias?

    opened by filimonov 4
  • archive not available?

    archive not available?

    I used to access https://github.com/mattn/go-colorable/archive/d228849504861217f796da67fae4f6e347643f15/go-colorable-d228849.tar.gz directly, but mow getting "curl: (22) The requested URL returned error: 500 Internal Server Error" do you know whether this should still work?

    opened by marcindulak 4
  • Remove procGetConsoleScreenBufferInfo.Call whose result looks to be unused

    Remove procGetConsoleScreenBufferInfo.Call whose result looks to be unused

    On func (w *Writer) Write([]byte) of colorable_windows.go, procGetConsoleScreenBufferInfo is called twice and the resuilt of the first one looks to be unused.

    It does not cause any problems, but by removing one api-call, the speed to draw text may be improved.

    (Japanese)
    Windows向けの Write 関数の中で2連続でprocGetConsoleScreenBufferInfoを呼び出している箇所があり、最初の方を削除してはどうかというプルリクエストです。実害はないのですが、自分のすごく重たい VM 上だと表示速度が目に見えて遅いので(go-colorable の責任ではなくハードが非力)、API呼び出しを減らして、少しでも表示速度を改善したいと思った次第です。
    opened by hymkor 4
  • Make colorable encoding agnostic

    Make colorable encoding agnostic

    ANSI sequences are defined in the ASCII encoding. Any stream of bytes in an encoding which is a superset of ASCII should be processable through a colorable and any byte that is not part of an ANSI sequence should kept as is.

    go-colorable does not fit this because it uses ReadRune. This gives the following issues:

    • a non-UTF-8 stream will be transformed into an UTF-8 stream with non-UTF8 bytes replaced by U+FFFD
    • even an UTF-8 stream may be altered if the stream is fed through the colorable using Write calls that are not on rune boundaries

    This patch adds tests checking encoding agnosticness, and shows that NonColorable fails as transmitting Latin-1. I can go further improving this testuite to include Colorable and provide fixes once this issue is recognized as a flaw that must be fixed.

    opened by dolmen 4
  • vendorized godep workspace

    vendorized godep workspace

    Hi. I'm using go-colorable indirectly via a chain of dependencies. Following the instructions of godep - https://github.com/tools/godep/issues/131 - I declared and added the godep workspace vendorized to the project with godep save.

    opened by moret 4
  • added power support ppc64le arch on yml file.

    added power support ppc64le arch on yml file.

    Added power support for the travis.yml file with ppc64le. This is part of the Ubuntu distribution for ppc64le. This helps us simplify testing later when distributions are re-building and re-releasing. For more info tag @gerrith3.

    opened by srinivas32 0
  • Crash when using from

    Crash when using from "vagrant ssh windows"

    When using from an ssh session using vagrant into a windows, then it crashes with in "colorable_windows.go" line 507

    https://github.com/mattn/go-colorable/blob/master/colorable_windows.go#L507

    image

    image

    It does not happen all the time but feels uncomfortable to have this in prod. Steps:

    1. be on linux
    2. open terminal and vagrant ssh windows
    3. do some high intensive outputs , like animation with colors, I use the spinner as you can see from screenshots

    Something clashes there

    opened by codemodify 4
  • Go modules bug

    Go modules bug

    When trying to go get go-colorable from gopkg, I'm currently getting this message (using Go 1.12):

    go get -u gopkg.in/mattn/go-colorable.v0
    go: gopkg.in/mattn/[email protected]: go.mod has non-....v0 module path "github.com/mattn/go-colorable" at revision v0.1.1
    go get: error loading module requirements
    

    It seems to me like there is some kind of conflict between the gopkg.in/mattn/go-colorable.v0 actual package path and the name of the module declared in the go.mod file github.com/mattn/go-colorable.

    For now, forcing the use of the lib without the go.mod file in it solves the issue:

    go get -u gopkg.in/mattn/[email protected]
    go: finding gopkg.in/mattn/go-colorable.v0 v0.1.0
    go: downloading gopkg.in/mattn/go-colorable.v0 v0.1.0
    go: extracting gopkg.in/mattn/go-colorable.v0 v0.1.0
    
    opened by solher 11
  • Use in logrus

    Use in logrus

    Hey Mattn, I like this workaround for Windows. Instead of documenting it as a workaround in the README, could we use this smartly upstream without downloading the library for all platforms?

    opened by sirupsen 1
  • Enable Sourcegraph

    Enable Sourcegraph

    I want to use Sourcegraph for go-colorable code search, browsing, and usage examples. Can an admin enable Sourcegraph for this repository? Just go to https://sourcegraph.com/github.com/mattn/go-colorable. (It should only take 30 seconds.)

    Thank you!

    opened by muhqu 0
Releases(0.12.21)
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
Terminal string styling for go done right, with full and painless Windows 10 support.

GChalk GChalk is a library heavily inspired by chalk, the popular Node.js terminal color library, and using go ports of supports-color and ansi-styles

Jason Walton 307 Jul 31, 2022
go-colorable - Colorable writer for Windows

go-colorable Colorable writer for windows. For example, most of logger packages doesn't show colors on windows. (I know we can do it with ansicon. But

mattn 631 Jul 31, 2022
Package for controlling the Windows firewall (aka Windows Filtering Platform, WFP)

wf What This is a package for controlling the Windows Filtering Platform (WFP), also known as the Windows firewall. See its docs: https://godoc.org/in

inet.af 44 Aug 3, 2022
An example desktop system tray application that can launch HTML5 windows. Go source with a build process for Windows, Mac and Linux.

ExampleTrayGUI An example cross-platform (Mac, Windows, Linux) system tray application that can launch HTML5 windows, developed in Go including functi

Grant Moore 48 Jun 20, 2022
An example desktop system tray application that can launch HTML5 windows. Go source with a build process for Windows, Mac and Linux.

ExampleTrayGUI An example cross-platform (Mac, Windows, Linux) system tray application that can launch HTML5 windows, developed in Go including functi

Grant Moore 48 Jun 20, 2022
An example desktop system tray application that can launch HTML5 windows. Go source with a build process for Windows, Mac and Linux.

An example cross-platform (Mac, Windows, Linux) system tray application that can launch HTML5 windows, developed in Go including functional build process. This repository is intended as a quick reference to help others start similar projects using the referenced libraries and will not be actively maintained.

Grant Moore 48 Jun 20, 2022
An example desktop system tray application that can launch HTML5 windows. Go source with a build process for Windows, Mac and Linux.

ExampleTrayGUI An example cross-platform (Mac, Windows, Linux) system tray application that can launch HTML5 windows, developed in Go including functi

Owen Moore 48 Jun 20, 2022
W32find - Find parent windows and their children windows using win32api.

w32find Package w32find provides a set of interface to win32 APIs that can be used to find windows and their controls. Install go get -v github.com/mo

MoonChant 0 Jan 5, 2022
Highly concurrent drop-in replacement for bufio.Writer

concurrent-writer Highly concurrent drop-in replacement for bufio.Writer. concurrent.Writer implements highly concurrent buffering for an io.Writer ob

Alin Sinpalean 44 Jun 21, 2022
Time based rotating file writer

cronowriter This is a simple file writer that it writes message to the specified format path. The file path is constructed based on current date and t

Yuta UEKUSA 47 Feb 8, 2022
Rolling writer is an IO util for auto rolling write in go.

RollingWriter RollingWriter is an auto rotate io.Writer implementation. It can works well with logger. Awesome Go popular log helper New Version v2.0

Arthur Lee 239 Aug 2, 2022
Rotating File Writer

Rotating File writer An io.writer & io.Closer compliant file writer that will always write to the path that you give it, even if somebody deletes/rena

Michael Pearson 34 Jul 12, 2021
Optimized bit-level Reader and Writer for Go.

bitio Package bitio provides an optimized bit-level Reader and Writer for Go. You can use Reader.ReadBits() to read arbitrary number of bits from an i

András Belicza 192 Jul 26, 2022
A minimalist Go PDF writer in 1982 lines. Draws text, images and shapes. Helps understand the PDF format. Used in production for reports.

one-file-pdf - A minimalist PDF generator in <2K lines and 1 file The main idea behind this project was: "How small can I make a PDF generator for it

Ali Bala 444 Jul 15, 2022
gensvg generates SVG to an io.Writer

gensvg: A Go library for SVG generation The library generates SVG as defined by the Scalable Vector Graphics 1.1 Specification

Anthony Starks 17 Jan 10, 2022
Golang io.Reader and io.Writer but with limits

LimitIO io.Reader and io.Writer with limit.

LI Zhennan 68 May 11, 2022
csv reader/writer.

IO csv reader sample version 0.0.1-SNAPSHOT Goals: main: read huge file, hex substring, write to new file. cmd/v2 version can read and write use ony o

Cranes Team 2 Nov 4, 2021
csv reader/writer and csv generator.

IO csv reader sample version 0.0.1-SNAPSHOT Goals: main: read huge file, hex substring, write to new file. repo has 2 version. v1 can read a file and

Cranes Team 2 Nov 4, 2021
Simple binary reader and writer

Simple Binary Stream Reader/Writer This package contains a set of simple utility reader and writer that can be used to efficiently read/write binary i

Roman Atachiants 6 Dec 22, 2021
A drop-in replacement to any Writer type, which also calculates a hash using the provided hash type.

writehasher A drop-in replacement to any Writer type, which also calculates a hash using the provided hash type. Example package main import ( "fmt"

Max 0 Jan 10, 2022
Cheap/fast/simple XLSX file writer for textual data

xlsxwriter Cheap/fast/simple XLSX file writer for textual data -- no fancy formatting or graphs go get github.com/mzimmerman/xlsxwriter data := [][]s

Matthew Zimmerman 0 Feb 8, 2022
A node.js version management utility for Windows. Ironically written in Go.

The npm/Microsoft/Google recommended Node.js version manager for Windows. This is not the same thing as nvm. The original nvm is a completely separate

Corey Butler 22.3k Jul 29, 2022
Tiny cross-platform webview library for C/C++/Golang. Uses WebKit (Gtk/Cocoa) and Edge (Windows)

webview A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs. Also, there are Rust bindings, Python bindings, Ni

webview 10.3k Aug 6, 2022
Qt binding for Go (Golang) with support for Windows / macOS / Linux / FreeBSD / Android / iOS / Sailfish OS / Raspberry Pi / AsteroidOS / Ubuntu Touch / JavaScript / WebAssembly

Introduction Qt is a free and open-source widget toolkit for creating graphical user interfaces as well as cross-platform applications that run on var

null 9.4k Aug 8, 2022
A Windows GUI toolkit for the Go Programming Language

About Walk Walk is a "Windows Application Library Kit" for the Go Programming Language. Its primarily useful for Desktop GUI development, but there is

Alexander Neumann 6.1k Aug 4, 2022
Command-line tool and library for Windows remote command execution in Go

WinRM for Go Note: if you're looking for the winrm command-line tool, this has been splitted from this project and is available at winrm-cli This is a

Brice Figureau 369 Jul 19, 2022
A Windows named pipe implementation written in pure Go.

npipe Package npipe provides a pure Go wrapper around Windows named pipes. Windows named pipe documentation: http://msdn.microsoft.com/en-us/library/w

Nate Finch 249 Jul 27, 2022
Test your command line interfaces on windows, linux and osx and nodes viá ssh and docker

Commander Define language independent tests for your command line scripts and programs in simple yaml files. It runs on windows, osx and linux It can

null 202 Jul 3, 2022