termtab-0.1.0.0: TUI guitar tablature and score editor
Safe HaskellNone
LanguageGHC2021

Termtab.Graphics.TermColor

Description

Query the terminal's foreground color so rasterized notation can be drawn in the user's theme color instead of a hardcoded one.

A terminal graphics image is raw pixels and cannot inherit terminal color attributes the way text cells do. To make the notation "use the terminal's text color" we ask the terminal for its foreground RGB via the OSC 10 query (ESC ] 10 ; ? BEL) and paint the ink with the reply. If the terminal does not answer (or stdin/stdout is not a TTY), we fall back to a neutral light ink.

Synopsis

Documentation

queryForegroundColor :: IO (Maybe (Word8, Word8, Word8)) Source #

Query the terminal foreground color via OSC 10. Returns Nothing if stdin/stdout is not a terminal or no reply arrives in time.

foregroundOrDefault :: IO PixelRGBA8 Source #

The terminal foreground as opaque ink, or defaultInk if unavailable.

defaultInk :: PixelRGBA8 Source #

Ink used when the terminal foreground can't be determined: opaque light gray, legible on a dark background.

parseOSCColor :: String -> Maybe (Word8, Word8, Word8) Source #

Parse an OSC 10 color reply, e.g. ESC]10;rgb:eaeaebebf0f0 BEL, into an 8-bit RGB triple. Each hex group may be 1-4 digits and is scaled to 0-255.