Puppet Function: motd::ansi::attr

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

Summary

function to wrap a string in ansi colour formating

Overview

motd::ansi::attr(String[1] $text, Motd::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 (Motd::Ansi::Formating)

Returns:

  • (String)


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

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