Puppet Function: motd::ansi::fg

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

Summary

function to change the forground colour of text

Overview

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

SPDX-License-Identifier: Apache-2.0

Parameters:

  • text (String[1])

    the text to wrap

  • colour (Motd::Ansi::Colour)

    the colour to use

  • reset (Boolean) (defaults to: true)

    if true terminate text with the reset string

Returns:

  • (String)


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

function motd::ansi::fg (
  String[1]            $text,
  Motd::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(motd::ansi::reset($formated), $formated)
}