supportscolor

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 20, 2019 License: MIT Imports: 3 Imported by: 0

README

supports-color

Features

This package provides a simple interface to query the level of support found in a given terminal.

  • Respects the --color flags, and additional colour specifications.
  • Handles TTY / Cygwin colour levels
  • Supports popular CI pipelines like TravisCI & CircleCI.

Roadmap

  • Check popular terminal support schemes (urvxt, xterm-256colour flag, etc.)
  • Proper unit tests (if possible)
  • Remove external dependency

Usage


import supportscolour

func main() {
    col := supportscolour.GetSupportLevel()
    if col.Has1m {
        // do something with truecolour
    } else if col.Has256 {
        // do something with 256 colours
    } else {
        // print out standard 16 colours.
    }
}

Install

go get -u github.com/johnaoss/supports-color

Contributing

Due to the nature of this problem, pull requests are appreciated if you find a terminal in which the data reported is inaccurate. I've currently only had access to a iTerm2 terminal, and as such I've only been able to test on the single platform.

License

This is licensed with the MIT License, and is found in the LICENSE file.

Thanks

Very much directly inspired by the npm module of the same name: github.com/chalk/supports-color !

Documentation

Overview

Package supportscolor provides information on the level of color support found in a given terminal, obeying OS-specific color flags. Testing currently has been done via. iTerm2 manual testing.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ForcedColor determines if there are flags in place forcing color.
	// This should never really change during the lifetime of a given program.
	ForcedColor *bool
)

Functions

This section is empty.

Types

type ColorSupport

type ColorSupport struct {
	Level    int
	HasBasic bool
	Has256   bool
	Has1m    bool
}

ColorSupport represents the given colors the terminal supports.

func GetSupportLevel

func GetSupportLevel() *ColorSupport

GetSupportLevel returns a struct containing whether or not certain color sizes are supported in a given terminal.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL