iris-0.1.0.0: Haskell CLI framework
Copyright2022 Dmitrii Kovanikov
LicenseMPL-2.0
MaintainerDmitrii Kovanikov <kovanikov@gmail.com>
StabilityExperimental
PortabilityPortable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Iris.Colour.Mode

Contents

Description

The ColourMode data type that allows disabling and enabling of colouring.

Since: 0.0.0.0

Synopsis

Documentation

data ColourMode Source #

Data type that tells whether the colouring is enabled or disabled. Its value is detected automatically on application start and stored in CliEnv.

Since: 0.0.0.0

Constructors

DisableColour

Since: 0.0.0.0

EnableColour

Since: 0.0.0.0

detectColourMode Source #

Arguments

:: Handle

A terminal handle (e.g. stderr)

-> ColourOption

User settings

-> Maybe String

Application name

-> IO ColourMode 

This function performs a full check of the Handle colouring support, env variables and user-specified settings to detect whether the given handle supports colouring.

Per CLI Guidelines, the algorithm for detecting the colouring support is the following:

__Disable color if your program is not in a terminal or the user requested it. These things should disable colors:__

  • stdout or stderr is not an interactive terminal (a TTY). It’s best to individually check—if you’re piping stdout to another program, it’s still useful to get colors on stderr.
  • The NO_COLOR environment variable is set.
  • The TERM environment variable has the value dumb.
  • The user passes the option --no-color.
  • You may also want to add a MYAPP_NO_COLOR environment variable in case users want to disable color specifically for your program.

ℹ️ Iris performs this check on the application start automatically so you don't need to call this function manually.

Since: 0.1.0.0

Internal

handleColourMode :: Handle -> IO ColourMode Source #

Returns ColourMode of a Handle ignoring environment and CLI options. You can use this function on output Handles to find out whether they support colouring or not.

Use a function like this to check whether you can print with colour to terminal:

handleColourMode stdout

Since: 0.0.0.0