cpick

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

README

Cpick

1.0.0 GoDoc Go Report Card Coverage

An extensive color picker in the terminal.

color picker image


Dependencies

Cpick depends on Tcell and Colors.

Cpick also uses Cview. However, Cview currently has a feature where the table cells are drawn with a required space in between cells, which ruins the aesthetic of Cpick. In order to fix this, a forked version of Cview is used within the Cpick package that has the required fixes. This may lead to bugs and issues in older versions of Cview that are not able to be readliy fixed until Cview adopts required features.


Installation

Golang

To include the Cpick package, include the line import "gitlab.com/ethanbakerdev/cpick".

To make a command based off of the package, run go install in the cmd/cpick directory. Command usage can be found in the docs.

Arch Linux (Arch User Repository)

Visit the AUR page to download Cpick to your arch system. If you don't know how to download a package from the Arch User Repository, you can follow directions from the Arch wiki.

Ubuntu/Debian

Coming soon!


Documentation

Documentation is present using Godoc.


Features

Cpick Settings

Cpick comes with two boolean settings: sandbox and testing.

  • Sandbox

Sandbox determines whether or not Cpick will return a color. Sandbox is useful for looking at colors that will be used somewhere else, like for a website. If sandbox is set to true, Cpick will not return any value but will instead cycle between different color tables. Setting sandbox to false means a color will be returned.

  • Testing

Testing is used to test coverage and validness of Cpick without requiring user input. Testing is useful for making sure Cpick can work on your device. Setting testing to true turns on the test mode, while setting testing to false keeps cpick on normal mode.

All of the tests can be found in the tests.go file (COMING SOON).

Controls/Keys

If you are looking for a simplified version, check out the docs. Here is a more in-depth explanation.

