New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/kortschak/ct

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/kortschak/ct

  • v0.0.0-20140325011614-7d86dffe6951
  • Source
  • Go
  • Socket score

Version published
Created
Source

ct

import "github.com/kortschak/ct"

Package ct provides ANSI terminal text coloring and decoration support.

type Color

type Color int

Color is a basic color list selector. Not all colors are available on all platforms.

const (
    Black Color = iota
    Red
    Green
    Yellow
    Blue
    Magenta
    Cyan
    LightGray
    Gray
    BoldRed
    BoldGreen
    BoldYellow
    BoldBlue
    BoldMagenta
    BoldCyan
    White
)

type Mode

type Mode uint64

Mode specifies terminal rendering modes via its Render method. Modes should be bitwise or'd together. Not all modes are available on all platforms.

A Mode is essentially a bit field of colors and decoration flags. The layout of a Mode is as follows:

bits 0-3    - color of foreground
bit 4       - set foreground color
bits 5-7    - color of background
bit 8       - set background color
bits 9-16   - XTerm color of foreground
bit 17      - set XTerm foreground color
bits 18-25  - XTerm color of background
bit 26      - set XTerm background color
bits 27-    - text decoration flags
highest bit - do not reset terminal after rendering

XTerm colors take priority over normal terminal colors if supported by the platform.

const (
    Reset Mode = 1 << (iota + colorBits)
    Bold
    Faint
    Italic
    Underline
    BlinkSlow
    BlinkRapid
    Negative
    Conceal
    CrossedOut
    NoResetAfter Mode = 1 << 63
)

func Bg

func Bg(c Color) Mode

Bg returns a background color Mode based on the provided Color.

func Fg

func Fg(c Color) Mode

Fg returns a foreground color Mode based on the provided Color.

func XTermBg

func XTermBg(c byte) Mode

XTermBg returns an XTerm background color Mode based on the provided XTerm color.

func XTermFg

func XTermFg(c byte) Mode

XTermFg returns an XTerm foreground color Mode based on the provided XTerm color.

func (Mode) Paint

func (m Mode) Paint(v ...interface{}) fmt.Formatter

Paint returns a fmt.Formatter that will apply the mode to the printed values of the parameters.

package main

import (
    "fmt"
    "github.com/kortschak/ct"
)

var (
    info = (ct.Fg(ct.Black) | ct.XTermFg(16) | ct.Bold).Paint
    warn = (ct.Fg(ct.White) | ct.Bg(ct.Red)).Paint
)

func main() {
    fmt.Println(warn("WARNING:"), "Danger, Will Robinson! Danger! ")
    fmt.Println(info("INFO:"), "Doctor Smith, please. You're making the Robot very unhappy!")
}

Generated by godoc2md

FAQs

Package last updated on 25 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc