summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordelthas <delthas@dille.cc>2022-07-25 10:56:57 +0200
committerdelthas <delthas@dille.cc>2022-07-25 10:56:57 +0200
commitf52114de33d3b51f298a3a7d1f6b59b3853d112c (patch)
tree8ef4b50bdd0b66d0a636e97a71f57757667aeb6a
parentFix crashing when shrinking the text to a zero width (diff)
Add pane-widths { text } to limit the max line width
Fixes: https://todo.sr.ht/~taiite/senpai/87
-rw-r--r--app.go1
-rw-r--r--config.go11
-rw-r--r--doc/senpai.5.scd5
-rw-r--r--ui/buffers.go18
-rw-r--r--ui/ui.go9
5 files changed, 36 insertions, 8 deletions
diff --git a/app.go b/app.go
index 4d5e5b3..2aaa486 100644
--- a/app.go
+++ b/app.go
@@ -127,6 +127,7 @@ func NewApp(cfg Config) (app *App, err error) {
ChanColEnabled: cfg.ChanColEnabled,
MemberColWidth: cfg.MemberColWidth,
MemberColEnabled: cfg.MemberColEnabled,
+ TextMaxWidth: cfg.TextMaxWidth,
AutoComplete: func(cursorIdx int, text []rune) []ui.Completion {
return app.completions(cursorIdx, text)
},
diff --git a/config.go b/config.go
index 5ac2a8a..7823ae7 100644
--- a/config.go
+++ b/config.go
@@ -68,6 +68,7 @@ type Config struct {
ChanColEnabled bool
MemberColWidth int
MemberColEnabled bool
+ TextMaxWidth int
Colors ConfigColors
@@ -100,6 +101,7 @@ func Defaults() (cfg Config, err error) {
ChanColEnabled: true,
MemberColWidth: 16,
MemberColEnabled: true,
+ TextMaxWidth: 0,
Colors: ConfigColors{
Prompt: tcell.ColorDefault,
Unread: tcell.ColorDefault,
@@ -241,6 +243,15 @@ func unmarshal(filename string, cfg *Config) (err error) {
} else {
cfg.MemberColWidth = members
}
+ case "text":
+ var text string
+ if err := child.ParseParams(&text); err != nil {
+ return err
+ }
+
+ if cfg.TextMaxWidth, err = strconv.Atoi(text); err != nil {
+ return err
+ }
default:
return fmt.Errorf("unknown directive %q", child.Name)
}
diff --git a/doc/senpai.5.scd b/doc/senpai.5.scd
index ec6bea5..a8bd9c3 100644
--- a/doc/senpai.5.scd
+++ b/doc/senpai.5.scd
@@ -125,6 +125,11 @@ pane-widths {
If the value is negative, the member list will be disabled by default
and will take the positive (opposite) width value when toggled with F8.
+ *text*
+ The maximum message text line width for messages, in number of cells.
+ By default, the value is zero, which means that there is no maximum.
+ Useful for keeping a readable line width on large screens.
+
*tls*
Enable TLS encryption. Defaults to true.
diff --git a/ui/buffers.go b/ui/buffers.go
index f1f71b3..915a1c8 100644
--- a/ui/buffers.go
+++ b/ui/buffers.go
@@ -205,6 +205,7 @@ type BufferList struct {
tlInnerWidth int
tlHeight int
+ textWidth int
showBufferNumbers bool
@@ -222,9 +223,10 @@ func NewBufferList(colors ConfigColors, mergeLine func(*Line, Line)) BufferList
}
}
-func (bs *BufferList) ResizeTimeline(tlInnerWidth, tlHeight int) {
+func (bs *BufferList) ResizeTimeline(tlInnerWidth, tlHeight, textWidth int) {
bs.tlInnerWidth = tlInnerWidth
bs.tlHeight = tlHeight - 2
+ bs.textWidth = textWidth
}
func (bs *BufferList) OpenOverlay() {
@@ -374,7 +376,7 @@ func (bs *BufferList) AddLine(netID, title string, notify NotifyType, line Line)
line.computeSplitPoints()
b.lines = append(b.lines, line)
if b == current && 0 < b.scrollAmt {
- b.scrollAmt += len(line.NewLines(bs.tlInnerWidth)) + 1
+ b.scrollAmt += len(line.NewLines(bs.textWidth)) + 1
}
}
@@ -451,7 +453,7 @@ func (bs *BufferList) UpdateRead() (netID, title string, timestamp time.Time) {
if y >= b.scrollAmt && line.Readable {
break
}
- y += len(line.NewLines(bs.tlInnerWidth)) + 1
+ y += len(line.NewLines(bs.textWidth)) + 1
}
if line != nil && line.At.After(b.read) {
b.read = line.At
@@ -492,7 +494,7 @@ func (bs *BufferList) ScrollUpHighlight() bool {
b.scrollAmt = y - bs.tlHeight + 1
return true
}
- y += len(line.NewLines(bs.tlInnerWidth)) + 1
+ y += len(line.NewLines(bs.textWidth)) + 1
}
return false
}
@@ -506,7 +508,7 @@ func (bs *BufferList) ScrollDownHighlight() bool {
if line.Highlight {
yLastHighlight = y
}
- y += len(line.NewLines(bs.tlInnerWidth)) + 1
+ y += len(line.NewLines(bs.textWidth)) + 1
}
b.scrollAmt = yLastHighlight
return b.scrollAmt != 0
@@ -722,6 +724,10 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int
}
y0++
+ if bs.textWidth < bs.tlInnerWidth {
+ x0 += (bs.tlInnerWidth - bs.textWidth) / 2
+ }
+
yi := b.scrollAmt + y0 + bs.tlHeight
for i := len(b.lines) - 1; 0 <= i; i-- {
if yi < y0 {
@@ -731,7 +737,7 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int
x1 := x0 + 9 + nickColWidth
line := &b.lines[i]
- nls := line.NewLines(bs.tlInnerWidth)
+ nls := line.NewLines(bs.textWidth)
yi -= len(nls) + 1
if y0+bs.tlHeight <= yi {
continue
diff --git a/ui/ui.go b/ui/ui.go
index 5533633..7ae13e2 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -16,6 +16,7 @@ type Config struct {
ChanColEnabled bool
MemberColWidth int
MemberColEnabled bool
+ TextMaxWidth int
AutoComplete func(cursorIdx int, text []rune) []Completion
Mouse bool
MergeLine func(former *Line, addition Line)
@@ -404,10 +405,14 @@ func (ui *UI) Resize() {
innerWidth = 1 // will break display somewhat, but this is an edge case
}
ui.e.Resize(innerWidth)
+ textWidth := innerWidth
+ if ui.config.TextMaxWidth > 0 && ui.config.TextMaxWidth < textWidth {
+ textWidth = ui.config.TextMaxWidth
+ }
if ui.channelWidth == 0 {
- ui.bs.ResizeTimeline(innerWidth, h-3)
+ ui.bs.ResizeTimeline(innerWidth, h-3, textWidth)
} else {
- ui.bs.ResizeTimeline(innerWidth, h-2)
+ ui.bs.ResizeTimeline(innerWidth, h-2, textWidth)
}
ui.screen.Sync()
}