mirror of
https://github.com/mum4k/termdash.git
synced 2025-04-25 13:48:50 +08:00
Changing termbox to tcell in all examples.
parent
ec6b860e01
commit
343c08a74e
@ -26,7 +26,7 @@ The following code displays five bars with values 1 through 5 and the relative m
|
||||
|
||||
```go
|
||||
func main() {
|
||||
t, err := termbox.New()
|
||||
t, err := tcell.New()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -47,13 +47,13 @@ The **container.New** function is used to construct a container. The API of this
|
||||
To create the terminal layout indicated in the diagram above, the developer can use the following code:
|
||||
|
||||
```go
|
||||
tb, err := termbox.New()
|
||||
t, err := tcell.New()
|
||||
if err != nil {
|
||||
return fmt.Errorf("termbox.New => %v", err)
|
||||
return fmt.Errorf("tcell.New => %v", err)
|
||||
}
|
||||
|
||||
if _, err := container.New(
|
||||
tb,
|
||||
t,
|
||||
container.SplitVertical(
|
||||
container.Left(
|
||||
container.Border(linestyle.Light),
|
||||
@ -83,4 +83,4 @@ if _, err := container.New(
|
||||
|
||||
When executed, this results in the following terminal layout:
|
||||
|
||||
[[/images/container-api/container_splits_actual.png|container_splits_actual]]
|
||||
[[/images/container-api/container_splits_actual.png|container_splits_actual]]
|
||||
|
@ -11,11 +11,11 @@ Containers don't have any borders by default, use one of the following options t
|
||||
The following code shows two containers with different border styles as shown above. The right container has the keyboard focus so its border is highlighted.
|
||||
|
||||
```go
|
||||
tb, err := termbox.New()
|
||||
t, err := tcell.New()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer tb.Close()
|
||||
defer t.Close()
|
||||
|
||||
c, err := container.New(
|
||||
t,
|
||||
@ -54,11 +54,11 @@ Containers that have a border can also have a text title displayed in the border
|
||||
The following code shows a container with a title in the border that is aligned to the right.
|
||||
|
||||
```go
|
||||
tb, err := termbox.New()
|
||||
t, err := tcell.New()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer tb.Close()
|
||||
defer t.Close()
|
||||
|
||||
c, err := container.New(
|
||||
t,
|
||||
@ -85,4 +85,4 @@ The **container.BorderTitleAlignCenter** option indicates that the container tit
|
||||
|
||||
### [container.BorderTitleAlignRight](https://godoc.org/github.com/mum4k/termdash/container#BorderTitleAlignRight):
|
||||
|
||||
The **container.BorderTitleAlignRight** option indicates that the container title should be aligned at the top right corner.
|
||||
The **container.BorderTitleAlignRight** option indicates that the container title should be aligned at the top right corner.
|
||||
|
@ -29,11 +29,11 @@ The **Container.Update** method applies the specified options to a container wit
|
||||
The following code places a button widget inside a container and then updates the container by replacing the button with a text widget:
|
||||
|
||||
```go
|
||||
tb, err := termbox.New()
|
||||
t, err := tcell.New()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer tb.Close()
|
||||
defer t.Close()
|
||||
|
||||
b, err := button.New("hello world", func() error {
|
||||
return nil
|
||||
@ -69,11 +69,11 @@ When container is updated by adding a new split, any previously placed widgets o
|
||||
The following code places a button widget inside a container and then updates the container by splitting it into two and placing a button and a text widget:
|
||||
|
||||
```go
|
||||
tb, err := termbox.New()
|
||||
t, err := tcell.New()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer tb.Close()
|
||||
defer t.Close()
|
||||
|
||||
b, err := button.New("hello world", func() error {
|
||||
return nil
|
||||
@ -110,4 +110,4 @@ if err := c.Update(
|
||||
); err != nil {
|
||||
return fmt.Errorf("c.Update => %v", err)
|
||||
}
|
||||
```
|
||||
```
|
||||
|
@ -52,9 +52,9 @@ The **grid.New** function is used to construct a **grid.Builder** instance. The
|
||||
To create the terminal layout indicated in the diagram above, the developer can use the following code:
|
||||
|
||||
```go
|
||||
tb, err := termbox.New()
|
||||
t, err := tcell.New()
|
||||
if err != nil {
|
||||
return fmt.Errorf("termbox.New => %v", err)
|
||||
return fmt.Errorf("tcell.New => %v", err)
|
||||
}
|
||||
|
||||
b, err := button.New("button", func() error {
|
||||
@ -107,4 +107,4 @@ if err != nil {
|
||||
|
||||
When executed, this results in the following terminal layout:
|
||||
|
||||
[[/images/grid-api/grid_actual.png|grid_actual]]
|
||||
[[/images/grid-api/grid_actual.png|grid_actual]]
|
||||
|
@ -55,9 +55,9 @@ The **right** and **left** values are specified as percentage of the container's
|
||||
The following code snippet demonstrates application and effect of margin and padding. The left container has both margin and padding applied. The right container has none of these options. Both containers contain a single button and have a border.
|
||||
|
||||
```go
|
||||
t, err := termbox.New()
|
||||
t, err := tcell.New()
|
||||
if err != nil {
|
||||
return fmt.Errorf("termbox.New => %v", err)
|
||||
return fmt.Errorf("tcell.New => %v", err)
|
||||
}
|
||||
defer t.Close()
|
||||
|
||||
@ -107,4 +107,4 @@ if err != nil {
|
||||
|
||||
The code above results in the following layout:
|
||||
|
||||
[[/images/container-api/container_margin_padding_actual.png|container_margin_padding_actual]]
|
||||
[[/images/container-api/container_margin_padding_actual.png|container_margin_padding_actual]]
|
||||
|
@ -22,11 +22,11 @@ The **container.PlaceWidget** option places the provided widget into the contain
|
||||
The following code places a button widget inside a container as shown above:
|
||||
|
||||
```go
|
||||
tb, err := termbox.New()
|
||||
t, err := tcell.New()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer tb.Close()
|
||||
defer t.Close()
|
||||
|
||||
b, err := button.New("hello world", func() error {
|
||||
return nil
|
||||
@ -55,11 +55,11 @@ horizontally and vertically.
|
||||
The following code aligns the button widget into the top right corner as shown above:
|
||||
|
||||
```go
|
||||
tb, err := termbox.New()
|
||||
t, err := tcell.New()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer tb.Close()
|
||||
defer t.Close()
|
||||
|
||||
b, err := button.New("hello world", func() error {
|
||||
return nil
|
||||
@ -86,4 +86,4 @@ The **container.AlignHorizontal** option is used to specify horizontal alignment
|
||||
|
||||
### [container.AlignVertical](https://godoc.org/github.com/mum4k/termdash/container#AlignVertical)
|
||||
|
||||
The **container.AlignVertical** option is used to specify vertical alignment for the widget. Refer to the [[Align API|align-api]] for alignment options.
|
||||
The **container.AlignVertical** option is used to specify vertical alignment for the widget. Refer to the [[Align API|align-api]] for alignment options.
|
||||
|
@ -40,9 +40,9 @@ The following code snippet starts Termdash with an empty container and no widget
|
||||
|
||||
```go
|
||||
// Create the terminal.
|
||||
t, err := termbox.New()
|
||||
t, err := tcell.New()
|
||||
if err != nil {
|
||||
return fmt.Errorf("termbox.New => %v", err)
|
||||
return fmt.Errorf("tcell.New => %v", err)
|
||||
}
|
||||
defer t.Close()
|
||||
|
||||
@ -81,9 +81,9 @@ The following code snippet starts Termdash with an empty container and no widget
|
||||
|
||||
```go
|
||||
// Create the terminal.
|
||||
t, err := termbox.New()
|
||||
t, err := tcell.New()
|
||||
if err != nil {
|
||||
return fmt.Errorf("termbox.New => %v", err)
|
||||
return fmt.Errorf("tcell.New => %v", err)
|
||||
}
|
||||
defer t.Close()
|
||||
|
||||
@ -184,4 +184,4 @@ quitter := func(m *terminalapi.Mouse) {
|
||||
if err := termdash.Run(ctx, t, c, termdash.MouseSubscriber(quitter)); err != nil {
|
||||
return fmt.Errorf("termdash.Run => %v", err)
|
||||
}
|
||||
```
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user