Skip to content

Commit

Permalink
styl: ignore useless code lines
Browse files Browse the repository at this point in the history
  • Loading branch information
yeqown committed Dec 13, 2021
1 parent 9267a8b commit 3b029fa
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 77 deletions.
67 changes: 34 additions & 33 deletions writer/terminal/helper.go
Original file line number Diff line number Diff line change
@@ -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
//}
77 changes: 39 additions & 38 deletions writer/terminal/option.go
Original file line number Diff line number Diff line change
@@ -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
//}
11 changes: 5 additions & 6 deletions writer/terminal/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3b029fa

Please sign in to comment.