commit f52114d
delthas
·
2022-07-25 08:56:57 +0000 UTC
parent 05c7327
Add pane-widths { text } to limit the max line width
Fixes: https://todo.sr.ht/~taiite/senpai/87
5 files changed,
+36,
-8
M
app.go
+1,
-0
1@@ -127,6 +127,7 @@ func NewApp(cfg Config) (app *App, err error) {
2 ChanColEnabled: cfg.ChanColEnabled,
3 MemberColWidth: cfg.MemberColWidth,
4 MemberColEnabled: cfg.MemberColEnabled,
5+ TextMaxWidth: cfg.TextMaxWidth,
6 AutoComplete: func(cursorIdx int, text []rune) []ui.Completion {
7 return app.completions(cursorIdx, text)
8 },
+11,
-0
1@@ -68,6 +68,7 @@ type Config struct {
2 ChanColEnabled bool
3 MemberColWidth int
4 MemberColEnabled bool
5+ TextMaxWidth int
6
7 Colors ConfigColors
8
9@@ -100,6 +101,7 @@ func Defaults() (cfg Config, err error) {
10 ChanColEnabled: true,
11 MemberColWidth: 16,
12 MemberColEnabled: true,
13+ TextMaxWidth: 0,
14 Colors: ConfigColors{
15 Prompt: tcell.ColorDefault,
16 Unread: tcell.ColorDefault,
17@@ -241,6 +243,15 @@ func unmarshal(filename string, cfg *Config) (err error) {
18 } else {
19 cfg.MemberColWidth = members
20 }
21+ case "text":
22+ var text string
23+ if err := child.ParseParams(&text); err != nil {
24+ return err
25+ }
26+
27+ if cfg.TextMaxWidth, err = strconv.Atoi(text); err != nil {
28+ return err
29+ }
30 default:
31 return fmt.Errorf("unknown directive %q", child.Name)
32 }
+5,
-0
1@@ -125,6 +125,11 @@ pane-widths {
2 If the value is negative, the member list will be disabled by default
3 and will take the positive (opposite) width value when toggled with F8.
4
5+ *text*
6+ The maximum message text line width for messages, in number of cells.
7+ By default, the value is zero, which means that there is no maximum.
8+ Useful for keeping a readable line width on large screens.
9+
10 *tls*
11 Enable TLS encryption. Defaults to true.
12
+12,
-6
1@@ -205,6 +205,7 @@ type BufferList struct {
2
3 tlInnerWidth int
4 tlHeight int
5+ textWidth int
6
7 showBufferNumbers bool
8
9@@ -222,9 +223,10 @@ func NewBufferList(colors ConfigColors, mergeLine func(*Line, Line)) BufferList
10 }
11 }
12
13-func (bs *BufferList) ResizeTimeline(tlInnerWidth, tlHeight int) {
14+func (bs *BufferList) ResizeTimeline(tlInnerWidth, tlHeight, textWidth int) {
15 bs.tlInnerWidth = tlInnerWidth
16 bs.tlHeight = tlHeight - 2
17+ bs.textWidth = textWidth
18 }
19
20 func (bs *BufferList) OpenOverlay() {
21@@ -374,7 +376,7 @@ func (bs *BufferList) AddLine(netID, title string, notify NotifyType, line Line)
22 line.computeSplitPoints()
23 b.lines = append(b.lines, line)
24 if b == current && 0 < b.scrollAmt {
25- b.scrollAmt += len(line.NewLines(bs.tlInnerWidth)) + 1
26+ b.scrollAmt += len(line.NewLines(bs.textWidth)) + 1
27 }
28 }
29
30@@ -451,7 +453,7 @@ func (bs *BufferList) UpdateRead() (netID, title string, timestamp time.Time) {
31 if y >= b.scrollAmt && line.Readable {
32 break
33 }
34- y += len(line.NewLines(bs.tlInnerWidth)) + 1
35+ y += len(line.NewLines(bs.textWidth)) + 1
36 }
37 if line != nil && line.At.After(b.read) {
38 b.read = line.At
39@@ -492,7 +494,7 @@ func (bs *BufferList) ScrollUpHighlight() bool {
40 b.scrollAmt = y - bs.tlHeight + 1
41 return true
42 }
43- y += len(line.NewLines(bs.tlInnerWidth)) + 1
44+ y += len(line.NewLines(bs.textWidth)) + 1
45 }
46 return false
47 }
48@@ -506,7 +508,7 @@ func (bs *BufferList) ScrollDownHighlight() bool {
49 if line.Highlight {
50 yLastHighlight = y
51 }
52- y += len(line.NewLines(bs.tlInnerWidth)) + 1
53+ y += len(line.NewLines(bs.textWidth)) + 1
54 }
55 b.scrollAmt = yLastHighlight
56 return b.scrollAmt != 0
57@@ -722,6 +724,10 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int
58 }
59 y0++
60
61+ if bs.textWidth < bs.tlInnerWidth {
62+ x0 += (bs.tlInnerWidth - bs.textWidth) / 2
63+ }
64+
65 yi := b.scrollAmt + y0 + bs.tlHeight
66 for i := len(b.lines) - 1; 0 <= i; i-- {
67 if yi < y0 {
68@@ -731,7 +737,7 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int
69 x1 := x0 + 9 + nickColWidth
70
71 line := &b.lines[i]
72- nls := line.NewLines(bs.tlInnerWidth)
73+ nls := line.NewLines(bs.textWidth)
74 yi -= len(nls) + 1
75 if y0+bs.tlHeight <= yi {
76 continue
M
ui/ui.go
+7,
-2
1@@ -16,6 +16,7 @@ type Config struct {
2 ChanColEnabled bool
3 MemberColWidth int
4 MemberColEnabled bool
5+ TextMaxWidth int
6 AutoComplete func(cursorIdx int, text []rune) []Completion
7 Mouse bool
8 MergeLine func(former *Line, addition Line)
9@@ -404,10 +405,14 @@ func (ui *UI) Resize() {
10 innerWidth = 1 // will break display somewhat, but this is an edge case
11 }
12 ui.e.Resize(innerWidth)
13+ textWidth := innerWidth
14+ if ui.config.TextMaxWidth > 0 && ui.config.TextMaxWidth < textWidth {
15+ textWidth = ui.config.TextMaxWidth
16+ }
17 if ui.channelWidth == 0 {
18- ui.bs.ResizeTimeline(innerWidth, h-3)
19+ ui.bs.ResizeTimeline(innerWidth, h-3, textWidth)
20 } else {
21- ui.bs.ResizeTimeline(innerWidth, h-2)
22+ ui.bs.ResizeTimeline(innerWidth, h-2, textWidth)
23 }
24 ui.screen.Sync()
25 }