tty-util.go: sostituita la variabile self con nome specifico tty per il tipo TTYContext

This commit is contained in:
Celestino Amoroso 2025-10-24 14:51:43 +02:00
parent 632f68a572
commit 269f30b2ed

View File

@ -29,142 +29,142 @@ type TTYContext struct {
isTTY [3]bool isTTY [3]bool
} }
func (self *TTYContext) Init() { func (ctx *TTYContext) Init() {
for i, _ := range self.isTTY { for i := range ctx.isTTY {
self.isTTY[i] = StreamIsTerminal(getStream(uint(i))) ctx.isTTY[i] = StreamIsTerminal(getStream(uint(i)))
} }
} }
func (self *TTYContext) IsTTY(fd uint) bool { func (ctx *TTYContext) IsTTY(fd uint) bool {
if fd == STDERR || fd == STDOUT { if fd == STDERR || fd == STDOUT {
return self.isTTY[fd] return ctx.isTTY[fd]
} }
return false return false
} }
func (self *TTYContext) Clean() { func (ctx *TTYContext) Clean() {
for i, _ := range self.isTTY { for i := range ctx.isTTY {
self.isTTY[i] = false ctx.isTTY[i] = false
} }
} }
func (self *TTYContext) Bold(fd uint) string { func (ctx *TTYContext) Bold(fd uint) string {
if self.isTTY[fd] { if ctx.isTTY[fd] {
return "\x1b[1m" return "\x1b[1m"
} }
return "" return ""
} }
func (self *TTYContext) BoldOff(fd uint) string { func (ctx *TTYContext) BoldOff(fd uint) string {
if self.isTTY[fd] { if ctx.isTTY[fd] {
return "\x1b[22m" return "\x1b[22m"
} }
return "" return ""
} }
func (self *TTYContext) Underline(fd uint) string { func (ctx *TTYContext) Underline(fd uint) string {
if self.isTTY[fd] { if ctx.isTTY[fd] {
return "\x1b[4m" return "\x1b[4m"
} }
return "" return ""
} }
func (self *TTYContext) UnderlineOff(fd uint) string { func (ctx *TTYContext) UnderlineOff(fd uint) string {
if self.isTTY[fd] { if ctx.isTTY[fd] {
return "\x1b[24m" return "\x1b[24m"
} }
return "" return ""
} }
func (self *TTYContext) Italic(fd uint) string { func (ctx *TTYContext) Italic(fd uint) string {
if self.isTTY[fd] { if ctx.isTTY[fd] {
return "\x1b[3m" return "\x1b[3m"
} }
return "" return ""
} }
func (self *TTYContext) ItalicOff(fd uint) string { func (ctx *TTYContext) ItalicOff(fd uint) string {
if self.isTTY[fd] { if ctx.isTTY[fd] {
return "\x1b[23m" return "\x1b[23m"
} }
return "" return ""
} }
func (self *TTYContext) BlackFg(fd uint) string { func (ctx *TTYContext) BlackFg(fd uint) string {
if self.isTTY[fd] { if ctx.isTTY[fd] {
return "\x1b[30m" return "\x1b[30m"
} }
return "" return ""
} }
func (self *TTYContext) RedFg(fd uint) string { func (ctx *TTYContext) RedFg(fd uint) string {
if self.isTTY[fd] { if ctx.isTTY[fd] {
return "\x1b[31m" return "\x1b[31m"
} }
return "" return ""
} }
func (self *TTYContext) GreenFg(fd uint) string { func (ctx *TTYContext) GreenFg(fd uint) string {
if self.isTTY[fd] { if ctx.isTTY[fd] {
return "\x1b[32m" return "\x1b[32m"
} }
return "" return ""
} }
func (self *TTYContext) BrownFg(fd uint) string { func (ctx *TTYContext) BrownFg(fd uint) string {
if self.isTTY[fd] { if ctx.isTTY[fd] {
return "\x1b[33m" return "\x1b[33m"
} }
return "" return ""
} }
func (self *TTYContext) BlueFg(fd uint) string { func (ctx *TTYContext) BlueFg(fd uint) string {
if self.isTTY[fd] { if ctx.isTTY[fd] {
return "\x1b[34m" return "\x1b[34m"
} }
return "" return ""
} }
func (self *TTYContext) MagentaFg(fd uint) string { func (ctx *TTYContext) MagentaFg(fd uint) string {
if self.isTTY[fd] { if ctx.isTTY[fd] {
return "\x1b[35m" return "\x1b[35m"
} }
return "" return ""
} }
func (self *TTYContext) CyanFg(fd uint) string { func (ctx *TTYContext) CyanFg(fd uint) string {
if self.isTTY[fd] { if ctx.isTTY[fd] {
return "\x1b[36m" return "\x1b[36m"
} }
return "" return ""
} }
func (self *TTYContext) WhiteFg(fd uint) string { func (ctx *TTYContext) WhiteFg(fd uint) string {
if self.isTTY[fd] { if ctx.isTTY[fd] {
return "\x1b[37m" return "\x1b[37m"
} }
return "" return ""
} }
func (self *TTYContext) FgColor(fd uint, n uint) string { func (ctx *TTYContext) FgColor(fd uint, n uint) string {
var color string var color string
switch n { switch n {
case BLACK: case BLACK:
color = self.BlackFg(fd) color = ctx.BlackFg(fd)
case WHITE: case WHITE:
color = self.WhiteFg(fd) color = ctx.WhiteFg(fd)
case RED: case RED:
color = self.RedFg(fd) color = ctx.RedFg(fd)
case GREEN: case GREEN:
color = self.GreenFg(fd) color = ctx.GreenFg(fd)
case BLUE: case BLUE:
color = self.BlueFg(fd) color = ctx.BlueFg(fd)
case BROWN: case BROWN:
color = self.BrownFg(fd) color = ctx.BrownFg(fd)
case CYAN: case CYAN:
color = self.CyanFg(fd) color = ctx.CyanFg(fd)
case MAGENTA: case MAGENTA:
color = self.MagentaFg(fd) color = ctx.MagentaFg(fd)
} }
return color return color
} }
@ -188,7 +188,7 @@ func (self *TTYContext) FgColor(fd uint, n uint) string {
// return color // return color
// } // }
func (self *TTYContext) Reset(fd uint) string { func (ctx *TTYContext) Reset(fd uint) string {
if StreamIsTerminal(getStream(fd)) { if StreamIsTerminal(getStream(fd)) {
return "\x1b[0m" return "\x1b[0m"
} }