Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
Trevor Slocum | b06b07dadb |
23
CHANGELOG
23
CHANGELOG
|
@ -1,23 +1,10 @@
|
|||
v1.5.9 (2022-02-02)
|
||||
- Fix unlocking application mutex when failing to initialize the screen
|
||||
- Fix DropDown.SetCurrentOption Unlock of unlocked RWMutex panic
|
||||
|
||||
v1.5.8 (2022-08-01)
|
||||
- Add TabbedPanels.SetChangedFunc
|
||||
- Add DropDown.SetDropDownSelectedSymbolRune (PR by gdamore)
|
||||
- Add List.SetIndicators (PR by gdamore)
|
||||
- Fix some missing ANSI translations
|
||||
|
||||
v1.5.7 (2021-09-01)
|
||||
- Add Application.HandlePanic
|
||||
v1.5.7 (WIP)
|
||||
- Add Modal.SetButtonsAlign and Modal.SetTextAlign
|
||||
- Fix Application.QueueEvent
|
||||
- Fix TextView.GetRegionText error when text contains color tags
|
||||
- Fix TextView region tags when placed at the end of a line
|
||||
- Do not customize Modal window styling by default (use GetForm and GetFrame to customize)
|
||||
- Draw application after updating root primitive via Application.SetRoot
|
||||
|
||||
v1.5.6 (2021-07-08)
|
||||
v1.5.6 (2020-07-08)
|
||||
- Add TrueColorTags option and do not use TrueColor tag values by default
|
||||
- Add TextView.SetHighlightForegroundColor and TextView.SetHighlightBackgroundColor
|
||||
- Add TextView.SetVerticalAlign
|
||||
|
@ -37,14 +24,14 @@ primitives to draw instead of the whole screen
|
|||
- When resetting color with "-" tag, set background color to primitive
|
||||
background color, rather than the terminal background color
|
||||
|
||||
v1.5.5 (2021-05-24)
|
||||
v1.5.5 (2020-05-24)
|
||||
- Fix Application.Suspend by restructuring event loop (queued updates will now only run between draws)
|
||||
|
||||
v1.5.4 (2021-04-03)
|
||||
v1.5.4 (2020-04-03)
|
||||
- Add TextView.GetBufferSize
|
||||
- Fix strikethrough support
|
||||
|
||||
v1.5.3 (2021-01-14)
|
||||
v1.5.3 (2020-01-14)
|
||||
- Document how to prevent screen artifacts when using SetBackgroundTransparent
|
||||
- Fix highlighting focused Form element
|
||||
- Fix incorrect TabbedPanels colors
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
# cview - Terminal-based user interface toolkit
|
||||
[![GoDoc](https://code.rocketnine.space/tslocum/godoc-static/raw/branch/master/badge.svg)](https://docs.rocketnine.space/code.rocketnine.space/tslocum/cview)
|
||||
[![Donate via LiberaPay](https://img.shields.io/liberapay/receives/rocketnine.space.svg?logo=liberapay)](https://liberapay.com/rocketnine.space)
|
||||
[![Donate via Patreon](https://img.shields.io/badge/dynamic/json?color=%23e85b46&label=Patreon&query=data.attributes.patron_count&suffix=%20patrons&url=https%3A%2F%2Fwww.patreon.com%2Fapi%2Fcampaigns%2F5252223)](https://www.patreon.com/rocketnine)
|
||||
[![Donate](https://img.shields.io/liberapay/receives/rocketnine.space.svg?logo=liberapay)](https://liberapay.com/rocketnine.space)
|
||||
|
||||
This package is a fork of [tview](https://github.com/rivo/tview).
|
||||
See [FORK.md](https://code.rocketnine.space/tslocum/cview/src/branch/master/FORK.md) for more information.
|
||||
|
|
12
ansi.go
12
ansi.go
|
@ -135,10 +135,6 @@ func (a *ansi) Write(text []byte) (int, error) {
|
|||
if strings.IndexRune(a.attributes, 'd') < 0 {
|
||||
a.attributes += "d"
|
||||
}
|
||||
case "3", "03":
|
||||
if strings.IndexRune(a.attributes, 'i') < 0 {
|
||||
a.attributes += "i"
|
||||
}
|
||||
case "4", "04":
|
||||
if strings.IndexRune(a.attributes, 'u') < 0 {
|
||||
a.attributes += "u"
|
||||
|
@ -147,14 +143,6 @@ func (a *ansi) Write(text []byte) (int, error) {
|
|||
if strings.IndexRune(a.attributes, 'l') < 0 {
|
||||
a.attributes += "l"
|
||||
}
|
||||
case "7", "07":
|
||||
if strings.IndexRune(a.attributes, 'r') < 0 {
|
||||
a.attributes += "r"
|
||||
}
|
||||
case "9", "09":
|
||||
if strings.IndexRune(a.attributes, 's') < 0 {
|
||||
a.attributes += "s"
|
||||
}
|
||||
case "22":
|
||||
if i := strings.IndexRune(a.attributes, 'b'); i >= 0 {
|
||||
a.attributes = a.attributes[:i] + a.attributes[i+1:]
|
||||
|
|
|
@ -25,9 +25,9 @@ const (
|
|||
// The following command displays a primitive p on the screen until Ctrl-C is
|
||||
// pressed:
|
||||
//
|
||||
// if err := cview.NewApplication().SetRoot(p, true).Run(); err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// if err := cview.NewApplication().SetRoot(p, true).Run(); err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
type Application struct {
|
||||
// The application's screen. Apart from Run(), this variable should never be
|
||||
// set directly. Always use the screenReplacement channel after calling
|
||||
|
@ -125,23 +125,6 @@ func NewApplication() *Application {
|
|||
}
|
||||
}
|
||||
|
||||
// HandlePanic (when deferred at the start of a goroutine) handles panics
|
||||
// gracefully. The terminal is returned to its original state before the panic
|
||||
// message is printed.
|
||||
//
|
||||
// Panics may only be handled by the panicking goroutine. Because of this,
|
||||
// HandlePanic must be deferred at the start of each goroutine (including main).
|
||||
func (a *Application) HandlePanic() {
|
||||
p := recover()
|
||||
if p == nil {
|
||||
return
|
||||
}
|
||||
|
||||
a.finalizeScreen()
|
||||
|
||||
panic(p)
|
||||
}
|
||||
|
||||
// SetInputCapture sets a function which captures all key events before they are
|
||||
// forwarded to the key event handler of the primitive which currently has
|
||||
// focus. This function can then choose to forward that key event (or a
|
||||
|
@ -251,9 +234,11 @@ func (a *Application) init() error {
|
|||
var err error
|
||||
a.screen, err = tcell.NewScreen()
|
||||
if err != nil {
|
||||
a.Unlock()
|
||||
return err
|
||||
}
|
||||
if err = a.screen.Init(); err != nil {
|
||||
a.Unlock()
|
||||
return err
|
||||
}
|
||||
a.width, a.height = a.screen.Size()
|
||||
|
@ -302,11 +287,18 @@ func (a *Application) Run() error {
|
|||
// Initialize screen
|
||||
err := a.init()
|
||||
if err != nil {
|
||||
a.Unlock()
|
||||
return err
|
||||
}
|
||||
|
||||
defer a.HandlePanic()
|
||||
// We catch panics to clean up because they mess up the terminal.
|
||||
defer func() {
|
||||
if p := recover(); p != nil {
|
||||
if a.screen != nil {
|
||||
a.screen.Fini()
|
||||
}
|
||||
panic(p)
|
||||
}
|
||||
}()
|
||||
|
||||
// Draw the screen for the first time.
|
||||
a.Unlock()
|
||||
|
@ -316,8 +308,6 @@ func (a *Application) Run() error {
|
|||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer a.HandlePanic()
|
||||
|
||||
defer wg.Done()
|
||||
for {
|
||||
a.RLock()
|
||||
|
@ -441,8 +431,6 @@ func (a *Application) Run() error {
|
|||
semaphore := &sync.Mutex{}
|
||||
|
||||
go func() {
|
||||
defer a.HandlePanic()
|
||||
|
||||
for update := range a.updates {
|
||||
semaphore.Lock()
|
||||
update()
|
||||
|
@ -450,16 +438,6 @@ func (a *Application) Run() error {
|
|||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
defer a.HandlePanic()
|
||||
|
||||
for event := range a.events {
|
||||
semaphore.Lock()
|
||||
handle(event)
|
||||
semaphore.Unlock()
|
||||
}
|
||||
}()
|
||||
|
||||
// Start screen event loop.
|
||||
for {
|
||||
a.Lock()
|
||||
|
@ -592,18 +570,13 @@ func (a *Application) Stop() {
|
|||
a.Lock()
|
||||
defer a.Unlock()
|
||||
|
||||
a.finalizeScreen()
|
||||
a.screenReplacement <- nil
|
||||
}
|
||||
|
||||
func (a *Application) finalizeScreen() {
|
||||
screen := a.screen
|
||||
if screen == nil {
|
||||
return
|
||||
}
|
||||
|
||||
a.screen = nil
|
||||
screen.Fini()
|
||||
a.screenReplacement <- nil
|
||||
}
|
||||
|
||||
// Suspend temporarily suspends the application by exiting terminal UI mode and
|
||||
|
@ -761,7 +734,7 @@ func (a *Application) GetAfterDrawFunc() func(screen tcell.Screen) {
|
|||
// This function must be called at least once or nothing will be displayed when
|
||||
// the application starts.
|
||||
//
|
||||
// It also calls SetFocus() on the primitive and draws the application.
|
||||
// It also calls SetFocus() on the primitive.
|
||||
func (a *Application) SetRoot(root Primitive, fullscreen bool) {
|
||||
a.Lock()
|
||||
a.root = root
|
||||
|
@ -772,8 +745,6 @@ func (a *Application) SetRoot(root Primitive, fullscreen bool) {
|
|||
a.Unlock()
|
||||
|
||||
a.SetFocus(root)
|
||||
|
||||
a.Draw()
|
||||
}
|
||||
|
||||
// ResizeToFullScreen resizes the given primitive such that it fills the entire
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
box := cview.NewBox()
|
||||
box.SetBorder(true)
|
||||
|
|
|
@ -5,8 +5,6 @@ import "code.rocketnine.space/tslocum/cview"
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
app.EnableMouse(true)
|
||||
|
||||
button := cview.NewButton("Hit Enter to close")
|
||||
|
|
|
@ -7,8 +7,6 @@ import (
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
app.EnableMouse(true)
|
||||
|
||||
checkbox := cview.NewCheckBox()
|
||||
|
|
|
@ -5,8 +5,6 @@ import "code.rocketnine.space/tslocum/cview"
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
app.EnableMouse(true)
|
||||
|
||||
dropdown := cview.NewDropDown()
|
||||
|
|
|
@ -14,8 +14,6 @@ func demoBox(title string) *cview.Box {
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
app.EnableMouse(true)
|
||||
|
||||
subFlex := cview.NewFlex()
|
||||
|
|
|
@ -18,8 +18,6 @@ func wrap(f func()) func(ev *tcell.EventKey) *tcell.EventKey {
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
app.EnableMouse(true)
|
||||
|
||||
input1 := cview.NewInputField()
|
||||
|
|
|
@ -7,8 +7,6 @@ import (
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
app.EnableMouse(true)
|
||||
|
||||
form := cview.NewForm()
|
||||
|
|
|
@ -8,8 +8,6 @@ import (
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
app.EnableMouse(true)
|
||||
|
||||
box := cview.NewBox()
|
||||
|
|
|
@ -7,8 +7,6 @@ import (
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
app.EnableMouse(true)
|
||||
|
||||
newPrimitive := func(text string) cview.Primitive {
|
||||
|
|
|
@ -12,7 +12,6 @@ const wordList = "ability,able,about,above,accept,according,account,across,act,a
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
words := strings.Split(wordList, ",")
|
||||
|
||||
|
|
|
@ -17,8 +17,6 @@ type company struct {
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
inputField := cview.NewInputField()
|
||||
inputField.SetLabel("Enter a company name: ")
|
||||
inputField.SetFieldWidth(30)
|
||||
|
|
|
@ -8,8 +8,6 @@ import (
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
app.EnableMouse(true)
|
||||
|
||||
inputField := cview.NewInputField()
|
||||
|
|
|
@ -9,8 +9,6 @@ import (
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
app.EnableMouse(true)
|
||||
|
||||
list := cview.NewList()
|
||||
|
|
|
@ -7,8 +7,6 @@ import (
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
app.EnableMouse(true)
|
||||
|
||||
modal := cview.NewModal()
|
||||
|
|
|
@ -11,8 +11,6 @@ const panelCount = 5
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
app.EnableMouse(true)
|
||||
|
||||
panels := cview.NewPanels()
|
||||
|
|
|
@ -43,8 +43,6 @@ var app = cview.NewApplication()
|
|||
|
||||
// Starting point for the presentation.
|
||||
func main() {
|
||||
defer app.HandlePanic()
|
||||
|
||||
var debugPort int
|
||||
flag.IntVar(&debugPort, "debug", 0, "port to serve debug info")
|
||||
flag.Parse()
|
||||
|
|
|
@ -61,7 +61,6 @@ func (r *RadioButtons) InputHandler() func(event *tcell.EventKey, setFocus func(
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
radioButtons := NewRadioButtons([]string{"Lions", "Elephants", "Giraffes"})
|
||||
radioButtons.SetBorder(true)
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
grid := cview.NewGrid()
|
||||
grid.SetColumns(-1, 6, 4, 30, -1)
|
||||
|
|
|
@ -11,8 +11,6 @@ const panelCount = 5
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
app.EnableMouse(true)
|
||||
|
||||
panels := cview.NewTabbedPanels()
|
||||
|
|
|
@ -12,8 +12,6 @@ const loremIpsumText = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
app.EnableMouse(true)
|
||||
|
||||
table := cview.NewTable()
|
||||
|
|
|
@ -21,8 +21,6 @@ Capitalize on low hanging fruit to identify a ballpark value added activity to b
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
app.EnableMouse(true)
|
||||
|
||||
textView := cview.NewTextView()
|
||||
|
|
|
@ -12,8 +12,6 @@ import (
|
|||
// Show a navigable tree view of the current directory.
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
app.EnableMouse(true)
|
||||
|
||||
rootDir := "."
|
||||
|
|
|
@ -9,8 +9,6 @@ import (
|
|||
|
||||
func main() {
|
||||
app := cview.NewApplication()
|
||||
defer app.HandlePanic()
|
||||
|
||||
panels := cview.NewPanels()
|
||||
|
||||
form := cview.NewForm()
|
||||
|
|
|
@ -10,8 +10,6 @@ import (
|
|||
func ExampleNewApplication() {
|
||||
// Initialize application.
|
||||
app := NewApplication()
|
||||
// Handle panics gracefully.
|
||||
defer app.HandlePanic()
|
||||
|
||||
// Create shared TextView.
|
||||
sharedTextView := NewTextView()
|
||||
|
@ -73,8 +71,6 @@ func ExampleNewApplication() {
|
|||
func ExampleApplication_EnableMouse() {
|
||||
// Initialize application.
|
||||
app := NewApplication()
|
||||
// Handle panics gracefully.
|
||||
defer app.HandlePanic()
|
||||
|
||||
// Enable mouse support.
|
||||
app.EnableMouse(true)
|
||||
|
|
28
dropdown.go
28
dropdown.go
|
@ -140,9 +140,6 @@ type DropDown struct {
|
|||
// The symbol to draw at the end of the field when opened.
|
||||
dropDownOpenSymbol rune
|
||||
|
||||
// The symbol used to draw the selected item when opened.
|
||||
dropDownSelectedSymbol rune
|
||||
|
||||
// A flag that determines whether the drop down symbol is always drawn.
|
||||
alwaysDrawDropDownSymbol bool
|
||||
|
||||
|
@ -169,16 +166,12 @@ func NewDropDown() *DropDown {
|
|||
prefixTextColor: Styles.ContrastSecondaryTextColor,
|
||||
dropDownSymbol: Styles.DropDownSymbol,
|
||||
dropDownOpenSymbol: Styles.DropDownOpenSymbol,
|
||||
dropDownSelectedSymbol: Styles.DropDownSelectedSymbol,
|
||||
abbreviationChars: Styles.DropDownAbbreviationChars,
|
||||
labelColorFocused: ColorUnset,
|
||||
fieldBackgroundColorFocused: ColorUnset,
|
||||
fieldTextColorFocused: ColorUnset,
|
||||
}
|
||||
|
||||
if sym := d.dropDownSelectedSymbol; sym != 0 {
|
||||
list.SetIndicators(" "+string(sym)+" ", "", " ", "")
|
||||
}
|
||||
d.focus = d
|
||||
|
||||
return d
|
||||
|
@ -198,21 +191,6 @@ func (d *DropDown) SetDropDownOpenSymbolRune(symbol rune) {
|
|||
d.Lock()
|
||||
defer d.Unlock()
|
||||
d.dropDownOpenSymbol = symbol
|
||||
|
||||
if symbol != 0 {
|
||||
d.list.SetIndicators(" "+string(symbol)+" ", "", " ", "")
|
||||
} else {
|
||||
d.list.SetIndicators("", "", "", "")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// SetDropDownSelectedSymbolRune sets the rune to be drawn at the start of the
|
||||
// selected list item.
|
||||
func (d *DropDown) SetDropDownSelectedSymbolRune(symbol rune) {
|
||||
d.Lock()
|
||||
defer d.Unlock()
|
||||
d.dropDownSelectedSymbol = symbol
|
||||
}
|
||||
|
||||
// SetAlwaysDrawDropDownSymbol sets a flad that determines whether the drop
|
||||
|
@ -228,6 +206,8 @@ func (d *DropDown) SetAlwaysDrawDropDownSymbol(alwaysDraw bool) {
|
|||
// this function will also trigger the "selected" callback (if there is one).
|
||||
func (d *DropDown) SetCurrentOption(index int) {
|
||||
d.Lock()
|
||||
defer d.Unlock()
|
||||
|
||||
if index >= 0 && index < len(d.options) {
|
||||
d.currentOption = index
|
||||
d.list.SetCurrentItem(index)
|
||||
|
@ -250,7 +230,6 @@ func (d *DropDown) SetCurrentOption(index int) {
|
|||
d.Lock()
|
||||
}
|
||||
}
|
||||
d.Unlock()
|
||||
}
|
||||
|
||||
// GetCurrentOption returns the index of the currently selected option as well
|
||||
|
@ -436,8 +415,7 @@ func (d *DropDown) getFieldWidth() int {
|
|||
}
|
||||
fieldWidth += len(d.optionPrefix) + len(d.optionSuffix)
|
||||
fieldWidth += len(d.currentOptionPrefix) + len(d.currentOptionSuffix)
|
||||
// space <text> space + dropDownSymbol + space
|
||||
fieldWidth += 4
|
||||
fieldWidth += 3 // space + dropDownSymbol + space
|
||||
return fieldWidth
|
||||
}
|
||||
|
||||
|
|
10
go.mod
10
go.mod
|
@ -4,9 +4,11 @@ go 1.12
|
|||
|
||||
require (
|
||||
code.rocketnine.space/tslocum/cbind v0.1.5
|
||||
github.com/gdamore/tcell/v2 v2.7.0
|
||||
github.com/gdamore/tcell/v2 v2.4.0
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0
|
||||
github.com/mattn/go-runewidth v0.0.15
|
||||
github.com/rivo/uniseg v0.4.6
|
||||
golang.org/x/term v0.16.0 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.13
|
||||
github.com/rivo/uniseg v0.2.0
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
|
||||
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
|
||||
golang.org/x/text v0.3.6 // indirect
|
||||
)
|
||||
|
|
52
go.sum
52
go.sum
|
@ -3,58 +3,28 @@ code.rocketnine.space/tslocum/cbind v0.1.5/go.mod h1:LtfqJTzM7qhg88nAvNhx+VnTjZ0
|
|||
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
|
||||
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
|
||||
github.com/gdamore/tcell/v2 v2.2.0/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU=
|
||||
github.com/gdamore/tcell/v2 v2.7.0 h1:I5LiGTQuwrysAt1KS9wg1yFfOI3arI3ucFrxtd/xqaA=
|
||||
github.com/gdamore/tcell/v2 v2.7.0/go.mod h1:hl/KtAANGBecfIPxk+FzKvThTqI84oplgbPEmVX60b8=
|
||||
github.com/gdamore/tcell/v2 v2.4.0 h1:W6dxJEmaxYvhICFoTY3WrLLEXsQ11SaFnKGVEXW57KM=
|
||||
github.com/gdamore/tcell/v2 v2.4.0/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU=
|
||||
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
|
||||
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/rivo/uniseg v0.4.6 h1:Sovz9sDSwbOz9tgUy8JpT+KgCkPYJEN/oYzlJiYTNLg=
|
||||
github.com/rivo/uniseg v0.4.6/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210309040221-94ec62e08169/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
|
||||
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
|
||||
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
|
||||
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
|
||||
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b h1:9zKuko04nR4gjZ4+DNjHqRlAJqbJETHwiNKDqTfOjfE=
|
||||
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
|
49
list.go
49
list.go
|
@ -194,15 +194,6 @@ type List struct {
|
|||
// The height of the list the last time it was drawn.
|
||||
height int
|
||||
|
||||
// Prefix and suffix strings drawn for unselected elements.
|
||||
unselectedPrefix, unselectedSuffix []byte
|
||||
|
||||
// Prefix and suffix strings drawn for selected elements.
|
||||
selectedPrefix, selectedSuffix []byte
|
||||
|
||||
// Maximum prefix and suffix width.
|
||||
prefixWidth, suffixWidth int
|
||||
|
||||
sync.RWMutex
|
||||
}
|
||||
|
||||
|
@ -636,24 +627,6 @@ func (l *List) SetItemEnabled(index int, enabled bool) {
|
|||
item.disabled = !enabled
|
||||
}
|
||||
|
||||
// SetIndicators is used to set prefix and suffix indicators for selected and unselected items.
|
||||
func (l *List) SetIndicators(selectedPrefix, selectedSuffix, unselectedPrefix, unselectedSuffix string) {
|
||||
l.Lock()
|
||||
defer l.Unlock()
|
||||
l.selectedPrefix = []byte(selectedPrefix)
|
||||
l.selectedSuffix = []byte(selectedSuffix)
|
||||
l.unselectedPrefix = []byte(unselectedPrefix)
|
||||
l.unselectedSuffix = []byte(unselectedSuffix)
|
||||
l.prefixWidth = len(selectedPrefix)
|
||||
if len(unselectedPrefix) > l.prefixWidth {
|
||||
l.prefixWidth = len(unselectedPrefix)
|
||||
}
|
||||
l.suffixWidth = len(selectedSuffix)
|
||||
if len(unselectedSuffix) > l.suffixWidth {
|
||||
l.suffixWidth = len(unselectedSuffix)
|
||||
}
|
||||
}
|
||||
|
||||
// FindItems searches the main and secondary texts for the given strings and
|
||||
// returns a list of item indices in which those strings are found. One of the
|
||||
// two search strings may be empty, it will then be ignored. Indices are always
|
||||
|
@ -893,7 +866,7 @@ func (l *List) Draw(screen tcell.Screen) {
|
|||
// Determine the dimensions.
|
||||
x, y, width, height := l.GetInnerRect()
|
||||
leftEdge := x
|
||||
fullWidth := width + l.paddingLeft + l.paddingRight + l.prefixWidth + l.suffixWidth
|
||||
fullWidth := width + l.paddingLeft + l.paddingRight
|
||||
bottomLimit := y + height
|
||||
|
||||
l.height = height
|
||||
|
@ -961,25 +934,7 @@ func (l *List) Draw(screen tcell.Screen) {
|
|||
RenderScrollBar(screen, l.scrollBarVisibility, scrollBarX, y, scrollBarHeight, len(l.items), scrollBarCursor, index-l.itemOffset, l.hasFocus, l.scrollBarColor)
|
||||
y++
|
||||
continue
|
||||
}
|
||||
|
||||
if index == l.currentItem {
|
||||
if len(l.selectedPrefix) > 0 {
|
||||
mainText = append(l.selectedPrefix, mainText...)
|
||||
}
|
||||
if len(l.selectedSuffix) > 0 {
|
||||
mainText = append(mainText, l.selectedSuffix...)
|
||||
}
|
||||
|
||||
} else {
|
||||
if len(l.unselectedPrefix) > 0 {
|
||||
mainText = append(l.unselectedPrefix, mainText...)
|
||||
}
|
||||
if len(l.unselectedSuffix) > 0 {
|
||||
mainText = append(mainText, l.unselectedSuffix...)
|
||||
}
|
||||
}
|
||||
if item.disabled {
|
||||
} else if item.disabled {
|
||||
// Shortcuts.
|
||||
if showShortcuts && item.shortcut != 0 {
|
||||
Print(screen, []byte(fmt.Sprintf("(%c)", item.shortcut)), x-5, y, 4, AlignRight, tcell.ColorDarkSlateGray.TrueColor())
|
||||
|
|
|
@ -39,7 +39,6 @@ type Theme struct {
|
|||
DropDownAbbreviationChars string // The chars to show when the option's text gets shortened.
|
||||
DropDownSymbol rune // The symbol to draw at the end of the field when closed.
|
||||
DropDownOpenSymbol rune // The symbol to draw at the end of the field when opened.
|
||||
DropDownSelectedSymbol rune // The symbol to draw to indicate the selected list item.
|
||||
|
||||
// Scroll bar
|
||||
ScrollBarColor tcell.Color
|
||||
|
@ -81,7 +80,6 @@ var Styles = Theme{
|
|||
DropDownAbbreviationChars: "...",
|
||||
DropDownSymbol: '◀',
|
||||
DropDownOpenSymbol: '▼',
|
||||
DropDownSelectedSymbol: '▶',
|
||||
|
||||
ScrollBarColor: tcell.ColorWhite.TrueColor(),
|
||||
|
||||
|
|
|
@ -69,12 +69,6 @@ func NewTabbedPanels() *TabbedPanels {
|
|||
return t
|
||||
}
|
||||
|
||||
// SetChangedFunc sets a handler which is called whenever a tab is added,
|
||||
// selected, reordered or removed.
|
||||
func (t *TabbedPanels) SetChangedFunc(handler func()) {
|
||||
t.panels.SetChangedFunc(handler)
|
||||
}
|
||||
|
||||
// AddTab adds a new tab. Tab names should consist only of letters, numbers
|
||||
// and spaces.
|
||||
func (t *TabbedPanels) AddTab(name, label string, item Primitive) {
|
||||
|
|
1
util.go
1
util.go
|
@ -86,7 +86,6 @@ const (
|
|||
// Package initialization.
|
||||
func init() {
|
||||
runewidth.EastAsianWidth = true
|
||||
runewidth.CreateLUT() // Create lookup table
|
||||
|
||||
// Initialize the predefined input field handlers.
|
||||
InputFieldInteger = func(text string, ch rune) bool {
|
||||
|
|
60
util_test.go
60
util_test.go
|
@ -1,7 +1,11 @@
|
|||
package cview
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/mattn/go-runewidth"
|
||||
)
|
||||
|
||||
// newTestApp returns a new application connected to a simulation screen.
|
||||
|
@ -17,3 +21,59 @@ func newTestApp(root Primitive) (*Application, error) {
|
|||
|
||||
return app, nil
|
||||
}
|
||||
|
||||
func TestWordWrap(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cases := []struct {
|
||||
text string
|
||||
width int
|
||||
expectedLines int
|
||||
}{
|
||||
{
|
||||
"first line\n\nthird line",
|
||||
80,
|
||||
3,
|
||||
},
|
||||
{
|
||||
"first line\n\nthird line",
|
||||
6,
|
||||
5,
|
||||
},
|
||||
{
|
||||
"string without any newlines",
|
||||
80,
|
||||
1,
|
||||
},
|
||||
{
|
||||
"string with one newline, string with one newline, string with one>\n<newline, string with one newline",
|
||||
32,
|
||||
5,
|
||||
},
|
||||
{
|
||||
"[red:-:-]Do you[-:-:-] want to\n\nquit the application?",
|
||||
28,
|
||||
4,
|
||||
},
|
||||
{
|
||||
Escape("In [Chinese astronomy], the stars that correspond to Gemini are located in two areas: the [White Tiger of the West] (西方白虎, *Xī Fāng Bái Hǔ*) and the [Vermillion Bird of the South] (南方朱雀, *Nán Fāng Zhū Què*)."),
|
||||
100,
|
||||
3,
|
||||
},
|
||||
}
|
||||
for i, c := range cases {
|
||||
lines := WordWrap(c.text, c.width)
|
||||
for j, line := range lines {
|
||||
if strings.Contains(line, "\n") {
|
||||
t.Errorf("case %d, line %d: wrapped line contains newline", i, j)
|
||||
}
|
||||
strippedWidth := runewidth.StringWidth(string(StripTags([]byte(line), true, true)))
|
||||
if strippedWidth > c.width {
|
||||
t.Errorf("case %d, line %d: wrapped line exceeds width %d with length %d", i, j, c.width, runewidth.StringWidth(line))
|
||||
}
|
||||
}
|
||||
if len(lines) != c.expectedLines {
|
||||
t.Errorf("case %d: expected %d lines, got %d", i, c.expectedLines, len(lines))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue