Puppet Function: motd::ansi::bg

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

Summary

function to change the background colour of text

Overview

motd::ansi::bg(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/bg.pp', line 6

function motd::ansi::bg (
  String[1]          $text,
  Motd::Ansi::Colour $colour,
  Boolean            $reset = true
) >> String {
  $csi = "\u001B[" # lint:ignore:double_quoted_strings
  $colour_codes = {
    'black'   => 40,
    'red'     => 41,
    'green'   => 42,
    'yellow'  => 43,
    'blue'    => 44,
    'magenta' => 45,
    'cyan'    => 46,
    'white'   => 47,
  }
  $formated =  "${csi}${colour_codes[$colour]}m${text}"
  $reset.bool2str(motd::ansi::reset($formated), $formated)
}