mirror of
https://github.com/rivo/tview.git
synced 2025-04-28 13:48:53 +08:00
No need to explicitly hide the cursor in no-cursor primitives.
This commit is contained in:
parent
1cc5331a5c
commit
9659be0e90
@ -244,6 +244,9 @@ func (a *Application) SetFocus(p Primitive) *Application {
|
|||||||
a.focus.Blur()
|
a.focus.Blur()
|
||||||
}
|
}
|
||||||
a.focus = p
|
a.focus = p
|
||||||
|
if a.screen != nil {
|
||||||
|
a.screen.HideCursor()
|
||||||
|
}
|
||||||
a.Unlock()
|
a.Unlock()
|
||||||
p.Focus(func(p Primitive) {
|
p.Focus(func(p Primitive) {
|
||||||
a.SetFocus(p)
|
a.SetFocus(p)
|
||||||
|
@ -115,10 +115,6 @@ func (b *Button) Draw(screen tcell.Screen) {
|
|||||||
}
|
}
|
||||||
Print(screen, b.label, x, y, width, AlignCenter, labelColor)
|
Print(screen, b.label, x, y, width, AlignCenter, labelColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.focus.HasFocus() {
|
|
||||||
screen.HideCursor()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputHandler returns the handler for this primitive.
|
// InputHandler returns the handler for this primitive.
|
||||||
|
@ -138,11 +138,6 @@ func (c *Checkbox) Draw(screen tcell.Screen) {
|
|||||||
checkedRune = ' '
|
checkedRune = ' '
|
||||||
}
|
}
|
||||||
screen.SetContent(x, y, checkedRune, nil, fieldStyle)
|
screen.SetContent(x, y, checkedRune, nil, fieldStyle)
|
||||||
|
|
||||||
// Hide cursor.
|
|
||||||
if c.focus.HasFocus() {
|
|
||||||
screen.HideCursor()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputHandler returns the handler for this primitive.
|
// InputHandler returns the handler for this primitive.
|
||||||
|
27
doc.go
27
doc.go
@ -2,6 +2,33 @@
|
|||||||
Package tview implements primitives for terminal based applications. It uses
|
Package tview implements primitives for terminal based applications. It uses
|
||||||
github.com/gdamore/tcell.
|
github.com/gdamore/tcell.
|
||||||
|
|
||||||
|
Hello World
|
||||||
|
|
||||||
|
Here is a very basic example showing a box with the title "Hello, world!":
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/rivo/tview"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
box := tview.NewBox().SetBorder(true).SetTitle("Hello, world!")
|
||||||
|
if err := tview.NewApplication().SetRoot(box, true).Run(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
First, we create a box primitive with a border and a title. Then we create an
|
||||||
|
application, set the box as its root primitive, and run the event loop. It
|
||||||
|
exits when the application's Stop() function is called or when Ctrl-C is
|
||||||
|
pressed.
|
||||||
|
|
||||||
|
If we have a primitive which consumes key presses, we call the application's
|
||||||
|
SetFocus() function to redirect all key presses to that primitive. Most
|
||||||
|
primitives then offer ways to install handlers that allow you to react to any
|
||||||
|
actions performed on them.
|
||||||
|
|
||||||
No mouse input (yet).
|
No mouse input (yet).
|
||||||
*/
|
*/
|
||||||
package tview
|
package tview
|
||||||
|
@ -231,11 +231,6 @@ func (d *DropDown) Draw(screen tcell.Screen) {
|
|||||||
d.list.SetRect(lx, ly, lwidth, lheight)
|
d.list.SetRect(lx, ly, lwidth, lheight)
|
||||||
d.list.Draw(screen)
|
d.list.Draw(screen)
|
||||||
}
|
}
|
||||||
|
|
||||||
// No cursor for this primitive.
|
|
||||||
if d.focus.HasFocus() {
|
|
||||||
screen.HideCursor()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputHandler returns the handler for this primitive.
|
// InputHandler returns the handler for this primitive.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user