Codebase list golang-github-mattn-go-colorable / 7a443b5
Update upstream source from tag 'upstream/0.1.7' Update to upstream version '0.1.7' with Debian dir f54482f7414b833602e827bff2da39f5a2142731 Drew Parsons 3 years ago
1 changed file(s) with 17 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
99 "os"
1010 "strconv"
1111 "strings"
12 "sync"
1213 "syscall"
1314 "unsafe"
1415
2627 backgroundRed = 0x40
2728 backgroundIntensity = 0x80
2829 backgroundMask = (backgroundRed | backgroundBlue | backgroundGreen | backgroundIntensity)
30 commonLvbUnderscore = 0x8000
2931
3032 cENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4
3133 )
9294 oldattr word
9395 oldpos coord
9496 rest bytes.Buffer
97 mutex sync.Mutex
9598 }
9699
97100 // NewColorable returns new instance of Writer which handles escape sequence from File.
431434
432435 // Write writes data on console
433436 func (w *Writer) Write(data []byte) (n int, err error) {
437 w.mutex.Lock()
438 defer w.mutex.Unlock()
434439 var csbi consoleScreenBufferInfo
435440 procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
436441
682687 switch {
683688 case n == 0 || n == 100:
684689 attr = w.oldattr
685 case 1 <= n && n <= 5:
690 case n == 4:
691 attr |= commonLvbUnderscore
692 case (1 <= n && n <= 3) || n == 5:
686693 attr |= foregroundIntensity
687 case n == 7:
688 attr = ((attr & foregroundMask) << 4) | ((attr & backgroundMask) >> 4)
689 case n == 22 || n == 25:
690 attr |= foregroundIntensity
691 case n == 27:
692 attr = ((attr & foregroundMask) << 4) | ((attr & backgroundMask) >> 4)
694 case n == 7 || n == 27:
695 attr =
696 (attr &^ (foregroundMask | backgroundMask)) |
697 ((attr & foregroundMask) << 4) |
698 ((attr & backgroundMask) >> 4)
699 case n == 22:
700 attr &^= foregroundIntensity
701 case n == 24:
702 attr &^= commonLvbUnderscore
693703 case 30 <= n && n <= 37:
694704 attr &= backgroundMask
695705 if (n-30)&1 != 0 {