shue

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: GPL-3.0 Imports: 11 Imported by: 0

README

Shue

A command line tool for modifying and converting colour values for use with CSS etc.

Installing

brew install stilvoid/tools/shue

or

Download a binary from the releases page.

or

Run go install github.com/stilvoid/shue@latest

Usage

The following formats can be read and output by shue:

  Name    Example
  ---     ---
  hex3    #123
  hex4    #1234
  hex6    #123456
  hex8    #12345678
  rgb     rgb(12, 34, 56)
  rgba    rgba(12, 45, 56, 0.7)
  hsl     hsl(180, 25%, 50%)
  hsla    hsla(180, 25%, 50%, 0.75)

If the input format contains an alpha value (hex4,hex8,rgba,hsla)
but the output format does not (hex3,hex6,rgb,hsl)
then shue will pre-multiply the colour before outputting.

Shue can lighten a colour by specifying --lighten with a value 100+
or darken a colour by specifying a value below 100.

If you specify --lighten and --invert, inversion takes place _after_ lightening

Usage:
  shue COLOUR [flags]

Examples:
  shue -f rgb 112233
  shue -f rgb "rgba(12,34,45,0.67)"
  shue -i "#ff0000"
  shue -l 150 "hsl(120, 100%, 50%)"

Flags:
  -f, --format string   Output format. See --help for details (default "all")
  -h, --help            help for shue
  -i, --invert          Invert the colour value - lighten is applied first
  -l, --lighten int     Percentage by which to adjust the brightness (default 100)
  -v, --version         version for shue

Documentation

Overview

Example (No_change)
package main

import (
	"fmt"

	"github.com/stilvoid/shue"
)

func exec(input string, format string, lighten int, invert bool) {
	c, _ := shue.Parse(input)

	c.Lighten(lighten)

	if invert {
		c.Invert()
	}

	out, _ := shue.Format(format, c)

	fmt.Println(out)
}

func main() {
	exec("123", "hex3", 100, false)
	exec("1234", "hex4", 100, false)
	exec("123456", "hex6", 100, false)
	exec("12345678", "hex8", 100, false)
	exec("rgb(32,64,128)", "rgb", 100, false)
	exec("rgba(32,64,128,0.125)", "rgba", 100, false)
	exec("hsl(120,50%,66%)", "hsl", 100, false)
	exec("hsla(120,50%,66%,0.1)", "hsla", 100, false)

}
Output:

#123
#1234
#123456
#12345678
rgb(32, 64, 128)
rgba(32, 64, 128, 0.125)
hsl(120, 50%, 66%)
hsla(120, 50%, 66%, 0.1)

Index

Examples

Constants

This section is empty.

Variables

View Source
var Formats []string

Functions

func Format

func Format(format string, colour Colour) (string, error)

Types

type Colour

type Colour struct {
	R, G, B, A float64
}

func Parse

func Parse(input string) (Colour, error)

func (*Colour) Equal

func (c *Colour) Equal(other Colour) bool

func (*Colour) HSL

func (c *Colour) HSL() (float64, float64, float64)

HSL returns pre-multiplied HSL values 0..1

func (*Colour) HSLA

func (c *Colour) HSLA() (float64, float64, float64, float64)

HSL returns non-pre-multiplied HSL values 0..1

func (*Colour) Invert

func (c *Colour) Invert()
Example
package main

import (
	"fmt"

	"github.com/stilvoid/shue"
)

func exec(input string, format string, lighten int, invert bool) {
	c, _ := shue.Parse(input)

	c.Lighten(lighten)

	if invert {
		c.Invert()
	}

	out, _ := shue.Format(format, c)

	fmt.Println(out)
}

func main() {
	exec("fff", "hex6", 100, true)
	exec("000", "hex6", 100, true)
	exec("0180f0", "hex6", 100, true)

}
Output:

#000000
#ffffff
#fe7f0f

func (*Colour) Lighten

func (c *Colour) Lighten(value int)
Example (And_invert)
package main

import (
	"fmt"

	"github.com/stilvoid/shue"
)

func exec(input string, format string, lighten int, invert bool) {
	c, _ := shue.Parse(input)

	c.Lighten(lighten)

	if invert {
		c.Invert()
	}

	out, _ := shue.Format(format, c)

	fmt.Println(out)
}

func main() {
	exec("888", "hex6", 150, true)
	exec("444", "hex6", 200, true)
	exec("fff", "hex6", 20, true)

}
Output:

#333333
#777777
#cccccc
Example (Darker)
package main

import (
	"fmt"

	"github.com/stilvoid/shue"
)

func exec(input string, format string, lighten int, invert bool) {
	c, _ := shue.Parse(input)

	c.Lighten(lighten)

	if invert {
		c.Invert()
	}

	out, _ := shue.Format(format, c)

	fmt.Println(out)
}

func main() {
	exec("000", "hex6", 50, false)
	exec("fff", "hex6", 50, false)
	exec("808080", "hex6", 50, false)
	exec("ff8060", "hex6", 50, false)

}
Output:

#000000
#808080
#404040
#b02300
Example (Lighter)
package main

import (
	"fmt"

	"github.com/stilvoid/shue"
)

func exec(input string, format string, lighten int, invert bool) {
	c, _ := shue.Parse(input)

	c.Lighten(lighten)

	if invert {
		c.Invert()
	}

	out, _ := shue.Format(format, c)

	fmt.Println(out)
}

func main() {
	exec("000", "hex6", 150, false)
	exec("fff", "hex6", 150, false)
	exec("808080", "hex6", 150, false)
	exec("804020", "hex6", 150, false)

}
Output:

#000000
#ffffff
#c0c0c0
#c06030

func (*Colour) RGB

func (c *Colour) RGB() (float64, float64, float64)

RGB returns pre-multiplied RGB values 0..1

func (*Colour) RGBA

func (c *Colour) RGBA() (float64, float64, float64, float64)

RGBA returns non-pre-multiplied RGBA values 0..1

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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