You can also see a minified help version by pressing ` while the Cpick application is running.

In Cpick, there are two main screens: the hue screen and the saturation-value screen.

The hue screen is the first screen that pops up. It contains a hue slider present at the top, two color tint previews on the left, and a table of different preset or custom colors at the bottom.

The saturation-value screen is the screen that pops up once you press enter to select a color on the hue screen. It contains one large color gradient in the center and two color tint previews on the right.

On the hue screen, you initially start off on the hue slider. This is where you can select a specific hue by navigating the table, either using h and l (from vim) or the left and right arrow. If you press enter, you will be moved to the saturation-value screen with the table representing the hue you chose. You can also press space to move to the listed colors at the bottom of the hue screen.

For the listed color table on the hue screen, you can navigate it using the standard vim keys (h, j, k, l) or the arrow keys. If you press enter on a selected color, you will be taken to the saturation-value screen and the color you selected will automatically be selected on the big color gradient table. You can also switch between color types by pressing c to go forward a page and C to go back.

In addition, you can press ? to open up a search menu. Here you can search for a specific color or keyword. You can press N to go to the next selection and n to go to the previous selection, just like in vim.

On the saturation-value screen, you can move about the screen using the standard vim keys (h, j, k, l) or the arrow keys. Once on a desired color, press enter to select it (take note that if you ran Cpick with sanbox as true, pressing enter on the table will take you back to the hue screen).

In addition, you can press g to go to the start of the table (top-left most cell) or G to go to the end of the table (bottom-right most cell).

Custom Colors

In Cpick, you can add custom colors that can come up on the color pages. You can add json files that hold the colors in 3 ways.

  1. Local Environment

Wherever you are running Cpick, you can provide a local colors.json file (file would have the path ./colors.json from wherever cpick is being run). This has the highest priority.

  1. ~/.config Directory

In the ~/.config directory, you can create a cpick directory that can contain the colors.json file (file would have the path ~/.config/cpick/colors.json). This has a lower priority than a local file but a higher priority than a ./cpick directory..

  1. ~/.cpick Directory

In your home directory, you can create a .cpick directory that can contain the colors.json file (file would have the path ~/.cpick/colors.json). This has the lowest priority.

The colors.json has a very strict format.

{
  "colorList": [
    {
      "name": "COLOR NAME 1",
      "colors": []
    },

    {	
      "name": "COLOR NAME 2",
      "colors": []
    },

    {	
      "name": "COLOR NAME 3",
      "colors": []
    }

  ]
}

Each color type consists of an object with a name and colors key. The name key consists of what color type the colors provided are, such as CSS, Solarized, or XTERM. The colors key holds all of the colors that will be previewed when Cpick is run. All of the different color types are in the colorList array.

An individual color is an object that consists of two keys: name and value. name is the name of the color and value is the hexadecimal value of the color as a string. The "#" for the hexadecimal value is optional.

"colors": [
  {"name": "Red",   "value": "#FF0000"},
  {"name": "Green", "value": "#00FF00"},
  {"name": "Blue",  "value": "#0000FF"}
]

Cpick comes with three color types as a default: CSS, Solarized, and XTERM. In order to fix complicated import problems, the json data is present in the colors.go file as a string. The preset data always has the lowest priority for being used.


Issues, Suggestions, and Patches

For issues and suggestions, please include as much useful information is possible. Make sure the issue is actually present or the suggestion is not inculded.

For patches, please submit them as pull requests.

Documentation

Overview

Package cpick is an interactive color picker in the terminal using cview

Package cpick is a advanced color picker that can be run from the terminal.

Controls

Help screen:

  • View help screen: ~ (Press enter to exit)

For everything:

  • Movement: standard vim keys (hjkl) or arrow keys
  • Advanced movement: press g to go to the top left of the table and press G to go to the bottom right of the table.
  • Exiting the application: q or escape

For hue screen (the first one)

  • Creating a new table based on selection: enter
  • Switch between slider and preset color table: space
  • Switch between color types on preset color table: C (forward) and c (backwards)
  • Enter search menu (for preset colors): ?
  • Go to next search instance: N (forward) and n (backward)
  • Switch to saturation-value table: tab

For saturation-value screen (the second one)

  • Select your final color: enter
  • Switch to hue screen: tab

For the search screen (when you press ?)

To search for a color name, type the name of the color into the search bar. Related colors will appear below.
Once a color (or phrase) is desired, press enter. You can press N (forward) and n (reverse) to swap between instances.

Each value type you want to select will have instructions below:

	* Hexadecimal: type the hex value starting with "#" (EX: #ffffff)
	* RGB: type "rgb:" and three RGB values separated by a space (EX: rgb: 255 255 255)
	* HSV: type "hsv:" and three HSV values separated by a space (EX: hsv: 0 100 0)
	* HSL: type "hsl:" and three HSL values separated by a space (EX: hsl: 0 100 50)
	* CMYK: type "cmyk:" and four CMYK values separated by a space (EX: cmyk: 0 0 0 0)
	* Decimal: type "decimal:" and then the decimal value (EX: 16777215)

Once a color is selected, you will be taken to the Saturation-Value table with the specified color selected.

Any errors that you make will appear in red below the search bar.

Return values

Cpick will return a struct (type ReturnValues) that contains all of the following
values:

* RGB
* HSV
* HSL
* CMYK
* Hex
* Decimal
* Ansi
* Name

RGB, HSV, HSL, CMYK, Hex, Decimal, and Ansi all come from the colors package (gitlab.com/ethanbakerdev/colors).

Name will only be returned if you select a value from the preset color table. Name will be "Custom color" if no preset color is selected.

"Hello World"

An example to start cpick in "normal" mode: cpick.Start(false, false)

Command Usage:

A cpick bash command can be installed by running `go install` in the cmd/cpick/ directory.

Cpick manual:

NAME

cpick - Color picker in the terminal

SYNOPSIS

cpick [TYPE] [OPTION]

DESCRIPTION

Bring up an extensive color picker to select and return many different colors in
various color types.

TYPES

Types: [rgb|hsv|hsl|cmyk|hex|decimal|ansi|escape|name|json|bash [NAME]|css [TAG]]

Default: ansi

Multiple types will result in the first type entered selected to return. For
example, running `cpick rgb ansi` will return rgb values.

rgb: Return rgb values separated by a semi-colon (EX: 255;127;0)

hsv: Return hsv values separated by a semi-colon (EX: 60;100;100)

hsl: Return hsl values separated by a semi-colon (EX: 60;100;50)

cmyk: Return cmyk values separated by a semi-colon (EX: 60;100;50)

hex: Return a hex value with the "#" (EX: #ffff00)

decimal: Return a deciaml value (EX: 13842970)

ansi: Return the value of an ansi escape code (this will be represented as a color)

escape: Return the ansi escape code (EX: \033[38;2;255;127;0m)

name: Return the name of the color (if there is one)

json: Return a json object containing all of the color info

css: Return a css line containing a certain tag with the specified color in
hexadecimal format. Css takes another keyword, [TAG], which is the specified css
tag that will be outputted. By default, [TAG]="color".

bash: Return a declare statement with the color constant as an ansi escape code.
Bash takes another keyword, [NAME], that is used as the name of the declaration
statement. By default, [NAME]="custom".

OPTIONS

-s, -sandbox
		Run Cpick in sandbox mode. No color will be returned

-t, -testing
		Run cpick in testing mode. No GUI will be shown, only functions will be tested

Package cpick is an interactive color picker in the terminal using cview

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColorValues

type ColorValues struct {
	RGB     color.RGB
	HSV     color.HSV
	HSL     color.HSL
	CMYK    color.CMYK
	Hex     color.Hex
	Decimal color.Decimal
	Ansi    color.Ansi
	Name    string
}

ColorValues type used to hold color values and optional name

func Start

func Start(sandbox bool, testing bool) (ColorValues, error)

Start function starts the cpick application. Sandbox (bool) determines whether or not cpick will return a color once selected on the Saturation-Value table (sandbox = false) or go back to the first screen (sandbox = true). Testing (bool) is used to test all of the functions to make sure they can run properly without a need for user input (testing = true).

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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