gitee.com/sy_183/go-common@v1.0.5-0.20231205030221-958cfe129b47/sgr/cache.go (about)

     1  package sgr
     2  
     3  import "strings"
     4  
     5  var (
     6  	// BoldFlag                 = 8
     7  	// FaintFlag                = 9
     8  	// ItalicFlag               = 10
     9  	// FrakturFlag              = 11
    10  	// ReversedFlag             = 12
    11  	// NormalIntensityFlag      = 13
    12  	// NotItalicBlackLetterFlag = 14
    13  	// NotReversedFlag          = 15
    14  	cacheTable1 [256]string
    15  
    16  	// UnderlineFlag        = 16
    17  	// DoublyUnderlinedFlag = 17
    18  	// SlowBlinkFlag        = 18
    19  	// RapidBlinkFlag       = 19
    20  	// OverlinedFlag        = 20
    21  	// NotUnderlinedFlag    = 21
    22  	// NotBlinkingFlag      = 22
    23  	// NotOverlinedFlag     = 23
    24  	cacheTable2 [256]string
    25  
    26  	// ConcealFlag                    = 24
    27  	// CrossedOutFlag                 = 25
    28  	// DisableProportionalSpacingFlag = 26
    29  	// RevealFlag                     = 27
    30  	// NotCrossedOutFlag              = 28
    31  	// ProportionalSpacingFlag        = 29
    32  	cacheTable3 [256]string
    33  
    34  	// FramedFlag                  = 32
    35  	// EncircledFlag               = 33
    36  	// SuperscriptFlag             = 34
    37  	// SubscriptFlag               = 35
    38  	// NotFramedEncircledFlag      = 36
    39  	// NotSuperscriptSubscriptFlag = 37
    40  	cacheTable4 [256]string
    41  
    42  	// IdeogramUnderlineFlag       = 40
    43  	// IdeogramDoubleUnderlineFlag = 41
    44  	// IdeogramOverlineFlag        = 42
    45  	// IdeogramDoubleOverlineFlag  = 43
    46  	// IdeogramStressMarkingFlag   = 44
    47  	// NoIdeogramAttributesFlag    = 45
    48  	cacheTable5 [256]string
    49  )
    50  
    51  func initCacheTable1() {
    52  	for i := 0; i < 256; i++ {
    53  		var flags1S []string
    54  		if i&0b00100000 != 0 {
    55  			flags1S = append(flags1S, NormalIntensityCode)
    56  		} else if i&0b00000001 != 0 {
    57  			flags1S = append(flags1S, BoldCode)
    58  		} else if i&0b00000010 != 0 {
    59  			flags1S = append(flags1S, FaintCode)
    60  		}
    61  		if i&0b01000000 != 0 {
    62  			flags1S = append(flags1S, NotItalicBlackLetterCode)
    63  		} else if i&0b00000100 != 0 {
    64  			flags1S = append(flags1S, ItalicCode)
    65  		} else if i&0b00001000 != 0 {
    66  			flags1S = append(flags1S, FrakturCode)
    67  		}
    68  		if i&0b10000000 != 0 {
    69  			flags1S = append(flags1S, NotReversedCode)
    70  		} else if i&0b00010000 != 0 {
    71  			flags1S = append(flags1S, ReversedCode)
    72  		}
    73  		cacheTable1[i] = strings.Join(flags1S, ";")
    74  	}
    75  }
    76  
    77  func initCacheTable2() {
    78  	for i := 0; i < 256; i++ {
    79  		var flags2S []string
    80  		if i&0b00100000 != 0 {
    81  			flags2S = append(flags2S, NotUnderlinedCode)
    82  		} else if i&0b00000001 != 0 {
    83  			flags2S = append(flags2S, UnderlineCode)
    84  		} else if i&0b00000010 != 0 {
    85  			flags2S = append(flags2S, DoublyUnderlinedCode)
    86  		}
    87  		if i&0b01000000 != 0 {
    88  			flags2S = append(flags2S, NotBlinkingCode)
    89  		} else if i&0b00000100 != 0 {
    90  			flags2S = append(flags2S, SlowBlinkCode)
    91  		} else if i&0b00001000 != 0 {
    92  			flags2S = append(flags2S, RapidBlinkCode)
    93  		}
    94  		if i&0b10000000 != 0 {
    95  			flags2S = append(flags2S, NotOverlinedCode)
    96  		} else if i&0b00010000 != 0 {
    97  			flags2S = append(flags2S, OverlinedCode)
    98  		}
    99  		cacheTable2[i] = strings.Join(flags2S, ";")
   100  	}
   101  }
   102  
   103  func initCacheTable3() {
   104  	for i := 0; i < 256; i++ {
   105  		var flags3S []string
   106  		if i&0b00001000 != 0 {
   107  			flags3S = append(flags3S, RevealCode)
   108  		} else if i&0b00000001 != 0 {
   109  			flags3S = append(flags3S, ConcealCode)
   110  		}
   111  		if i&0b00010000 != 0 {
   112  			flags3S = append(flags3S, NotCrossedOutCode)
   113  		} else if i&0b00000010 != 0 {
   114  			flags3S = append(flags3S, CrossedOutCode)
   115  		}
   116  		if i&0b00100000 != 0 {
   117  			flags3S = append(flags3S, DisableProportionalSpacingCode)
   118  		} else if i&0b00000100 != 0 {
   119  			flags3S = append(flags3S, ProportionalSpacingCode)
   120  		}
   121  		cacheTable3[i] = strings.Join(flags3S, ";")
   122  	}
   123  }
   124  
   125  func initCacheTable4() {
   126  	for i := 0; i < 256; i++ {
   127  		var flags4S []string
   128  		if i&0b00010000 != 0 {
   129  			flags4S = append(flags4S, NotFramedEncircledCode)
   130  		} else if i&0b00000001 != 0 {
   131  			flags4S = append(flags4S, FramedCode)
   132  		} else if i&0b00000010 != 0 {
   133  			flags4S = append(flags4S, EncircledCode)
   134  		}
   135  		if i&0b00100000 != 0 {
   136  			flags4S = append(flags4S, NotSuperscriptSubscriptCode)
   137  		} else if i&0b00000100 != 0 {
   138  			flags4S = append(flags4S, SuperscriptCode)
   139  		} else if i&0b00001000 != 0 {
   140  			flags4S = append(flags4S, SubscriptCode)
   141  		}
   142  		cacheTable4[i] = strings.Join(flags4S, ";")
   143  	}
   144  }
   145  
   146  func initCacheTable5() {
   147  	for i := 0; i < 256; i++ {
   148  		var flags5S []string
   149  		if i&0b00100000 != 0 {
   150  			flags5S = append(flags5S, NoIdeogramAttributesCode)
   151  		} else if i&0b00000001 != 0 {
   152  			flags5S = append(flags5S, IdeogramUnderlineCode)
   153  		} else if i&0b00000010 != 0 {
   154  			flags5S = append(flags5S, IdeogramDoubleUnderlineCode)
   155  		} else if i&0b00000100 != 0 {
   156  			flags5S = append(flags5S, IdeogramOverlineCode)
   157  		} else if i&0b00001000 != 0 {
   158  			flags5S = append(flags5S, IdeogramDoubleOverlineCode)
   159  		} else if i&0b00010000 != 0 {
   160  			flags5S = append(flags5S, IdeogramStressMarkingCode)
   161  		}
   162  		cacheTable5[i] = strings.Join(flags5S, ";")
   163  	}
   164  }
   165  
   166  func init() {
   167  	initCacheTable1()
   168  	initCacheTable2()
   169  	initCacheTable3()
   170  	initCacheTable4()
   171  	initCacheTable5()
   172  }