File Coverage

lib/Wireguard/WGmeta/Cli/TerminalHelpers.pm
Criterion Covered Total %
statement 27 36 75.0
branch 5 14 35.7
condition n/a
subroutine 9 10 90.0
pod 0 1 0.0
total 41 61 67.2


line stmt bran cond sub pod time code
1             package Wireguard::WGmeta::Cli::TerminalHelpers;
2 1     1   7 use strict;
  1         2  
  1         30  
3 1     1   14 use warnings FATAL => 'all';
  1         3  
  1         32  
4 1     1   5 use experimental 'signatures';
  1         2  
  1         5  
5 1     1   85 use base 'Exporter';
  1         2  
  1         146  
6             our @EXPORT = qw(prettify_message BOLD RESET GREEN RED YELLOW);
7              
8 1 50   1   7 use constant BOLD => (!defined($ENV{'WG_NO_COLOR'})) ? "\e[1m" : "";
  1         2  
  1         93  
9 1 50   1   7 use constant RESET => (!defined($ENV{'WG_NO_COLOR'})) ? "\e[0m" : "";
  1         2  
  1         76  
10 1 50   1   7 use constant GREEN => (!defined($ENV{'WG_NO_COLOR'})) ? "\e[32m" : "";
  1         2  
  1         91  
11 1 50   1   7 use constant RED => (!defined($ENV{'WG_NO_COLOR'})) ? "\e[31m" : "";
  1         10  
  1         71  
12 1 50   1   7 use constant YELLOW => (!defined($ENV{'WG_NO_COLOR'})) ? "\e[33m" : "";
  1         2  
  1         191  
13              
14 0     0 0   sub prettify_message($error, $is_warning) {
  0            
  0            
  0            
15 0 0         $error =~ s/at.*$//g unless (defined $ENV{IS_TESTING});
16 0 0         if ($is_warning == 1) {
17 0           print BOLD . YELLOW . "Warning: " . RESET . $error;
18 0           return;
19             }
20 0           print BOLD . RED . "Error: " . RESET . $error;
21             }
22              
23             1;