soft/xcolor

Lightweight color picker for X11

Building and running xcolor requires Xlib libraries to be present

xcolor 🌈

Lightweight color picker for X11. Use mouse to select colors visible anywhere on the screen to get their RGB representation.

Installation

Using Cargo

xcolor can be installed using cargo:

Building and running xcolor requires xcb and Xlib libraries to be present.

To get the latest development version of xcolor, you can direct cargo to install from the git repository:

Installing xcolor with cargo will not install its manual page or desktop file. To also install these additional files, invoke make install in the project directory. By default, the install script will place the files under /usr/local/ hierarchy.

Arch Linux

xcolor is available in the Arch Linux community repository. To install it with pacman:

Usage

Simply invoke the xcolor command to select a color. The selected color will be printed to the standard output.

Saving to Selection

By default, the selected color is printed to the standard output. By specifying the -s flag, xcolor can be instructed to instead save the color to X11's selection. The selection to use can be specified as an argument. Possible selection values are clipboard (the default), primary, and secondary.

Because of the way selections work in X11, xcolor forks into background when -s mode is used. This behavior can be disabled by defining XCOLOR_FOREGROUND environment variable.

Color Preview

The -S or --scale flag controls the upscaling (or zoom) of the preview. By default it is set to 8 which indicates an 8x zoom level.

The -P or --preview-size flag controls the size of the preview in pixels. So that the preview always has a center pixel this number must be odd, if an even number is passed then it will be changed to the next odd number.

Formatting

By default, the color values will be printed in lowercase hexadecimal format. The output format can be changed using the -f NAME switch. Supported format names are listed below:

Format Specifier Description Example Custom Format Equivalent
hex Lowercase hexadecimal (default) #ff00ff #%{02hr}%{02hg}%{02hb}
HEX Uppercase hexadecimal #00FF00 #%{02Hr}%{02Hg}%{02Hb}
hex! Compact lowercase hexadecimal1 #fff Not expressible
HEX! Compact uppercase hexadecimal1 #F0F Not expressible
rgb Decimal RGB rgb(255, 255, 255) rgb(%{r}, %{g}, %{b})
plain Decimal with semicolon separators 0;0;0 %{r};%{g};%{b}

1: The compact form refers to CSS three-letter color codes as specified by CSS Color Module Level 3. If the color is not expressible in three-letter form, the regular six-letter form will be used.

Custom Formats

The -f switch provides quick access to some commonly used formatting options. However, if custom output formatting is desired, this can be achieved using the -c FORMAT switch. The FORMAT parameter specifies a template for the output and supports a simple template language.

FORMAT templates can contain special expansions that are written inside %{...} blocks. These blocks will be expanded into color values according to the specifiers defined inside the block. Here are some examples of valid format strings and what they might translate to:

Format String Example Output
%{r}, %{g}, %{b} 255, 0, 100
Green: %{-4g} Green: ---7
#%{02hr}%{02hg}%{02hb} #00ff00
%{016Br} 0000000000000011

Expansion blocks in format strings always contain a channel specifier (r for red, g for green, and b for blue). Additionally, they can contain an optional number format specifier (h for lowercase hexadecimal, H for uppercase hexadecimal, o for octal, B for binary, and d for decimal) and an optional padding specifier consisting of a character to use for padding and the length the string should be padded to. We can use these rules to decode the above example string:

In the output, we get the contents of the red color channel formatted in binary and padded with zeroes to be sixteen characters long.

Issues

Bugs & Issues should be reported at GitHub.

Issues

Collection of the latest Issues

N-R-K

N-R-K

Comment Icon0

Hi,

I see my cpu constantly staying at ~50% and spiking to ~60% on occasion when moving the cursor around with xcolor. Don't believe such high cpu usage should be necessary for whats being done.

infmagic2047

infmagic2047

Comment Icon0

If I left-click while moving the mouse (especially when moving fast), sometimes xcolor does not catch the left-click, and instead keep running as if there were no clicks.

My preliminary debugging shows that, in wait_for_location function, there are indeed no left-click event received when this happens. Maybe the event is somehow lost when there are too many events (the mouse moving) to handle.

Barbaross93

Barbaross93

Comment Icon1

Just a minor request; would it be possible to add a right click to cancel xcolor? Often times I find myself using xcolor just for the (pixel perfect) zoom.

Soft

Soft

Comment Icon0

It would be really cool to better test xcolor in the CI. Currently, we only have unit tests for the parsing code but do not test X11 related code.

We could use Xorg with dummy output to test various features, check that colors can be selected and they are the correct colors and so on.

Soft

Soft

Comment Icon0

Currently, the save to selection functionality does not support very large data transfers. This is likely not too critical for xcolor's use case as color representations tend to be small but could in theory be a problem when using a custom template.

Versions

Find the latest versions by id

0.5.1 - Sep 07, 2021

  • Upgrade nom to version 7

0.5.0 - Aug 17, 2021

This release includes the following changes:

  • New and improved magnifier view
  • Updated dependencies
  • Miscellaneous bug fixes and improvements

0.4.0 - Apr 09, 2018

This release introduces a live preview functionality that continuously displays the color under the cursor.

0.3.1 - Mar 31, 2018

Include man page

0.3.0 - Mar 25, 2018

Added support for formatting output as three-letter CSS color codes and for saving the output to X11 selection.

0.2.0 - Mar 21, 2018

Information - Updated Aug 01, 2022

Stars: 352
Forks: 16
Issues: 14

Repositories & Extras

A dead simple ANSI terminal color painting library for Rust

See the ansi_term, term_painter, to name a few), begging the question: why yet another? Here

A dead simple ANSI terminal color painting library for Rust

a tool to analyze file system usage written in Rust

coloured output, according to the LS_COLORS environment variable

a tool to analyze file system usage written in Rust

Rust VEML6040 RGBW Color Sensor Driver

This is a platform agnostic Rust driver for the VEML6040 RGBW color light

Rust VEML6040 RGBW Color Sensor Driver

A Gameboy Color (GBC) emulator written in Rust

There are two types of tests:

A Gameboy Color (GBC) emulator written in Rust

A rust library for colorizing tracing_error::SpanTrace objects in the style

A rust library for colorizing color-backtrace

A rust library for colorizing tracing_error::SpanTrace objects in the style

Mizu is an accurate Gameboy emulator built in Rust

Emulating The original gameboy (DMG) and gameboy color hardware

Mizu is an accurate Gameboy emulator built in Rust

Simple Game Boy (Color) emulator written in Rust

rustboycolor Rust stable branch

Simple Game Boy (Color) emulator written in Rust
Facebook Instagram Twitter GitHub Dribbble
Privacy