Merge remote-tracking branch 'origin-main/master'

pull/824/head
x88 8 months ago
commit 0e1fc10b32

@ -2,7 +2,7 @@
package main
import (
"io/ioutil"
"os"
"path/filepath"
"github.com/gdamore/tcell/v2"
@ -21,7 +21,7 @@ func main() {
// A helper function which adds the files and directories of the given path
// to the given target node.
add := func(target *tview.TreeNode, path string) {
files, err := ioutil.ReadDir(path)
files, err := os.ReadDir(path)
if err != nil {
panic(err)
}

@ -4,12 +4,16 @@ import (
"github.com/gdamore/tcell/v2"
)
// Configuration values.
// Flex directions.
const (
FlexRow = 0 // One item per row.
FlexColumn = 1 // One item per column.
FlexRowCSS = 1 // As defined in CSS, items distributed along a row.
FlexColumnCSS = 0 // As defined in CSS, items distributed within a column.
// One item per row.
FlexRow = 0
// One item per column.
FlexColumn = 1
// As defined in CSS, items distributed along a row.
FlexRowCSS = 1
// As defined in CSS, items distributed within a column.
FlexColumnCSS = 0
)
// flexItem holds layout options for one item.
@ -49,7 +53,7 @@ type Flex struct {
// background before any items are drawn, set it to a box with the desired
// color:
//
// flex.Box = NewBox()
// flex.Box = NewBox()
func NewFlex() *Flex {
f := &Flex{
direction: FlexColumn,

@ -77,11 +77,12 @@ func NewGrid() *Grid {
// SetColumns defines how the columns of the grid are distributed. Each value
// defines the size of one column, starting with the leftmost column. Values
// greater 0 represent absolute column widths (gaps not included). Values less
// or equal 0 represent proportional column widths or fractions of the remaining
// free space, where 0 is treated the same as -1. That is, a column with a value
// of -3 will have three times the width of a column with a value of -1 (or 0).
// The minimum width set with SetMinSize() is always observed.
// greater than 0 represent absolute column widths (gaps not included). Values
// less than or equal to 0 represent proportional column widths or fractions of
// the remaining free space, where 0 is treated the same as -1. That is, a
// column with a value of -3 will have three times the width of a column with a
// value of -1 (or 0). The minimum width set with SetMinSize() is always
// observed.
//
// Primitives may extend beyond the columns defined explicitly with this
// function. A value of 0 is assumed for any undefined column. In fact, if you

@ -1310,6 +1310,10 @@ func (t *TextArea) extendLines(width, maxLines int) {
break
}
}
if lineWidth > t.widestLine {
t.widestLine = lineWidth
}
}
// truncateLines truncates the trailing lines of the [TextArea.lineStarts]

@ -1259,7 +1259,7 @@ func (t *TextView) Draw(screen tcell.Screen) {
}
// Purge.
if purgeStart > 0 {
if purgeStart > 0 && purgeStart < len(t.lineIndex) {
newText := t.text.String()[t.lineIndex[purgeStart].offset:]
t.text.Reset()
t.text.WriteString(newText)

@ -362,6 +362,35 @@ func (t *TreeView) GetCurrentNode() *TreeNode {
return t.currentNode
}
// GetPath returns all nodes located on the path from the root to the given
// node, including the root and the node itself. If there is no root node, nil
// is returned. If there are multiple paths to the node, a random one is chosen
// and returned.
func (t *TreeView) GetPath(node *TreeNode) []*TreeNode {
if t.root == nil {
return nil
}
var f func(current *TreeNode, path []*TreeNode) []*TreeNode
f = func(current *TreeNode, path []*TreeNode) []*TreeNode {
if current == node {
return path
}
for _, child := range current.children {
newPath := make([]*TreeNode, len(path), len(path)+1)
copy(newPath, path)
if p := f(child, append(newPath, child)); p != nil {
return p
}
}
return nil
}
return f(t.root, []*TreeNode{t.root})
}
// SetTopLevel sets the first tree level that is visible with 0 referring to the
// root, 1 to the root's child nodes, and so on. Nodes above the top level are
// not displayed.

Loading…
Cancel
Save