commit 34e3264
Hubert Hirtz
·
2020-08-16 15:34:28 +0000 UTC
parent afe9803
ui: Configurable nick column width
4 files changed,
+27,
-15
M
app.go
+3,
-1
1@@ -23,7 +23,9 @@ type App struct {
2 func NewApp(cfg Config) (app *App, err error) {
3 app = &App{}
4
5- app.win, err = ui.New()
6+ app.win, err = ui.New(ui.Config{
7+ NickColWidth: cfg.NickColWidth,
8+ })
9 if err != nil {
10 return
11 }
+11,
-6
1@@ -7,18 +7,23 @@ import (
2 )
3
4 type Config struct {
5- Addr string
6- Nick string
7- Real string
8- User string
9- Password *string
10- Highlights []string
11+ Addr string
12+ Nick string
13+ Real string
14+ User string
15+ Password *string
16+
17+ Highlights []string
18+ NickColWidth int `yaml:"nick-column-width"`
19
20 Debug bool
21 }
22
23 func ParseConfig(buf []byte) (cfg Config, err error) {
24 err = yaml.Unmarshal(buf, &cfg)
25+ if cfg.NickColWidth <= 0 {
26+ cfg.NickColWidth = 16
27+ }
28 return
29 }
30
+3,
-5
1@@ -206,7 +206,7 @@ type buffer struct {
2 isAtTop bool
3 }
4
5-func (b *buffer) DrawLines(screen tcell.Screen, width int, height int) {
6+func (b *buffer) DrawLines(screen tcell.Screen, width, height, nickColWidth int) {
7 st := tcell.StyleDefault
8 for x := 0; x < width; x++ {
9 for y := 0; y < height; y++ {
10@@ -214,8 +214,6 @@ func (b *buffer) DrawLines(screen tcell.Screen, width int, height int) {
11 }
12 }
13
14- nickColWidth := 16
15-
16 y0 := b.scrollAmt + height
17 for i := len(b.lines) - 1; 0 <= i; i-- {
18 if y0 < 0 {
19@@ -472,8 +470,8 @@ func (bs *bufferList) idx(title string) int {
20 return -1
21 }
22
23-func (bs *bufferList) Draw(screen tcell.Screen) {
24- bs.list[bs.current].DrawLines(screen, bs.width, bs.height-3)
25+func (bs *bufferList) Draw(screen tcell.Screen, nickColWidth int) {
26+ bs.list[bs.current].DrawLines(screen, bs.width, bs.height-3, nickColWidth)
27 bs.drawStatusBar(screen, bs.height-3)
28 bs.drawTitleList(screen, bs.height-1)
29 }
M
ui/ui.go
+10,
-3
1@@ -8,17 +8,24 @@ import (
2 "github.com/gdamore/tcell"
3 )
4
5+type Config struct {
6+ NickColWidth int
7+}
8+
9 type UI struct {
10 screen tcell.Screen
11 Events chan tcell.Event
12 exit atomic.Value // bool
13+ config Config
14
15 bs bufferList
16 e editor
17 }
18
19-func New() (ui *UI, err error) {
20- ui = &UI{}
21+func New(config Config) (ui *UI, err error) {
22+ ui = &UI{
23+ config: config,
24+ }
25
26 ui.screen, err = tcell.NewScreen()
27 if err != nil {
28@@ -208,6 +215,6 @@ func (ui *UI) Resize() {
29 func (ui *UI) draw() {
30 _, h := ui.screen.Size()
31 ui.e.Draw(ui.screen, h-2)
32- ui.bs.Draw(ui.screen)
33+ ui.bs.Draw(ui.screen, ui.config.NickColWidth)
34 ui.screen.Show()
35 }