summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHubert Hirtz <hubert@hirtzfr.eu>2020-08-16 17:34:28 +0200
committerHubert Hirtz <hubert@hirtzfr.eu>2020-08-16 17:34:28 +0200
commit34e3264e22ba0524b124f4d350f154e276a7fee8 (patch)
treeebe755ad9c30eab81c82341f6f20e69e817d7d3d
parentFix +typing=active being sent incorrectly (diff)
ui: Configurable nick column width
Diffstat (limited to '')
-rw-r--r--app.go4
-rw-r--r--config.go17
-rw-r--r--ui/buffers.go8
-rw-r--r--ui/ui.go13
4 files changed, 27 insertions, 15 deletions
diff --git a/app.go b/app.go
index 73fe90a..af2ca2e 100644
--- a/app.go
+++ b/app.go
@@ -23,7 +23,9 @@ type App struct {
func NewApp(cfg Config) (app *App, err error) {
app = &App{}
- app.win, err = ui.New()
+ app.win, err = ui.New(ui.Config{
+ NickColWidth: cfg.NickColWidth,
+ })
if err != nil {
return
}
diff --git a/config.go b/config.go
index 216655a..09f4b39 100644
--- a/config.go
+++ b/config.go
@@ -7,18 +7,23 @@ import (
)
type Config struct {
- Addr string
- Nick string
- Real string
- User string
- Password *string
- Highlights []string
+ Addr string
+ Nick string
+ Real string
+ User string
+ Password *string
+
+ Highlights []string
+ NickColWidth int `yaml:"nick-column-width"`
Debug bool
}
func ParseConfig(buf []byte) (cfg Config, err error) {
err = yaml.Unmarshal(buf, &cfg)
+ if cfg.NickColWidth <= 0 {
+ cfg.NickColWidth = 16
+ }
return
}
diff --git a/ui/buffers.go b/ui/buffers.go
index bec770e..07f91a8 100644
--- a/ui/buffers.go
+++ b/ui/buffers.go
@@ -206,7 +206,7 @@ type buffer struct {
isAtTop bool
}
-func (b *buffer) DrawLines(screen tcell.Screen, width int, height int) {
+func (b *buffer) DrawLines(screen tcell.Screen, width, height, nickColWidth int) {
st := tcell.StyleDefault
for x := 0; x < width; x++ {
for y := 0; y < height; y++ {
@@ -214,8 +214,6 @@ func (b *buffer) DrawLines(screen tcell.Screen, width int, height int) {
}
}
- nickColWidth := 16
-
y0 := b.scrollAmt + height
for i := len(b.lines) - 1; 0 <= i; i-- {
if y0 < 0 {
@@ -472,8 +470,8 @@ func (bs *bufferList) idx(title string) int {
return -1
}
-func (bs *bufferList) Draw(screen tcell.Screen) {
- bs.list[bs.current].DrawLines(screen, bs.width, bs.height-3)
+func (bs *bufferList) Draw(screen tcell.Screen, nickColWidth int) {
+ bs.list[bs.current].DrawLines(screen, bs.width, bs.height-3, nickColWidth)
bs.drawStatusBar(screen, bs.height-3)
bs.drawTitleList(screen, bs.height-1)
}
diff --git a/ui/ui.go b/ui/ui.go
index adeec86..6755fd3 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -8,17 +8,24 @@ import (
"github.com/gdamore/tcell"
)
+type Config struct {
+ NickColWidth int
+}
+
type UI struct {
screen tcell.Screen
Events chan tcell.Event
exit atomic.Value // bool
+ config Config
bs bufferList
e editor
}
-func New() (ui *UI, err error) {
- ui = &UI{}
+func New(config Config) (ui *UI, err error) {
+ ui = &UI{
+ config: config,
+ }
ui.screen, err = tcell.NewScreen()
if err != nil {
@@ -208,6 +215,6 @@ func (ui *UI) Resize() {
func (ui *UI) draw() {
_, h := ui.screen.Size()
ui.e.Draw(ui.screen, h-2)
- ui.bs.Draw(ui.screen)
+ ui.bs.Draw(ui.screen, ui.config.NickColWidth)
ui.screen.Show()
}