Puppet Function: wmflib::ansi::fg

Defined in:
modules/wmflib/functions/ansi/fg.pp
Function type:
Puppet Language

Summary

function to change the forground colour of text

Overview

wmflib::ansi::fg(String[1] $text, Wmflib::Ansi::Colour $colour, Boolean $reset = true)String

SPDX-License-Identifier: Apache-2.0

Parameters:

  • text (String[1])

    the text to wrap

  • colour (Wmflib::Ansi::Colour)

    the colour to use

  • reset (Boolean) (defaults to: true)

    if true terminate text with the reset string

Returns:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'modules/wmflib/functions/ansi/fg.pp', line 6

function wmflib::ansi::fg (
    String[1]            $text,
    Wmflib::Ansi::Colour $colour,
    Boolean              $reset = true
) >> String {
    $csi = "\u001B[" # lint:ignore:double_quoted_strings
    $colour_codes = {
        'black'   => 30,
        'red'     => 31,
        'green'   => 32,
        'yellow'  => 33,
        'blue'    => 34,
        'magenta' => 35,
        'cyan'    => 36,
        'white'   => 37,
    }
    $formated =  "${csi}${colour_codes[$colour]}m${text}"
    $reset.bool2str(wmflib::ansi::reset($formated), $formated)
}