Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set Display.errch and use it for errors from mouse/keyboard #17

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Next Next commit
set Display.errch and use it for errors from mouse/keyboard
i've only seen error EOF from devdraw mouse/keyboard, when i close
a window (at least on macos), or by calling Display.Close().  before
this change, the draw lib would call log.Fatal, ending the entire
program.  now, it will send the error on errch.  it is the caller's
responsibility to pass an errch to Init() that has buffering, if
it wants to be sure it sees the errors.

this doesn't remove the "TODO use errch" comment at Init(), because
not all errors are handled yet. there are still some log.Fatal's,
around allocimage/allocwindow.
  • Loading branch information
mjl- committed Jan 6, 2018
commit b913ad677a5705021e1ced8a78ab717ac654d7d5
3 changes: 3 additions & 0 deletions draw/init.go
Original file line number Diff line number Diff line change
@@ -88,6 +88,9 @@ func Init(errch chan<- error, fontname, label, winsize string) (*Display, error)
if err != nil {
return nil, err
}
if errch == nil {
errch = make(chan error)
}
d := &Display{
conn: c,
errch: errch,
8 changes: 5 additions & 3 deletions draw/keyboard.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package draw

import "log"

const (
KeyFn = '\uF000'

@@ -42,7 +40,11 @@ func kbdproc(d *Display, ch chan rune) {
for {
r, err := d.conn.ReadKbd()
if err != nil {
log.Fatal(err)
select {
case d.errch <- err:
default:
}
return
}
ch <- r
}
7 changes: 5 additions & 2 deletions draw/mouse.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ package draw
import (
"fmt"
"image"
"log"
"os"
)

@@ -45,7 +44,11 @@ func mouseproc(mc *Mousectl, d *Display, ch chan Mouse, rch chan bool) {
for {
m, resized, err := d.conn.ReadMouse()
if err != nil {
log.Fatal(err)
select {
case d.errch <- err:
default:
}
return
}
if resized {
rch <- true