Skip to content

Commit b376cb0

Browse files
authored
Merge pull request #75 from jesseduffield/tab-width
Add a TabWidth field to gocui.View
2 parents aba68ae + 5c75d83 commit b376cb0

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

view.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ type View struct {
195195
// if true, the view will underline hyperlinks only when the cursor is on
196196
// them; otherwise, they will always be underlined
197197
UnderlineHyperLinksOnlyOnHover bool
198+
199+
// number of spaces per \t character, defaults to 4
200+
TabWidth int
198201
}
199202

200203
type pos struct {
@@ -424,6 +427,7 @@ func NewView(name string, x0, y0, x1, y1 int, mode OutputMode) *View {
424427
searcher: &searcher{},
425428
TextArea: &TextArea{},
426429
rangeSelectStartY: -1,
430+
TabWidth: 4,
427431
}
428432

429433
v.FgColor, v.BgColor = ColorDefault, ColorDefault
@@ -923,9 +927,12 @@ func (v *View) parseInput(ch rune, x int, _ int) (bool, []cell) {
923927
return truncateLine, nil
924928
} else if ch == '\t' {
925929
// fill tab-sized space
926-
const tabStop = 4
930+
tabWidth := v.TabWidth
931+
if tabWidth < 1 {
932+
tabWidth = 4
933+
}
927934
ch = ' '
928-
repeatCount = tabStop - (x % tabStop)
935+
repeatCount = tabWidth - (x % tabWidth)
929936
}
930937
c := cell{
931938
fgColor: v.ei.curFgColor,

0 commit comments

Comments
 (0)