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

toolman.org/terminal/decor

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

toolman.org/terminal/decor

  • v0.4.0
  • Go
  • Socket score

Version published
Created
Source

Mit License GitHub Release GoDoc Go Report Card

toolman.org/terminal/decor

Package decor provides facilities for decorating a string of characters with display attributes for the current (or specified) terminal type. This is done using a notation inspired by (but slightly different from) Zsh prompt formatting. Supported attributes are bold, italic, and/or underlined characters as well as 256-color support for foreground and background colors.

Terminal Attributes

At its basis, this package is about decorating short blurbs of text to display in a terminal. As a simple example, consider the following program:

package main

import (
	"fmt"
	"os"

	"toolman.org/terminal/decor"
)

func main() {
	d, err := decor.New()
	if err != nil {
		panic(err)
	}

	input := "[@B@F{44}@Iuser@i@F{Orchid1}@@@F{Green3}host@f@b]"
	output, err := d.Format(input)
	if err != nil {
		panic(err)
	}

	fmt.Printf("\nTERM....: %q\n\n", os.Getenv("TERM"))
	fmt.Printf("Input...: %q\n\n", input)
	fmt.Printf("Quoted..: %q\n\n", output)
	fmt.Printf("RAW.....: %s\n\n", output)
}

When executed, this emits output similar to the following:

Screenshot #1

This shows I'm using a terminal of type rxvt-256color, the input I'd like to format, a quoted representation of the formatted output for this terminal and then the output as rendered by the terminal itself.

Below is a quick-n-dirty chart that walks through each of the attribute markings used above:

Screenshot #2 Screenshot #2

FAQs

Package last updated on 05 Mar 2023

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