diff --git a/application.go b/application.go index 6a215d6..f45b6ae 100644 --- a/application.go +++ b/application.go @@ -244,6 +244,9 @@ func (a *Application) SetFocus(p Primitive) *Application { a.focus.Blur() } a.focus = p + if a.screen != nil { + a.screen.HideCursor() + } a.Unlock() p.Focus(func(p Primitive) { a.SetFocus(p) diff --git a/button.go b/button.go index c9c472e..99789a3 100644 --- a/button.go +++ b/button.go @@ -115,10 +115,6 @@ func (b *Button) Draw(screen tcell.Screen) { } Print(screen, b.label, x, y, width, AlignCenter, labelColor) } - - if b.focus.HasFocus() { - screen.HideCursor() - } } // InputHandler returns the handler for this primitive. diff --git a/checkbox.go b/checkbox.go index d298fcf..c9da33b 100644 --- a/checkbox.go +++ b/checkbox.go @@ -138,11 +138,6 @@ func (c *Checkbox) Draw(screen tcell.Screen) { checkedRune = ' ' } screen.SetContent(x, y, checkedRune, nil, fieldStyle) - - // Hide cursor. - if c.focus.HasFocus() { - screen.HideCursor() - } } // InputHandler returns the handler for this primitive. diff --git a/doc.go b/doc.go index bcb1106..8a45438 100644 --- a/doc.go +++ b/doc.go @@ -2,6 +2,33 @@ Package tview implements primitives for terminal based applications. It uses 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). */ package tview diff --git a/dropdown.go b/dropdown.go index 55493b5..a283b3c 100644 --- a/dropdown.go +++ b/dropdown.go @@ -231,11 +231,6 @@ func (d *DropDown) Draw(screen tcell.Screen) { d.list.SetRect(lx, ly, lwidth, lheight) d.list.Draw(screen) } - - // No cursor for this primitive. - if d.focus.HasFocus() { - screen.HideCursor() - } } // InputHandler returns the handler for this primitive.