Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gizak/termui
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: PingCAP-QE/termui
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Jun 26, 2023

  1. restore the github.com/codingpoeta/termui

    Signed-off-by: mahjonp <junpeng.man@gmail.com>
    mahjonp committed Jun 26, 2023
    Copy the full SHA
    1abf859 View commit details
Showing with 53 additions and 8 deletions.
  1. +33 −8 widgets/paragraph.go
  2. +20 −0 widgets/tree.go
41 changes: 33 additions & 8 deletions widgets/paragraph.go
Original file line number Diff line number Diff line change
@@ -6,6 +6,9 @@ package widgets

import (
"image"
"io/ioutil"
"os"
"os/exec"

. "github.com/gizak/termui/v3"
)
@@ -25,24 +28,46 @@ func NewParagraph() *Paragraph {
}
}

func (self *Paragraph) Draw(buf *Buffer) {
self.Block.Draw(buf)
func (p *Paragraph) ScrollHalfPageUp() {}

cells := ParseStyles(self.Text, self.TextStyle)
if self.WrapText {
cells = WrapCells(cells, uint(self.Inner.Dx()))
func (p *Paragraph) ScrollHalfPageDown() {}

func (p *Paragraph) Get() string {
return p.Text
}

func (p *Paragraph) Edit() string {
ioutil.WriteFile("./.tmpfile", []byte(p.Text), 0644)
cmd := exec.Command("vim", "./.tmpfile")
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Run()
tmp, err := ioutil.ReadFile("./.tmpfile")
if err != nil {
return ""
}
p.Text = string(tmp)
return p.Text
}

func (p *Paragraph) Draw(buf *Buffer) {
p.Block.Draw(buf)

cells := ParseStyles(p.Text, p.TextStyle)
if p.WrapText {
cells = WrapCells(cells, uint(p.Inner.Dx()))
}

rows := SplitCells(cells, '\n')

for y, row := range rows {
if y+self.Inner.Min.Y >= self.Inner.Max.Y {
if y+p.Inner.Min.Y >= p.Inner.Max.Y {
break
}
row = TrimCells(row, self.Inner.Dx())
row = TrimCells(row, p.Inner.Dx())
for _, cx := range BuildCellWithXArray(row) {
x, cell := cx.X, cx.Cell
buf.SetCell(cell, image.Pt(x, y).Add(self.Inner.Min))
buf.SetCell(cell, image.Pt(x, y).Add(p.Inner.Min))
}
}
}
20 changes: 20 additions & 0 deletions widgets/tree.go
Original file line number Diff line number Diff line change
@@ -180,6 +180,26 @@ func (self *Tree) SelectedNode() *TreeNode {
return self.rows[self.SelectedRow]
}

func (self *Tree) SelectedNodeWithIndex() *TreeNode {
if len(self.rows) == 0 {
return nil
}
rowNow := self.SelectedRow
res := self.rows[rowNow]
lastLevel := res.level
for lastLevel > 0 {
rowNow--
if self.rows[rowNow].level == lastLevel {
continue
}
lastLevel--
tmp := *self.rows[rowNow]
tmp.Nodes = []*TreeNode{res}
res = &tmp
}
return res
}

func (self *Tree) ScrollUp() {
self.ScrollAmount(-1)
}