Skip to content

Commit

Permalink
Address errcheck errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Dec 29, 2017
1 parent b7abc91 commit e76df81
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 57 deletions.
28 changes: 21 additions & 7 deletions internal/cops/examples/borkart/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ func main() {
}
}

func run() error {
func run() (err error) {

term := terminal.New(os.Stdout.Fd())
defer term.Restore()
term.SetRaw()
defer func() {
err = term.Restore()
}()
err = term.SetRaw()
if err != nil {
return err
}

bounds, err := term.Bounds()
if err != nil {
Expand Down Expand Up @@ -72,11 +77,17 @@ Loop:

buf, cur = display.RenderOver(buf, cur, front, back, display.Model24)
front, back = back, front
os.Stdout.Write(buf)
_, err = os.Stdout.Write(buf)
if err != nil {
return err
}
buf = buf[0:0]

var rbuf [1]byte
os.Stdin.Read(rbuf[0:1])
_, err = os.Stdin.Read(rbuf[0:1])
if err != nil {
return err
}

switch rbuf[0] {
case ' ':
Expand All @@ -101,7 +112,10 @@ Loop:
buf, cur = cur.Home(buf)
buf, cur = cur.Clear(buf)
buf, cur = cur.Show(buf)
os.Stdout.Write(buf)
_, err = os.Stdout.Write(buf)
if err != nil {
return err
}
buf = buf[0:0]
return nil
return err
}
6 changes: 3 additions & 3 deletions internal/cops/examples/brailleline/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {
}
}

func run() error {
func run() (err error) {
w, h := 32, 16
pb := image.Rect(0, 0, w, h)
bb := braille.Bounds(pb)
Expand All @@ -38,7 +38,7 @@ func run() error {
cur := display.Reset
buf, cur = display.Render(buf, cur, front, display.Model0)
buf = append(buf, "\r\n"...)
os.Stdout.Write(buf)
_, err = os.Stdout.Write(buf)

return nil
return err
}
6 changes: 3 additions & 3 deletions internal/cops/examples/braillematrix/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {
}
}

func run() error {
func run() (err error) {

w, h := 16, 16
pb := image.Rect(0, 0, w, h)
Expand Down Expand Up @@ -66,7 +66,7 @@ func run() error {
cur := display.Reset
buf, cur = display.Render(buf, cur, page, display.Model8)
buf = append(buf, "\r\n"...)
os.Stdout.Write(buf)
_, err = os.Stdout.Write(buf)

return nil
return err
}
22 changes: 15 additions & 7 deletions internal/cops/examples/braillewave/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ func main() {
}
}

func run() error {
func run() (err error) {
term := terminal.New(os.Stdout.Fd())
defer term.Restore()
term.SetRaw()
defer func() {
err = term.Restore()
}()
err = term.SetRaw()
if err != nil {
return err
}

bounds, err := term.Bounds()
if err != nil {
Expand All @@ -34,7 +39,7 @@ func run() error {
stopper := make(chan struct{}, 0)
go func() {
var rbuf [1]byte
os.Stdin.Read(rbuf[0:1])
_, err = os.Stdin.Read(rbuf[0:1])
close(stopper)
}()

Expand Down Expand Up @@ -69,7 +74,10 @@ Loop:

buf, cur = display.RenderOver(buf, cur, front, back, display.Model24)
front, back = back, front
os.Stdout.Write(buf)
_, err = os.Stdout.Write(buf)
if err != nil {
return err
}
buf = buf[0:0]

select {
Expand All @@ -84,8 +92,8 @@ Loop:
buf, cur = cur.Home(buf)
buf, cur = cur.Clear(buf)
buf, cur = cur.Show(buf)
os.Stdout.Write(buf)
_, err = os.Stdout.Write(buf)
buf = buf[0:0]

return nil
return err
}
25 changes: 18 additions & 7 deletions internal/cops/examples/earthgif/earthgif.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ func main() {
}
}

func run() error {
func run() (err error) {
term := terminal.New(os.Stdin.Fd())
defer term.Restore()
term.SetRaw()
defer func() {
err = term.Restore()
}()
err = term.SetRaw()
if err != nil {
return err
}

data, err := Asset("earth.gif")
if err != nil {
Expand Down Expand Up @@ -62,7 +67,10 @@ func run() error {
go func() {
var rbuf [1]byte
for {
os.Stdin.Read(rbuf[0:1])
_, err := os.Stdin.Read(rbuf[0:1])
if err != nil {
break
}
keypress <- rbuf[0]
}
}()
Expand All @@ -78,7 +86,10 @@ Loop:
buf, cur = display.RenderOver(buf, cur, front, back, display.Model24)
front, back = back, front
buf, cur = cur.Home(buf)
os.Stdout.Write(buf)
_, err = os.Stdout.Write(buf)
if err != nil {
break Loop
}
buf = buf[0:0]

delay := time.Duration(imgs.Delay[i]) * time.Millisecond * 10
Expand All @@ -98,10 +109,10 @@ Loop:
buf, cur = cur.Home(buf)
buf, cur = cur.Clear(buf)
buf, cur = cur.Show(buf)
os.Stdout.Write(buf)
_, err = os.Stdout.Write(buf)
buf = buf[0:0]

return nil
return err
}

func projectCenterPreserveAspect(inner, outer image.Point) image.Rectangle {
Expand Down
25 changes: 18 additions & 7 deletions internal/cops/examples/hicops/hicops.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ func main() {
}
}

func run() error {
func run() (err error) {
term := terminal.New(os.Stdin.Fd())
defer term.Restore()
term.SetRaw()
defer func() {
err = term.Restore()
}()
err = term.SetRaw()
if err != nil {
return
}

bounds, err := term.Bounds()
if err != nil {
Expand Down Expand Up @@ -51,17 +56,23 @@ func run() error {
buf, cur = cur.Home(buf)
buf, cur = display.Render(buf, cur, front, display.Model24)
buf, cur = cur.Home(buf)
os.Stdout.Write(buf)
_, err = os.Stdout.Write(buf)
if err != nil {
return err
}
buf = buf[0:0]

var input [1]byte
os.Stdin.Read(input[0:1])
_, err = os.Stdin.Read(input[0:1])
if err != nil {
return err
}

buf, cur = cur.Home(buf)
buf, cur = cur.Clear(buf)
buf, cur = cur.Show(buf)
os.Stdout.Write(buf)
_, err = os.Stdout.Write(buf)
buf = buf[0:0]

return nil
return err
}
26 changes: 18 additions & 8 deletions internal/cops/examples/vt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ func main() {
}
}

func run() error {
func run() (err error) {
term := terminal.New(os.Stdin.Fd())
defer term.Restore()
term.SetRaw()
defer func() {
err = term.Restore()
}()
err = term.SetRaw()
if err != nil {
return err
}

leader, follower, err := termios.Pty()
if err != nil {
Expand All @@ -46,7 +51,9 @@ func run() error {
}

vtw := vtio.NewDisplayWriter(bounds)
go io.Copy(vtw, leader)
go func() {
_, err = io.Copy(vtw, leader)
}()

front, back := display.New2(bounds)

Expand All @@ -61,7 +68,7 @@ func run() error {
r := make(chan struct{}, 0)
go func() {
var rbuf [1]byte
os.Stdin.Read(rbuf[0:1])
_, err = os.Stdin.Read(rbuf[0:1])
close(r)
}()

Expand All @@ -73,7 +80,10 @@ DrawLoop:
buf, cur = display.RenderOver(buf, cur, front, back, display.Model24)
front, back = back, front
// fmt.Printf("%q\r\n", buf)
os.Stdout.Write(buf)
_, err = os.Stdout.Write(buf)
if err != nil {
break DrawLoop
}
buf = buf[0:0]
case <-r:
break DrawLoop
Expand All @@ -84,8 +94,8 @@ DrawLoop:
buf, cur = cur.Home(buf)
buf, cur = cur.Clear(buf)
buf, cur = cur.Show(buf)
os.Stdout.Write(buf)
_, err = os.Stdout.Write(buf)
buf = buf[0:0]

return nil
return err
}
2 changes: 1 addition & 1 deletion internal/cops/terminal/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Terminal struct {
// that terminal to its current state.
func New(fd uintptr) Terminal {
t := Terminal{fd: fd}
termios.Tcgetattr(fd, &t.old)
_ = termios.Tcgetattr(fd, &t.old)
t.now = t.old
return t
}
Expand Down
Loading

0 comments on commit e76df81

Please sign in to comment.