From 3b029fa248fad0c3b5abeae4993428e588862695 Mon Sep 17 00:00:00 2001 From: yeqown Date: Mon, 13 Dec 2021 16:24:12 +0800 Subject: [PATCH] styl: ignore useless code lines --- writer/terminal/helper.go | 67 +++++++++++++++++----------------- writer/terminal/option.go | 77 ++++++++++++++++++++------------------- writer/terminal/writer.go | 11 +++--- 3 files changed, 78 insertions(+), 77 deletions(-) diff --git a/writer/terminal/helper.go b/writer/terminal/helper.go index f812cfb..2d5a007 100644 --- a/writer/terminal/helper.go +++ b/writer/terminal/helper.go @@ -1,35 +1,36 @@ package terminal -import ( - "image/color" - "os" - "syscall" - "unsafe" -) - -const defaultRatio float64 = 7.0 / 3.0 // The terminal's default cursor width/height ratio - -func terminalSize() (int, int, float64) { - var size [4]uint16 - if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, - uintptr(os.Stdout.Fd()), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&size)), - 0, 0, 0); err != 0 { - panic(err) - } - rows, cols, width, height := size[0], size[1], size[2], size[3] - - whratio := defaultRatio - if width > 0 && height > 0 { - whratio = float64(height/rows) / float64(width/cols) - } - - return int(cols), int(rows), whratio -} - -func terminalColor(rgb color.RGBA) uint16 { - r := (((rgb.R * 5) + 127) / 255) * 36 - g := (((rgb.G * 5) + 127) / 255) * 6 - b := ((rgb.B * 5) + 127) / 255 - - return uint16(r+g+b) + 16 + 1 // termbox default color offset -} +// +//import ( +// "image/color" +// "os" +// "syscall" +// "unsafe" +//) +// +//const defaultRatio float64 = 7.0 / 3.0 // The terminal's default cursor width/height ratio +// +//func terminalSize() (int, int, float64) { +// var size [4]uint16 +// if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, +// uintptr(os.Stdout.Fd()), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&size)), +// 0, 0, 0); err != 0 { +// panic(err) +// } +// rows, cols, width, height := size[0], size[1], size[2], size[3] +// +// whratio := defaultRatio +// if width > 0 && height > 0 { +// whratio = float64(height/rows) / float64(width/cols) +// } +// +// return int(cols), int(rows), whratio +//} +// +//func terminalColor(rgb color.RGBA) uint16 { +// r := (((rgb.R * 5) + 127) / 255) * 36 +// g := (((rgb.G * 5) + 127) / 255) * 6 +// b := ((rgb.B * 5) + 127) / 255 +// +// return uint16(r+g+b) + 16 + 1 // termbox default color offset +//} diff --git a/writer/terminal/option.go b/writer/terminal/option.go index 1eb8b56..d930f9e 100644 --- a/writer/terminal/option.go +++ b/writer/terminal/option.go @@ -1,40 +1,41 @@ package terminal -import ( - "fmt" - "image/color" -) - -var ( - White = color.RGBA{R: 255, G: 255, B: 255, A: 255} - Black = color.RGBA{A: 255} -) - -// hexToRGBA convert hex string into color.RGBA -func hexToRGBA(s string) color.RGBA { - c := color.RGBA{ - R: 0, - G: 0, - B: 0, - A: 0xff, - } - - var err error - switch len(s) { - case 7: - _, err = fmt.Sscanf(s, "#%02x%02x%02x", &c.R, &c.G, &c.B) - case 4: - _, err = fmt.Sscanf(s, "#%1x%1x%1x", &c.R, &c.G, &c.B) - // Double the hex digits: - c.R *= 17 - c.G *= 17 - c.B *= 17 - default: - err = fmt.Errorf("invalid length, must be 7 or 4") - } - if err != nil { - panic(err) - } - - return c -} +// +//import ( +// "fmt" +// "image/color" +//) +// +//var ( +// White = color.RGBA{R: 255, G: 255, B: 255, A: 255} +// Black = color.RGBA{A: 255} +//) +// +//// hexToRGBA convert hex string into color.RGBA +//func hexToRGBA(s string) color.RGBA { +// c := color.RGBA{ +// R: 0, +// G: 0, +// B: 0, +// A: 0xff, +// } +// +// var err error +// switch len(s) { +// case 7: +// _, err = fmt.Sscanf(s, "#%02x%02x%02x", &c.R, &c.G, &c.B) +// case 4: +// _, err = fmt.Sscanf(s, "#%1x%1x%1x", &c.R, &c.G, &c.B) +// // Double the hex digits: +// c.R *= 17 +// c.G *= 17 +// c.B *= 17 +// default: +// err = fmt.Errorf("invalid length, must be 7 or 4") +// } +// if err != nil { +// panic(err) +// } +// +// return c +//} diff --git a/writer/terminal/writer.go b/writer/terminal/writer.go index cf4db33..ac6fa11 100644 --- a/writer/terminal/writer.go +++ b/writer/terminal/writer.go @@ -11,8 +11,7 @@ var _ qrcode.Writer = (*Writer)(nil) // Writer implements qrcode.Writer based on termbox to print QRCode into // terminal / console. -type Writer struct { -} +type Writer struct{} func New() *Writer { w := &Writer{} @@ -50,10 +49,10 @@ func (w Writer) drawBlock(x, y, padding int, fg termbox.Attribute, bg termbox.At } func (w Writer) Write(mat matrix.Matrix) error { - width, height, whratio := terminalSize() - _ = width - _ = height - _ = whratio + //width, height, whratio := terminalSize() + //_ = width + //_ = height + //_ = whratio ww, hh := mat.Width(), mat.Height() bg := termbox.ColorWhite