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