Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

git.sr.ht/~rj/sgr

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git.sr.ht/~rj/sgr

  • v1.16.2
  • Go
  • Socket score

Version published
Created
Source

Package sgr

Go Reference Go Report Card builds.sr.ht status Coverage badge Version badge

Package sgr provides formatters to write ANSI escape sequences that can format and colorize text.

Banner image

  • Coverage of the Select Graphic Rendition (SGR) section of the ANSI escape sequences.
  • Statically typed API avoids the use of untyped or embedded formatting strings.
  • Automatic mapping to lower bit-width colours, when necessary, to match the terminal's support
  • Performance aware API.
  • Compatible with using io.Writer and the standard library.

Install

The package can be installed from the command line using the go tool. There are no dependencies beyond the standard library. Any version of Go should work.

go get git.sr.ht/~rj/sgr

Getting Started

Package documentation and examples are on Go Reference.

As a small introduction, the following snippet prints to the console using some bold text. You can experiment with the snippet on the go playground.

func main() {
	// The formatter is responsible for deciding when and what escape
	// codes to use.  The call to NewFormatter will return a formatter
	// suitable for use with standard out.
	f := sgr.NewFormatter()

	// Print some text with bold.
	fmt.Println("Hello,", f.Bold("world!"))
}

Contribute

To submit bug reports and suggestions, please use the issue tracker.

Discussions occur using the mailing list. The mailing list can also be used to submit patches.

Scope

This packages does not aim to support a complete list of SGR escape codes, either for all possible terminals or even as defined in the standard. The supported codes should be widely portable across many terminals and operating systems.

Windows: Terminals on windows will increasingly support ANSI escape sequences, but current support may be uneven. The legacy API for setting text attributes has been, if not deprecated, discouraged. Therefore, direct support for the legacy API is not planned. If older terminials must be supported, then go-colorable can be used.

License

BSD (c) Robert Johnstone

FAQs

Package last updated on 02 Oct 2024

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