Puppet Function: wmflib::ansi::attr

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

Summary

function to wrap a string in ansi colour formating

Overview

wmflib::ansi::attr(String[1] $text, Wmflib::Ansi::Formating $format, Boolean $reset = true)String

SPDX-License-Identifier: Apache-2.0

Parameters:

  • text (String[1])

    the text to wrap

  • formating

    any formating to add e.g. bold, underlined

  • reset (Boolean) (defaults to: true)

    if true terminate text with the reset string

  • format (Wmflib::Ansi::Formating)

Returns:



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

function wmflib::ansi::attr (
    String[1]               $text,
    Wmflib::Ansi::Formating $format,
    Boolean                 $reset = true
) >> String {
    $csi = "\u001B[" # lint:ignore:double_quoted_strings
    $format_codes = {
        'normal'     => 0,
        'bold'       => 1,
        'underlined' => 4,
        'blinking'   => 5,
        'reverse'    => 7,
    }
    $formated = "${csi}${format_codes[$format]}m${text}"
    $reset.bool2str(wmflib::ansi::reset($formated), $formated)
}