github.com/AlpineAIO/wails/v2@v2.0.0-beta.32.0.20240505041856-1047a8fa5fef/internal/colour/colour.go (about)

     1  package colour
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/wzshiming/ctc"
     8  )
     9  
    10  var ColourEnabled = true
    11  
    12  func Col(col ctc.Color, text string) string {
    13  	if !ColourEnabled {
    14  		return text
    15  	}
    16  	return fmt.Sprintf("%s%s%s", col, text, ctc.Reset)
    17  }
    18  
    19  func Yellow(text string) string {
    20  	if !ColourEnabled {
    21  		return text
    22  	}
    23  	return Col(ctc.ForegroundBrightYellow, text)
    24  }
    25  
    26  func Red(text string) string {
    27  	if !ColourEnabled {
    28  		return text
    29  	}
    30  	return Col(ctc.ForegroundBrightRed, text)
    31  }
    32  
    33  func Blue(text string) string {
    34  	if !ColourEnabled {
    35  		return text
    36  	}
    37  	return Col(ctc.ForegroundBrightBlue, text)
    38  }
    39  
    40  func Green(text string) string {
    41  	if !ColourEnabled {
    42  		return text
    43  	}
    44  	return Col(ctc.ForegroundBrightGreen, text)
    45  }
    46  
    47  func Cyan(text string) string {
    48  	if !ColourEnabled {
    49  		return text
    50  	}
    51  	return Col(ctc.ForegroundBrightCyan, text)
    52  }
    53  
    54  func Magenta(text string) string {
    55  	if !ColourEnabled {
    56  		return text
    57  	}
    58  	return Col(ctc.ForegroundBrightMagenta, text)
    59  }
    60  
    61  func White(text string) string {
    62  	if !ColourEnabled {
    63  		return text
    64  	}
    65  	return Col(ctc.ForegroundBrightWhite, text)
    66  }
    67  
    68  func Black(text string) string {
    69  	if !ColourEnabled {
    70  		return text
    71  	}
    72  	return Col(ctc.ForegroundBrightBlack, text)
    73  }
    74  
    75  func DarkYellow(text string) string {
    76  	if !ColourEnabled {
    77  		return text
    78  	}
    79  	return Col(ctc.ForegroundYellow, text)
    80  }
    81  
    82  func DarkRed(text string) string {
    83  	if !ColourEnabled {
    84  		return text
    85  	}
    86  	return Col(ctc.ForegroundRed, text)
    87  }
    88  
    89  func DarkBlue(text string) string {
    90  	if !ColourEnabled {
    91  		return text
    92  	}
    93  	return Col(ctc.ForegroundBlue, text)
    94  }
    95  
    96  func DarkGreen(text string) string {
    97  	if !ColourEnabled {
    98  		return text
    99  	}
   100  	return Col(ctc.ForegroundGreen, text)
   101  }
   102  
   103  func DarkCyan(text string) string {
   104  	if !ColourEnabled {
   105  		return text
   106  	}
   107  	return Col(ctc.ForegroundCyan, text)
   108  }
   109  
   110  func DarkMagenta(text string) string {
   111  	if !ColourEnabled {
   112  		return text
   113  	}
   114  	return Col(ctc.ForegroundMagenta, text)
   115  }
   116  
   117  func DarkWhite(text string) string {
   118  	if !ColourEnabled {
   119  		return text
   120  	}
   121  	return Col(ctc.ForegroundWhite, text)
   122  }
   123  
   124  func DarkBlack(text string) string {
   125  	if !ColourEnabled {
   126  		return text
   127  	}
   128  	return Col(ctc.ForegroundBlack, text)
   129  }
   130  
   131  var rainbowCols = []func(string) string{Red, Yellow, Green, Cyan, Blue, Magenta}
   132  
   133  func Rainbow(text string) string {
   134  	if !ColourEnabled {
   135  		return text
   136  	}
   137  	var builder strings.Builder
   138  
   139  	for i := 0; i < len(text); i++ {
   140  		fn := rainbowCols[i%len(rainbowCols)]
   141  		builder.WriteString(fn(text[i : i+1]))
   142  	}
   143  
   144  	return builder.String()
   145  }