Zach DeCook: 1 config: allow gaps to be customized 6 files changed, 37 insertions(+), 33 deletions(-)
If you like, I could probably refactor some option code so there's a net negative in lines (rather than +4 new lines). ;) -Zach
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~taiite/public-inbox/patches/27400/mbox | git am -3Learn more about email & git
--- app.go | 1 + config.go | 11 +++++++++++ doc/senpai.5.scd | 3 +++ ui/buffers.go | 10 +++++----- ui/draw_utils.go | 3 +-- ui/ui.go | 42 ++++++++++++++++-------------------------- 6 files changed, 37 insertions(+), 33 deletions(-) diff --git a/app.go b/app.go index 1144560..ca8b1d1 100644 --- a/app.go +++ b/app.go @@ -118,6 +118,7 @@ func NewApp(cfg Config) (app *App, err error) { app.win, err = ui.New(ui.Config{ NickColWidth: cfg.NickColWidth, + GapsColWidth: cfg.GapsColWidth, ChanColWidth: cfg.ChanColWidth, MemberColWidth: cfg.MemberColWidth, AutoComplete: func(cursorIdx int, text []rune) []ui.Completion { diff --git a/config.go b/config.go index 35857ba..69efbf6 100644 --- a/config.go +++ b/config.go @@ -65,6 +65,7 @@ type Config struct { Highlights []string OnHighlightPath string NickColWidth int + GapsColWidth int ChanColWidth int MemberColWidth int @@ -95,6 +96,7 @@ func Defaults() (cfg Config, err error) { Highlights: nil, OnHighlightPath: "", NickColWidth: 16, + GapsColWidth: 2, ChanColWidth: 0, MemberColWidth: 0, Colors: ConfigColors{ @@ -203,6 +205,15 @@ func unmarshal(filename string, cfg *Config) (err error) { if cfg.NickColWidth, err = strconv.Atoi(nicknames); err != nil { return err } + case "gaps": + var gaps string + if err := child.ParseParams(&gaps); err != nil { + return err + } + + if cfg.GapsColWidth, err = strconv.Atoi(gaps); err != nil { + return err + } case "channels": var channels string if err := child.ParseParams(&channels); err != nil { diff --git a/doc/senpai.5.scd b/doc/senpai.5.scd index e75513d..fc221ab 100644 --- a/doc/senpai.5.scd +++ b/doc/senpai.5.scd @@ -113,6 +113,9 @@ pane-widths { The number of cells that the column for nicknames occupies in the timeline. By default, 16. + *gaps* + The number of cells separating the timestamps, nicknames, and messages. By default, 2. + *channels* Make the channel list vertical, with a width equals to the given amount of cells. By default, the channel list is horizontal. diff --git a/ui/buffers.go b/ui/buffers.go index 1ccb921..4d400d0 100644 --- a/ui/buffers.go +++ b/ui/buffers.go @@ -555,15 +555,15 @@ func (bs *BufferList) DrawHorizontalBufferList(screen tcell.Screen, x0, y0, widt } } -func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int) { - clearArea(screen, x0, y0, bs.tlInnerWidth+nickColWidth+9, bs.tlHeight+2) +func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int, gapsColWidth int) { + clearArea(screen, x0, y0, 5+gapsColWidth+nickColWidth+gapsColWidth+bs.tlInnerWidth, bs.tlHeight+2) b := &bs.list[bs.current] xTopic := x0 printString(screen, &xTopic, y0, Styled(b.topic, tcell.StyleDefault)) y0++ - for x := x0; x < x0+bs.tlInnerWidth+nickColWidth+9; x++ { + for x := x0; x < x0+5+gapsColWidth+nickColWidth+gapsColWidth+bs.tlInnerWidth; x++ { st := tcell.StyleDefault.Foreground(tcell.ColorGray) screen.SetContent(x, y0, 0x2500, nil, st) } @@ -575,7 +575,7 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int break } - x1 := x0 + 9 + nickColWidth + x1 := x0 + 5 + gapsColWidth + nickColWidth + gapsColWidth line := &b.lines[i] nls := line.NewLines(bs.tlInnerWidth) @@ -593,7 +593,7 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int identSt := tcell.StyleDefault. Foreground(line.HeadColor). Reverse(line.Highlight) - printIdent(screen, x0+7, yi, nickColWidth, Styled(line.Head, identSt)) + printIdent(screen, x0+5+gapsColWidth, yi, nickColWidth, Styled(line.Head, identSt)) } x := x1 diff --git a/ui/draw_utils.go b/ui/draw_utils.go index 45e81db..394523c 100644 --- a/ui/draw_utils.go +++ b/ui/draw_utils.go @@ -27,14 +27,13 @@ func printIdent(screen tcell.Screen, x, y, width int, s StyledString) { if len(s.styles) != 0 && s.styles[0].Start == 0 { st = s.styles[0].Style } - screen.SetContent(x-1, y, ' ', nil, st) + screen.SetContent(x, y, ' ', nil, st) printString(screen, &x, y, s) if len(s.styles) != 0 { // TODO check if it's not a style that is from the truncated // part of s. st = s.styles[len(s.styles)-1].Style } - screen.SetContent(x, y, ' ', nil, st) } func printNumber(screen tcell.Screen, x *int, y int, st tcell.Style, n int) { diff --git a/ui/ui.go b/ui/ui.go index 7e02812..a16b296 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -11,6 +11,7 @@ import ( type Config struct { NickColWidth int + GapsColWidth int ChanColWidth int MemberColWidth int AutoComplete func(cursorIdx int, text []rune) []Completion @@ -315,7 +316,7 @@ func (ui *UI) InputBackSearch() { func (ui *UI) Resize() { w, h := ui.screen.Size() - innerWidth := w - 9 - ui.config.ChanColWidth - ui.config.NickColWidth - ui.config.MemberColWidth + innerWidth := w - ui.config.ChanColWidth - 5 - ui.config.GapsColWidth - ui.config.NickColWidth - ui.config.GapsColWidth - ui.config.MemberColWidth ui.e.Resize(innerWidth) if ui.config.ChanColWidth == 0 { ui.bs.ResizeTimeline(innerWidth, h-3) @@ -332,38 +333,27 @@ func (ui *UI) Size() (int, int) { func (ui *UI) Draw(members []irc.Member) { w, h := ui.screen.Size() + chanRow := 0 if ui.config.ChanColWidth == 0 { - ui.e.Draw(ui.screen, 9+ui.config.NickColWidth, h-2) - } else { - ui.e.Draw(ui.screen, 9+ui.config.ChanColWidth+ui.config.NickColWidth, h-1) + chanRow = 1 } - ui.bs.DrawTimeline(ui.screen, ui.config.ChanColWidth, 0, ui.config.NickColWidth) - if ui.config.ChanColWidth == 0 { - ui.bs.DrawHorizontalBufferList(ui.screen, 0, h-1, w-ui.config.MemberColWidth) - } else { - ui.bs.DrawVerticalBufferList(ui.screen, 0, 0, ui.config.ChanColWidth, h, &ui.channelOffset) - } + ui.e.Draw(ui.screen, 5 + ui.config.GapsColWidth + ui.config.NickColWidth + ui.config.GapsColWidth, h-1-chanRow) + + + ui.bs.DrawTimeline(ui.screen, ui.config.ChanColWidth, 0, ui.config.NickColWidth, ui.config.GapsColWidth) + ui.bs.DrawHorizontalBufferList(ui.screen, 0, h-chanRow, w-ui.config.MemberColWidth) + if ui.config.MemberColWidth != 0 { drawVerticalMemberList(ui.screen, w-ui.config.MemberColWidth, 0, ui.config.MemberColWidth, h, members, &ui.memberOffset) } - if ui.config.ChanColWidth == 0 { - ui.drawStatusBar(ui.config.ChanColWidth, h-3, w-ui.config.MemberColWidth) - } else { - ui.drawStatusBar(ui.config.ChanColWidth, h-2, w-ui.config.ChanColWidth-ui.config.MemberColWidth) - } + ui.drawStatusBar(ui.config.ChanColWidth, h-2-chanRow, w-ui.config.MemberColWidth) - if ui.config.ChanColWidth == 0 { - for x := 0; x < 9+ui.config.NickColWidth; x++ { - ui.screen.SetContent(x, h-2, ' ', nil, tcell.StyleDefault) - } - printIdent(ui.screen, 7, h-2, ui.config.NickColWidth, ui.prompt) - } else { - for x := ui.config.ChanColWidth; x < 9+ui.config.ChanColWidth+ui.config.NickColWidth; x++ { - ui.screen.SetContent(x, h-1, ' ', nil, tcell.StyleDefault) - } - printIdent(ui.screen, ui.config.ChanColWidth+7, h-1, ui.config.NickColWidth, ui.prompt) + for x := 0; x < 5 + ui.config.GapsColWidth + ui.config.NickColWidth + ui.config.GapsColWidth; x++ { + ui.screen.SetContent(x, h-1-chanRow, ' ', nil, tcell.StyleDefault) } + printIdent(ui.screen, 5 + ui.config.GapsColWidth, h-1-chanRow, ui.config.NickColWidth, ui.prompt) + ui.screen.Show() } @@ -381,7 +371,7 @@ func (ui *UI) drawStatusBar(x0, y, width int) { x := x0 + 5 + ui.config.NickColWidth printString(ui.screen, &x, y, s.StyledString()) - x += 2 + x += ui.config.GapsColWidth s.Reset() s.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorGray)) -- 2.34.1
Hi thanks for the patch. IIUC you want gaps to be one cell wide, is that right? The gaps have been set to 2 originally because highlight nicks have padding. This padding would need to take the gap width into account, and senpai hasn't the kind of UI that is made for narrow windows anyway. I don't think it makes sense to add all this code just for 2 cells.