mirror of
https://github.com/gizak/termui.git
synced 2025-04-30 13:49:00 +08:00
Merge 2ab0428ad0dfb24d0a9ea9d6ce02ebff85d146b5 into f976fe697aa09b747f16fa6e08c36dde5fb16f27
This commit is contained in:
commit
4debfa6ea1
12
CHANGELOG.md
12
CHANGELOG.md
@ -81,7 +81,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Set `termbox-go` backend to 256 colors by default
|
- Set `termbox-go` backend to 256 colors by default
|
||||||
- Moved widgets to `github.com/gizak/termui/widgets`
|
- Moved widgets to `github.com/buahaha/termui/widgets`
|
||||||
- Rewrote widgets (check examples and code)
|
- Rewrote widgets (check examples and code)
|
||||||
- Rewrote grid
|
- Rewrote grid
|
||||||
- grids are instantiated locally instead of through `termui.Body`
|
- grids are instantiated locally instead of through `termui.Body`
|
||||||
@ -121,9 +121,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Rename Par widget to Paragraph
|
- Rename Par widget to Paragraph
|
||||||
- Rename MBarChart widget to StackedBarChart
|
- Rename MBarChart widget to StackedBarChart
|
||||||
|
|
||||||
[#237]: https://github.com/gizak/termui/pull/237
|
[#237]: https://github.com/buahaha/termui/pull/237
|
||||||
[#126]: https://github.com/gizak/termui/pull/126
|
[#126]: https://github.com/buahaha/termui/pull/126
|
||||||
|
|
||||||
[Unreleased]: https://github.com/gizak/termui/compare/v3.1.0...HEAD
|
[Unreleased]: https://github.com/buahaha/termui/compare/v3.1.0...HEAD
|
||||||
[3.1.0]: https://github.com/gizak/termui/compare/v3.0.0...v3.1.0
|
[3.1.0]: https://github.com/buahaha/termui/compare/v3.0.0...v3.1.0
|
||||||
[3.0.0]: https://github.com/gizak/termui/compare/v2.3.0...v3.0.0
|
[3.0.0]: https://github.com/buahaha/termui/compare/v2.3.0...v3.0.0
|
||||||
|
@ -20,7 +20,7 @@ It is not necessary to `go get` termui, since Go will automatically manage any i
|
|||||||
|
|
||||||
### Dep
|
### Dep
|
||||||
|
|
||||||
Add with `dep ensure -add github.com/gizak/termui`. With Dep, `/v3` should *not* be included in the import statements.
|
Add with `dep ensure -add github.com/buahaha/termui`. With Dep, `/v3` should *not* be included in the import statements.
|
||||||
|
|
||||||
## Hello World
|
## Hello World
|
||||||
|
|
||||||
@ -30,8 +30,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
ui "github.com/gizak/termui/v3"
|
ui "github.com/buahaha/termui/v3"
|
||||||
"github.com/gizak/termui/v3/widgets"
|
"github.com/buahaha/termui/v3/widgets"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -74,7 +74,7 @@ Run an example with `go run _examples/{example}.go` or run each example consecut
|
|||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
- [wiki](https://github.com/gizak/termui/wiki)
|
- [wiki](https://github.com/buahaha/termui/wiki)
|
||||||
|
|
||||||
## Uses
|
## Uses
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
ui "github.com/gizak/termui/v3"
|
ui "github.com/buahaha/termui/v3"
|
||||||
"github.com/gizak/termui/v3/widgets"
|
"github.com/buahaha/termui/v3/widgets"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
ui "github.com/gizak/termui/v3"
|
ui "github.com/buahaha/termui/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -11,8 +11,8 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
ui "github.com/gizak/termui/v3"
|
ui "github.com/buahaha/termui/v3"
|
||||||
"github.com/gizak/termui/v3/widgets"
|
"github.com/buahaha/termui/v3/widgets"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -37,7 +37,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
listData := []string{
|
listData := []string{
|
||||||
"[0] gizak/termui",
|
"[0] buahaha/termui",
|
||||||
"[1] editbox.go",
|
"[1] editbox.go",
|
||||||
"[2] interrupt.go",
|
"[2] interrupt.go",
|
||||||
"[3] keyboard.go",
|
"[3] keyboard.go",
|
||||||
|
@ -10,8 +10,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
ui "github.com/gizak/termui/v3"
|
ui "github.com/buahaha/termui/v3"
|
||||||
"github.com/gizak/termui/v3/widgets"
|
"github.com/buahaha/termui/v3/widgets"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -11,8 +11,8 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
ui "github.com/gizak/termui/v3"
|
ui "github.com/buahaha/termui/v3"
|
||||||
"github.com/gizak/termui/v3/widgets"
|
"github.com/buahaha/termui/v3/widgets"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -5,8 +5,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
ui "github.com/gizak/termui/v3"
|
ui "github.com/buahaha/termui/v3"
|
||||||
"github.com/gizak/termui/v3/widgets"
|
"github.com/buahaha/termui/v3/widgets"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -18,8 +18,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
ui "github.com/gizak/termui/v3"
|
ui "github.com/buahaha/termui/v3"
|
||||||
"github.com/gizak/termui/v3/widgets"
|
"github.com/buahaha/termui/v3/widgets"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -9,8 +9,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
ui "github.com/gizak/termui/v3"
|
ui "github.com/buahaha/termui/v3"
|
||||||
"github.com/gizak/termui/v3/widgets"
|
"github.com/buahaha/termui/v3/widgets"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -22,7 +22,7 @@ func main() {
|
|||||||
l := widgets.NewList()
|
l := widgets.NewList()
|
||||||
l.Title = "List"
|
l.Title = "List"
|
||||||
l.Rows = []string{
|
l.Rows = []string{
|
||||||
"[0] github.com/gizak/termui/v3",
|
"[0] github.com/buahaha/termui/v3",
|
||||||
"[1] [你好,世界](fg:blue)",
|
"[1] [你好,世界](fg:blue)",
|
||||||
"[2] [こんにちは世界](fg:red)",
|
"[2] [こんにちは世界](fg:red)",
|
||||||
"[3] [color](fg:white,bg:green) output",
|
"[3] [color](fg:white,bg:green) output",
|
||||||
|
@ -9,8 +9,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
ui "github.com/gizak/termui/v3"
|
ui "github.com/buahaha/termui/v3"
|
||||||
"github.com/gizak/termui/v3/widgets"
|
"github.com/buahaha/termui/v3/widgets"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -9,8 +9,8 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
ui "github.com/gizak/termui/v3"
|
ui "github.com/buahaha/termui/v3"
|
||||||
"github.com/gizak/termui/v3/widgets"
|
"github.com/buahaha/termui/v3/widgets"
|
||||||
)
|
)
|
||||||
|
|
||||||
var run = true
|
var run = true
|
||||||
|
@ -10,8 +10,8 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
ui "github.com/gizak/termui/v3"
|
ui "github.com/buahaha/termui/v3"
|
||||||
"github.com/gizak/termui/v3/widgets"
|
"github.com/buahaha/termui/v3/widgets"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -9,8 +9,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
ui "github.com/gizak/termui/v3"
|
ui "github.com/buahaha/termui/v3"
|
||||||
"github.com/gizak/termui/v3/widgets"
|
"github.com/buahaha/termui/v3/widgets"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -9,8 +9,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
ui "github.com/gizak/termui/v3"
|
ui "github.com/buahaha/termui/v3"
|
||||||
"github.com/gizak/termui/v3/widgets"
|
"github.com/buahaha/termui/v3/widgets"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -9,8 +9,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
ui "github.com/gizak/termui/v3"
|
ui "github.com/buahaha/termui/v3"
|
||||||
"github.com/gizak/termui/v3/widgets"
|
"github.com/buahaha/termui/v3/widgets"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -9,8 +9,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
ui "github.com/gizak/termui/v3"
|
ui "github.com/buahaha/termui/v3"
|
||||||
"github.com/gizak/termui/v3/widgets"
|
"github.com/buahaha/termui/v3/widgets"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -5,8 +5,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
ui "github.com/gizak/termui/v3"
|
ui "github.com/buahaha/termui/v3"
|
||||||
"github.com/gizak/termui/v3/widgets"
|
"github.com/buahaha/termui/v3/widgets"
|
||||||
)
|
)
|
||||||
|
|
||||||
type nodeValue string
|
type nodeValue string
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
ui "github.com/gizak/termui/v3"
|
ui "github.com/buahaha/termui/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// logs all events to the termui window
|
// logs all events to the termui window
|
||||||
|
@ -3,7 +3,7 @@ package termui
|
|||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
|
|
||||||
"github.com/gizak/termui/v3/drawille"
|
"github.com/buahaha/termui/v3/drawille"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Canvas struct {
|
type Canvas struct {
|
||||||
|
8
go.mod
8
go.mod
@ -1,9 +1,9 @@
|
|||||||
module github.com/gizak/termui/v3
|
module github.com/buahaha/termui/v3
|
||||||
|
|
||||||
go 1.15
|
go 1.15
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/mattn/go-runewidth v0.0.2
|
github.com/mattn/go-runewidth v0.0.12
|
||||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7
|
github.com/mitchellh/go-wordwrap v1.0.1
|
||||||
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d
|
github.com/nsf/termbox-go v1.1.0
|
||||||
)
|
)
|
||||||
|
9
theme.go
9
theme.go
@ -35,6 +35,7 @@ type RootTheme struct {
|
|||||||
List ListTheme
|
List ListTheme
|
||||||
Tree TreeTheme
|
Tree TreeTheme
|
||||||
Paragraph ParagraphTheme
|
Paragraph ParagraphTheme
|
||||||
|
Input InputTheme
|
||||||
PieChart PieChartTheme
|
PieChart PieChartTheme
|
||||||
Sparkline SparklineTheme
|
Sparkline SparklineTheme
|
||||||
StackedBarChart StackedBarChartTheme
|
StackedBarChart StackedBarChartTheme
|
||||||
@ -77,6 +78,10 @@ type ParagraphTheme struct {
|
|||||||
Text Style
|
Text Style
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type InputTheme struct {
|
||||||
|
Text Style
|
||||||
|
}
|
||||||
|
|
||||||
type PieChartTheme struct {
|
type PieChartTheme struct {
|
||||||
Slices []Color
|
Slices []Color
|
||||||
}
|
}
|
||||||
@ -121,6 +126,10 @@ var Theme = RootTheme{
|
|||||||
Text: NewStyle(ColorWhite),
|
Text: NewStyle(ColorWhite),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Input: InputTheme{
|
||||||
|
Text: NewStyle(ColorWhite),
|
||||||
|
},
|
||||||
|
|
||||||
PieChart: PieChartTheme{
|
PieChart: PieChartTheme{
|
||||||
Slices: StandardColors,
|
Slices: StandardColors,
|
||||||
},
|
},
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
rw "github.com/mattn/go-runewidth"
|
rw "github.com/mattn/go-runewidth"
|
||||||
|
|
||||||
. "github.com/gizak/termui/v3"
|
. "github.com/buahaha/termui/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BarChart struct {
|
type BarChart struct {
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
|
|
||||||
. "github.com/gizak/termui/v3"
|
. "github.com/buahaha/termui/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Gauge struct {
|
type Gauge struct {
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
. "github.com/gizak/termui/v3"
|
. "github.com/buahaha/termui/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Image struct {
|
type Image struct {
|
||||||
|
84
widgets/input.go
Normal file
84
widgets/input.go
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
// Copyright 2021 Szymon Błaszczyński <museyoucoulduse@gmail.com>. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT license that can
|
||||||
|
// be found in the LICENSE file.
|
||||||
|
|
||||||
|
package widgets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"image"
|
||||||
|
|
||||||
|
. "github.com/buahaha/termui/v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Input struct {
|
||||||
|
Block
|
||||||
|
Text string
|
||||||
|
TextStyle Style
|
||||||
|
WrapText bool
|
||||||
|
focusing bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create new Input widget. Somehow similar to Paragraph.
|
||||||
|
func NewInput() *Input {
|
||||||
|
return &Input{
|
||||||
|
Block: *NewBlock(),
|
||||||
|
TextStyle: Theme.Input.Text,
|
||||||
|
WrapText: true,
|
||||||
|
focusing: false,
|
||||||
|
Text: "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Input) Draw(buf *Buffer) {
|
||||||
|
self.Block.Draw(buf)
|
||||||
|
|
||||||
|
cells := ParseStyles(self.Text, self.TextStyle)
|
||||||
|
if self.WrapText {
|
||||||
|
cells = WrapCells(cells, uint(self.Inner.Dx()))
|
||||||
|
}
|
||||||
|
|
||||||
|
rows := SplitCells(cells, '\n')
|
||||||
|
|
||||||
|
for y, row := range rows {
|
||||||
|
if y+self.Inner.Min.Y >= self.Inner.Max.Y {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
row = TrimCells(row, self.Inner.Dx())
|
||||||
|
for _, cx := range BuildCellWithXArray(row) {
|
||||||
|
x, cell := cx.X, cx.Cell
|
||||||
|
buf.SetCell(cell, image.Pt(x, y).Add(self.Inner.Min))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Focus on input field and start typing.
|
||||||
|
// Best used with go routine 'go inputField.Focus()'
|
||||||
|
func (i *Input) Focus() {
|
||||||
|
i.focusing = true
|
||||||
|
Loop:
|
||||||
|
for {
|
||||||
|
events := PollEvents()
|
||||||
|
e := <-events
|
||||||
|
if e.Type == KeyboardEvent {
|
||||||
|
switch e.ID {
|
||||||
|
case "<Backspace>":
|
||||||
|
if len(i.Text) > 0 {
|
||||||
|
i.Text = i.Text[:len(i.Text)-1]
|
||||||
|
Render(i)
|
||||||
|
}
|
||||||
|
case "<Escape>", "C-c", "<Enter>":
|
||||||
|
i.focusing = false
|
||||||
|
break Loop
|
||||||
|
case "<Space>":
|
||||||
|
i.Text = i.Text + " "
|
||||||
|
Render(i)
|
||||||
|
case "<Tab>":
|
||||||
|
i.Text = i.Text + "\t"
|
||||||
|
Render(i)
|
||||||
|
default:
|
||||||
|
i.Text = i.Text + e.ID
|
||||||
|
Render(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
rw "github.com/mattn/go-runewidth"
|
rw "github.com/mattn/go-runewidth"
|
||||||
|
|
||||||
. "github.com/gizak/termui/v3"
|
. "github.com/buahaha/termui/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type List struct {
|
type List struct {
|
||||||
|
@ -7,7 +7,7 @@ package widgets
|
|||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
|
|
||||||
. "github.com/gizak/termui/v3"
|
. "github.com/buahaha/termui/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Paragraph struct {
|
type Paragraph struct {
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
. "github.com/gizak/termui/v3"
|
. "github.com/buahaha/termui/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
|
|
||||||
. "github.com/gizak/termui/v3"
|
. "github.com/buahaha/termui/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Plot has two modes: line(default) and scatter.
|
// Plot has two modes: line(default) and scatter.
|
||||||
|
@ -7,7 +7,7 @@ package widgets
|
|||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
|
|
||||||
. "github.com/gizak/termui/v3"
|
. "github.com/buahaha/termui/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Sparkline is like: ▅▆▂▂▅▇▂▂▃▆▆▆▅▃. The data points should be non-negative integers.
|
// Sparkline is like: ▅▆▂▂▅▇▂▂▃▆▆▆▅▃. The data points should be non-negative integers.
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
rw "github.com/mattn/go-runewidth"
|
rw "github.com/mattn/go-runewidth"
|
||||||
|
|
||||||
. "github.com/gizak/termui/v3"
|
. "github.com/buahaha/termui/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StackedBarChart struct {
|
type StackedBarChart struct {
|
||||||
|
@ -7,7 +7,7 @@ package widgets
|
|||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
|
|
||||||
. "github.com/gizak/termui/v3"
|
. "github.com/buahaha/termui/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*Table is like:
|
/*Table is like:
|
||||||
|
@ -7,7 +7,7 @@ package widgets
|
|||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
|
|
||||||
. "github.com/gizak/termui/v3"
|
. "github.com/buahaha/termui/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TabPane is a renderable widget which can be used to conditionally render certain tabs/views.
|
// TabPane is a renderable widget which can be used to conditionally render certain tabs/views.
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
. "github.com/gizak/termui/v3"
|
. "github.com/buahaha/termui/v3"
|
||||||
rw "github.com/mattn/go-runewidth"
|
rw "github.com/mattn/go-runewidth"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user