mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-31 14:24:25 +03:00
build: bump gocui
This commit is contained in:
62
vendor/github.com/gdamore/tcell/v2/TUTORIAL.md
generated
vendored
62
vendor/github.com/gdamore/tcell/v2/TUTORIAL.md
generated
vendored
@ -18,7 +18,7 @@ to the terminal capabilities.
|
||||
Applications receive an event of type `EventResize` when they are first initialized and each time the terminal is resized.
|
||||
The new size is available as `Size`.
|
||||
|
||||
```golang
|
||||
```go
|
||||
switch ev := ev.(type) {
|
||||
case *tcell.EventResize:
|
||||
w, h := ev.Size()
|
||||
@ -35,7 +35,7 @@ When a rune key is pressed, an event with its `Key` set to `KeyRune` is dispatch
|
||||
|
||||
When a non-rune key is pressed, it is available as the `Key` of the event.
|
||||
|
||||
```golang
|
||||
```go
|
||||
switch ev := ev.(type) {
|
||||
case *tcell.EventKey:
|
||||
mod, key, ch := ev.Mod(), ev.Key(), ev.Rune()
|
||||
@ -62,7 +62,7 @@ Mouse events are only delivered if
|
||||
|
||||
The mouse buttons being pressed (if any) are available as `Buttons`, and the position of the mouse is available as `Position`.
|
||||
|
||||
```golang
|
||||
```go
|
||||
switch ev := ev.(type) {
|
||||
case *tcell.EventMouse:
|
||||
mod := ev.Modifiers()
|
||||
@ -81,12 +81,16 @@ Button2 | ButtonSecondary | Right button
|
||||
Button3 | ButtonMiddle | Middle button
|
||||
Button4 | | Side button (thumb/next)
|
||||
Button5 | | Side button (thumb/prev)
|
||||
WheelUp | | Scroll wheel up
|
||||
WheelDown | | Scroll wheel down
|
||||
WheelLeft | | Horizontal wheel left
|
||||
WheelRight | | Horizontal wheel right
|
||||
|
||||
## Usage
|
||||
|
||||
To create a tcell application, first initialize a screen to hold it.
|
||||
To create a _Tcell_ application, first initialize a screen to hold it.
|
||||
|
||||
```golang
|
||||
```go
|
||||
s, err := tcell.NewScreen()
|
||||
if err != nil {
|
||||
log.Fatalf("%+v", err)
|
||||
@ -105,7 +109,7 @@ s.Clear()
|
||||
|
||||
Text may be drawn on the screen using `SetContent`.
|
||||
|
||||
```golang
|
||||
```go
|
||||
s.SetContent(0, 0, 'H', nil, defStyle)
|
||||
s.SetContent(1, 0, 'i', nil, defStyle)
|
||||
s.SetContent(2, 0, '!', nil, defStyle)
|
||||
@ -113,7 +117,7 @@ s.SetContent(2, 0, '!', nil, defStyle)
|
||||
|
||||
To draw text more easily, define a render function.
|
||||
|
||||
```golang
|
||||
```go
|
||||
func drawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string) {
|
||||
row := y1
|
||||
col := x1
|
||||
@ -133,7 +137,7 @@ func drawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string
|
||||
|
||||
Lastly, define an event loop to handle user input and update application state.
|
||||
|
||||
```golang
|
||||
```go
|
||||
quit := func() {
|
||||
s.Fini()
|
||||
os.Exit(0)
|
||||
@ -161,13 +165,12 @@ for {
|
||||
|
||||
The following demonstrates how to initialize a screen, draw text/graphics and handle user input.
|
||||
|
||||
```golang
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
)
|
||||
@ -245,12 +248,29 @@ func main() {
|
||||
drawBox(s, 1, 1, 42, 7, boxStyle, "Click and drag to draw a box")
|
||||
drawBox(s, 5, 9, 32, 14, boxStyle, "Press C to reset")
|
||||
|
||||
quit := func() {
|
||||
// You have to catch panics in a defer, clean up, and
|
||||
// re-raise them - otherwise your application can
|
||||
// die without leaving any diagnostic trace.
|
||||
maybePanic := recover()
|
||||
s.Fini()
|
||||
if maybePanic != nil {
|
||||
panic(maybePanic)
|
||||
}
|
||||
}
|
||||
defer quit()
|
||||
|
||||
// Here's how to get the screen size when you need it.
|
||||
// xmax, ymax := s.Size()
|
||||
|
||||
// Here's an example of how to inject a keystroke where it will
|
||||
// be picked up by the next PollEvent call. Note that the
|
||||
// queue is LIFO, it has a limited length, and PostEvent() can
|
||||
// return an error.
|
||||
// s.PostEvent(tcell.NewEventKey(tcell.KeyRune, rune('a'), 0))
|
||||
|
||||
// Event loop
|
||||
ox, oy := -1, -1
|
||||
quit := func() {
|
||||
s.Fini()
|
||||
os.Exit(0)
|
||||
}
|
||||
for {
|
||||
// Update screen
|
||||
s.Show()
|
||||
@ -264,7 +284,7 @@ func main() {
|
||||
s.Sync()
|
||||
case *tcell.EventKey:
|
||||
if ev.Key() == tcell.KeyEscape || ev.Key() == tcell.KeyCtrlC {
|
||||
quit()
|
||||
return
|
||||
} else if ev.Key() == tcell.KeyCtrlL {
|
||||
s.Sync()
|
||||
} else if ev.Rune() == 'C' || ev.Rune() == 'c' {
|
||||
@ -272,14 +292,13 @@ func main() {
|
||||
}
|
||||
case *tcell.EventMouse:
|
||||
x, y := ev.Position()
|
||||
button := ev.Buttons()
|
||||
// Only process button events, not wheel events
|
||||
button &= tcell.ButtonMask(0xff)
|
||||
|
||||
if button != tcell.ButtonNone && ox < 0 {
|
||||
ox, oy = x, y
|
||||
}
|
||||
switch ev.Buttons() {
|
||||
case tcell.Button1, tcell.Button2:
|
||||
if ox < 0 {
|
||||
ox, oy = x, y // record location when click started
|
||||
}
|
||||
|
||||
case tcell.ButtonNone:
|
||||
if ox >= 0 {
|
||||
label := fmt.Sprintf("%d,%d to %d,%d", ox, oy, x, y)
|
||||
@ -291,3 +310,4 @@ func main() {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user