rename events and Screen.Fini -> Screen.Close
7 files changed, 106 insertions(+), 103 deletions(-)

M error.go
M event.go
M mouse.go
M screen.go
M simscreen.go
M tscreen.go
M view/app.go
M error.go +4 -4
@@ 49,14 49,14 @@ var (
 	ErrEventQFull = errors.New("event queue full")
 )
 
-// An EventError is an event representing some sort of error, and carries
+// An ErrorEvent is an event representing some sort of error, and carries
 // an error payload.
-type EventError struct {
+type ErrorEvent struct {
 	*event
 	error
 }
 
 // NewEventError creates an ErrorEvent with the given error payload.
-func NewEventError(err error) *EventError {
-	return &EventError{newEvent(), err}
+func NewErrorEvent(err error) *ErrorEvent {
+	return &ErrorEvent{newEvent(), err}
 }

          
M event.go +4 -4
@@ 39,18 39,18 @@ func newEvent() *event {
 // EventResize is sent when the window size changes.
 //
 // todo: used in simulation screen only
-type EventResize struct {
+type ResizeEvent struct {
 	*event
 	w, h int
 }
 
 // NewEventResize creates an EventResize with the new updated window size,
 // which is given in character cells.
-func NewEventResize(width, height int) *EventResize {
-	return &EventResize{newEvent(), width, height}
+func NewResizeEvent(width, height int) *ResizeEvent {
+	return &ResizeEvent{newEvent(), width, height}
 }
 
 // Size returns the new window size as width, height in character cells.
-func (ev *EventResize) Size() (int, int) {
+func (ev *ResizeEvent) Size() (int, int) {
 	return ev.w, ev.h
 }

          
M mouse.go +1 -1
@@ 56,7 56,7 @@ func (ev *MouseEvent) Position() (int, i
 
 // NewEventMouse is used to create a new mouse event.  Applications
 // shouldn't need to use this; its mostly for screen implementors.
-func NewEventMouse(x, y int, btn ButtonMask, mod ModMask) *MouseEvent {
+func NewMouseEvent(x, y int, btn ButtonMask, mod ModMask) *MouseEvent {
 	return &MouseEvent{event: newEvent(), x: x, y: y, btn: btn, mod: mod}
 }
 

          
M screen.go +2 -2
@@ 18,8 18,8 @@ package tcell
 // This can be a terminal window or a physical console.  Platforms implement
 // this differerently.
 type Screen interface {
-	// Fini finalizes the screen also releasing resources.
-	Fini()
+	// Close closes the screen releasing all resources.
+	Close() error
 
 	// Clear erases the screen.  The contents of any screen buffers
 	// will also be cleared.  This has the logical effect of

          
M simscreen.go +4 -3
@@ 96,7 96,7 @@ type SimScreen struct {
 	sync.Mutex
 }
 
-func (s *SimScreen) Fini() {
+func (s *SimScreen) Close() error {
 	s.Lock()
 	s.fini = true
 	s.back.Resize(0, 0)

          
@@ 107,6 107,7 @@ func (s *SimScreen) Fini() {
 	s.physw = 0
 	s.physh = 0
 	s.front = nil
+	return nil
 }
 
 func (s *SimScreen) SetStyle(style Style) {

          
@@ 279,7 280,7 @@ func (s *SimScreen) resize() {
 	ow, oh := s.back.Size()
 	if w != ow || h != oh {
 		s.back.Resize(w, h)
-		s.PostEvent(NewEventResize(w, h))
+		s.PostEvent(NewResizeEvent(w, h))
 	}
 }
 

          
@@ 310,7 311,7 @@ func (s *SimScreen) PostEvent(ev Event) 
 }
 
 func (s *SimScreen) InjectMouse(x, y int, buttons ButtonMask, mod ModMask) {
-	s.PostEvent(NewEventMouse(x, y, buttons, mod))
+	s.PostEvent(NewMouseEvent(x, y, buttons, mod))
 }
 
 func (s *SimScreen) InjectKey(key Key, r rune, mod ModMask) {

          
M tscreen.go +88 -87
@@ 72,8 72,8 @@ func NewTerminfoScreen() (Screen, error)
 	t.decoder = enc.NewDecoder()
 
 	// environment overrides
-	w := ti.Columns
-	h := ti.Lines
+	// todo: bug here, see below
+	w, h := ti.Columns, ti.Lines
 	if i, _ := strconv.Atoi(os.Getenv("LINES")); i != 0 {
 		h = i
 	}

          
@@ 86,10 86,11 @@ func NewTerminfoScreen() (Screen, error)
 	signal.Notify(t.sigwinch, syscall.SIGWINCH)
 
 	if w, h, e := t.term.ReadSize(); e == nil && w != 0 && h != 0 {
+		// a resize, and below another one
 		t.cells.Resize(w, h)
 	}
 
-	if t.ti.SetFgBgRGB != "" || t.ti.SetFgRGB != "" || t.ti.SetBgRGB != "" {
+	if ti.SetFgBgRGB != "" || ti.SetFgRGB != "" || ti.SetBgRGB != "" {
 		t.truecolor = true
 	}
 	// A user who wants to have his themes honored can

          
@@ 110,16 111,17 @@ func NewTerminfoScreen() (Screen, error)
 	t.quit = make(chan struct{})
 
 	t.TPuts(ti.EnterCA)
-	t.TPuts(ti.HideCursor)
 	t.TPuts(ti.EnableAcs)
-	t.TPuts(ti.Clear)
+	t.hideCursor()
+	t.clearScreen()
 
 	t.cx, t.cy = -1, -1
+	t.cursorx, t.cursory = -1, -1
 	t.style = StyleDefault
+	// second resize, see above
 	t.cells.Resize(w, h)
-	t.cursorx, t.cursory = -1, -1
 	if err := t.resize(); err != nil {
-		return nil, fmt.Errorf("resize terminal: %v", err)
+		return nil, fmt.Errorf("resize screen: %v", err)
 	}
 
 	go t.mainLoop()

          
@@ 181,17 183,16 @@ type tScreen struct {
 	buttondn bool
 }
 
-func (t *tScreen) Fini() {
+func (t *tScreen) Close() error {
 	ti := t.ti
 	t.Lock()
 	t.cells.Resize(0, 0)
-	t.TPuts(ti.ShowCursor)
+	t.showCursor()
 	t.TPuts(ti.AttrOff)
-	t.TPuts(ti.Clear)
+	t.clearScreen()
 	t.TPuts(ti.ExitCA)
 	t.TPuts(ti.ExitKeypad)
 	t.DisableMouse()
-	t.clear = false
 	t.fini = true
 
 	if t.quit != nil {

          
@@ 203,8 204,8 @@ func (t *tScreen) Fini() {
 	signal.Stop(t.sigwinch)
 
 	<-t.indoneq
-	// todo: error
-	t.term.Close()
+
+	return t.term.Close()
 }
 
 func (t *tScreen) SetStyle(style Style) {

          
@@ 430,19 431,7 @@ func (t *tScreen) TPuts(s string) {
 	t.ti.TPuts(t.term.Out, s, t.term.Speed)
 }
 
-func (t *tScreen) Show() {
-	t.Lock()
-	if !t.fini {
-		// why resize here? dont we do this if an resize event occurs?
-		t.resize()
-		t.draw()
-	}
-	t.Unlock()
-}
-
 func (t *tScreen) clearScreen() {
-	fg, bg, _ := t.style.Decompose()
-	t.sendFgBg(fg, bg)
 	t.TPuts(t.ti.Clear)
 	t.clear = false
 }

          
@@ 467,6 456,8 @@ func (t *tScreen) draw() {
 	t.hideCursor()
 
 	if t.clear {
+		fg, bg, _ := t.style.Decompose()
+		t.sendFgBg(fg, bg)
 		t.clearScreen()
 	}
 	curr := Style(-1)

          
@@ 520,11 511,33 @@ func (t *tScreen) resize() error {
 		t.cells.Resize(w, h)
 		t.cells.Invalidate()
 		t.h, t.w = h, w
-		t.PostEvent(NewEventResize(w, h))
+		t.PostEvent(NewResizeEvent(w, h))
 	}
 	return nil
 }
 
+func (t *tScreen) Show() {
+	t.Lock()
+	if !t.fini {
+		// why resize here? dont we do this if an resize event occurs?
+		t.resize()
+		t.draw()
+	}
+	t.Unlock()
+}
+
+func (t *tScreen) Sync() {
+	t.Lock()
+	t.gotoXY(-1, -1)
+	if !t.fini {
+		t.resize()
+		t.clear = true
+		t.cells.Invalidate()
+		t.draw()
+	}
+	t.Unlock()
+}
+
 func (t *tScreen) Colors() int {
 	// this doesn't change, no need for lock
 	if t.truecolor {

          
@@ 542,53 555,6 @@ func (t *tScreen) PollEvent() Event {
 	}
 }
 
-// vtACSNames is a map of bytes defined by terminfo that are used in
-// the terminals Alternate Character Set to represent other glyphs.
-// For example, the upper left corner of the box drawing set can be
-// displayed by printing "l" while in the alternate character set.
-// Its not quite that simple, since the "l" is the terminfo name,
-// and it may be necessary to use a different character based on
-// the terminal implementation (or the terminal may lack support for
-// this altogether).  See buildAcsMap below for detail.
-var vtACSNames = map[byte]rune{
-	'+': RuneRArrow,
-	',': RuneLArrow,
-	'-': RuneUArrow,
-	'.': RuneDArrow,
-	'0': RuneBlock,
-	'`': RuneDiamond,
-	'a': RuneCkBoard,
-	'b': '␉', // VT100, Not defined by terminfo
-	'c': '␌', // VT100, Not defined by terminfo
-	'd': '␋', // VT100, Not defined by terminfo
-	'e': '␊', // VT100, Not defined by terminfo
-	'f': RuneDegree,
-	'g': RunePlMinus,
-	'h': RuneBoard,
-	'i': RuneLantern,
-	'j': RuneLRCorner,
-	'k': RuneURCorner,
-	'l': RuneULCorner,
-	'm': RuneLLCorner,
-	'n': RunePlus,
-	'o': RuneS1,
-	'p': RuneS3,
-	'q': RuneHLine,
-	'r': RuneS7,
-	's': RuneS9,
-	't': RuneLTee,
-	'u': RuneRTee,
-	'v': RuneBTee,
-	'w': RuneTTee,
-	'x': RuneVLine,
-	'y': RuneLEqual,
-	'z': RuneGEqual,
-	'{': RunePi,
-	'|': RuneNEqual,
-	'}': RuneSterling,
-	'~': RuneBullet,
-}
-
 func (t *tScreen) PostEventWait(ev Event) {
 	t.evch <- ev
 }

          
@@ 673,7 639,7 @@ func (t *tScreen) postMouseEvent(x, y, b
 	// screen, especially with click-drag events.  Clip the coordinates
 	// to the screen in that case.
 	x, y = t.clip(x, y)
-	t.PostEvent(NewEventMouse(x, y, button, mod))
+	t.PostEvent(NewMouseEvent(x, y, button, mod))
 }
 
 // parseSgrMouse attempts to locate an SGR mouse record at the start of the

          
@@ 1056,7 1022,7 @@ func (t *tScreen) inputLoop() {
 		case io.EOF:
 		case nil:
 		default:
-			t.PostEvent(NewEventError(e))
+			t.PostEvent(NewErrorEvent(e))
 			return
 		}
 		t.keychan <- chunk[:n]

          
@@ 1071,18 1037,6 @@ func (t *tScreen) gotoXY(x, y int) {
 	}
 }
 
-func (t *tScreen) Sync() {
-	t.Lock()
-	t.cx, t.cy = -1, -1
-	if !t.fini {
-		t.resize()
-		t.clear = true
-		t.cells.Invalidate()
-		t.draw()
-	}
-	t.Unlock()
-}
-
 func (t *tScreen) CharacterSet() string {
 	return t.charset
 }

          
@@ 1138,6 1092,53 @@ func (t *tScreen) HasKey(k Key) bool {
 
 func (t *tScreen) Resize(int, int, int, int) {}
 
+// vtACSNames is a map of bytes defined by terminfo that are used in
+// the terminals Alternate Character Set to represent other glyphs.
+// For example, the upper left corner of the box drawing set can be
+// displayed by printing "l" while in the alternate character set.
+// Its not quite that simple, since the "l" is the terminfo name,
+// and it may be necessary to use a different character based on
+// the terminal implementation (or the terminal may lack support for
+// this altogether).  See buildAcsMap below for detail.
+var vtACSNames = map[byte]rune{
+	'+': RuneRArrow,
+	',': RuneLArrow,
+	'-': RuneUArrow,
+	'.': RuneDArrow,
+	'0': RuneBlock,
+	'`': RuneDiamond,
+	'a': RuneCkBoard,
+	'b': '␉', // VT100, Not defined by terminfo
+	'c': '␌', // VT100, Not defined by terminfo
+	'd': '␋', // VT100, Not defined by terminfo
+	'e': '␊', // VT100, Not defined by terminfo
+	'f': RuneDegree,
+	'g': RunePlMinus,
+	'h': RuneBoard,
+	'i': RuneLantern,
+	'j': RuneLRCorner,
+	'k': RuneURCorner,
+	'l': RuneULCorner,
+	'm': RuneLLCorner,
+	'n': RunePlus,
+	'o': RuneS1,
+	'p': RuneS3,
+	'q': RuneHLine,
+	'r': RuneS7,
+	's': RuneS9,
+	't': RuneLTee,
+	'u': RuneRTee,
+	'v': RuneBTee,
+	'w': RuneTTee,
+	'x': RuneVLine,
+	'y': RuneLEqual,
+	'z': RuneGEqual,
+	'{': RunePi,
+	'|': RuneNEqual,
+	'}': RuneSterling,
+	'~': RuneBullet,
+}
+
 // buildAcsMap builds a map of characters that we translate from Unicode to
 // alternate character encodings.  To do this, we use the standard VT100 ACS
 // maps.  This is only done if the terminal lacks support for Unicode; we

          
M view/app.go +3 -2
@@ 144,7 144,7 @@ loop:
 			screen.Sync()
 		case *eventAppFunc:
 			nev.fn()
-		case *tcell.EventResize:
+		case *tcell.ResizeEvent:
 			screen.Sync()
 			widget.Resize()
 		default:

          
@@ 153,7 153,8 @@ loop:
 			}
 		}
 	}
-	screen.Fini()
+	// todo: error handling
+	screen.Close()
 	app.wg.Done()
 }