mirror of https://github.com/jroimartin/gocui.git
Remove View.WrapPrefix
This commit is contained in:
parent
0992dc1df0
commit
0e85b51ed2
|
@ -19,7 +19,6 @@ func layout(g *gocui.Gui) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
v.Wrap = true
|
v.Wrap = true
|
||||||
v.WrapPrefix = "> "
|
|
||||||
|
|
||||||
line := strings.Repeat("This is a long line -- ", 10)
|
line := strings.Repeat("This is a long line -- ", 10)
|
||||||
fmt.Fprintf(v, "%s\n\n", line)
|
fmt.Fprintf(v, "%s\n\n", line)
|
||||||
|
|
25
view.go
25
view.go
|
@ -52,9 +52,6 @@ type View struct {
|
||||||
// view's x-origin will be ignored.
|
// view's x-origin will be ignored.
|
||||||
Wrap bool
|
Wrap bool
|
||||||
|
|
||||||
// If Wrap is true, each wrapping line is prefixed with this prefix.
|
|
||||||
WrapPrefix string
|
|
||||||
|
|
||||||
// If Autoscroll is true, the View will automatically scroll down when the
|
// If Autoscroll is true, the View will automatically scroll down when the
|
||||||
// text overflows. If true the view's y-origin will be ignored.
|
// text overflows. If true the view's y-origin will be ignored.
|
||||||
Autoscroll bool
|
Autoscroll bool
|
||||||
|
@ -62,7 +59,6 @@ type View struct {
|
||||||
|
|
||||||
type viewLine struct {
|
type viewLine struct {
|
||||||
linesX, linesY int // coordinates relative to v.lines
|
linesX, linesY int // coordinates relative to v.lines
|
||||||
offset int // len(v.WrapPrefix) or 0
|
|
||||||
line []rune
|
line []rune
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,15 +199,13 @@ func (v *View) Rewind() {
|
||||||
// draw re-draws the view's contents.
|
// draw re-draws the view's contents.
|
||||||
func (v *View) draw() error {
|
func (v *View) draw() error {
|
||||||
maxX, maxY := v.Size()
|
maxX, maxY := v.Size()
|
||||||
lenPfx := len(v.WrapPrefix)
|
|
||||||
|
|
||||||
if v.Wrap {
|
if v.Wrap {
|
||||||
if lenPfx >= maxX {
|
if maxX == 0 {
|
||||||
return errors.New("WrapPrefix bigger or equal to X size")
|
return errors.New("X size of the view cannot be 0")
|
||||||
}
|
}
|
||||||
v.ox = 0
|
v.ox = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.tainted {
|
if v.tainted {
|
||||||
v.viewLines = nil
|
v.viewLines = nil
|
||||||
for i, line := range v.lines {
|
for i, line := range v.lines {
|
||||||
|
@ -225,17 +219,12 @@ func (v *View) draw() error {
|
||||||
v.viewLines = append(v.viewLines, vline)
|
v.viewLines = append(v.viewLines, vline)
|
||||||
}
|
}
|
||||||
// Append remaining lines with WrapPrefix
|
// Append remaining lines with WrapPrefix
|
||||||
for n := maxX; n < len(line); n += maxX - lenPfx {
|
for n := maxX; n < len(line); n += maxX {
|
||||||
wrappedLine := append(append([]rune(v.WrapPrefix), line[n:]...))
|
if len(line[n:]) <= maxX {
|
||||||
if len(wrappedLine) <= maxX {
|
vline := viewLine{linesX: n, linesY: i, line: line[n:]}
|
||||||
vline := viewLine{linesX: n, linesY: i,
|
|
||||||
offset: lenPfx,
|
|
||||||
line: wrappedLine}
|
|
||||||
v.viewLines = append(v.viewLines, vline)
|
v.viewLines = append(v.viewLines, vline)
|
||||||
} else {
|
} else {
|
||||||
vline := viewLine{linesX: n, linesY: i,
|
vline := viewLine{linesX: n, linesY: i, line: line[n : n+maxX]}
|
||||||
offset: lenPfx,
|
|
||||||
line: wrappedLine[:maxX]}
|
|
||||||
v.viewLines = append(v.viewLines, vline)
|
v.viewLines = append(v.viewLines, vline)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -292,7 +281,7 @@ func (v *View) realPosition(vx, vy int) (x, y int, err error) {
|
||||||
|
|
||||||
if vy < len(v.viewLines) {
|
if vy < len(v.viewLines) {
|
||||||
vline := v.viewLines[vy]
|
vline := v.viewLines[vy]
|
||||||
x = vline.linesX + vline.offset + vx
|
x = vline.linesX + vx
|
||||||
y = vline.linesY
|
y = vline.linesY
|
||||||
} else {
|
} else {
|
||||||
vline := v.viewLines[len(v.viewLines)-1]
|
vline := v.viewLines[len(v.viewLines)-1]
|
||||||
|
|
Loading…
Reference in New Issue