@@ 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