Update tab name as subject changes
Also moves truncation to the tab widget
This commit is contained in:
parent
065da5e372
commit
2c486cb7f5
5 changed files with 40 additions and 10 deletions
|
@ -3,8 +3,6 @@ package account
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/mattn/go-runewidth"
|
|
||||||
|
|
||||||
"git.sr.ht/~sircmpwn/aerc2/widgets"
|
"git.sr.ht/~sircmpwn/aerc2/widgets"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,9 +17,15 @@ func Compose(aerc *widgets.Aerc, args []string) error {
|
||||||
}
|
}
|
||||||
acct := aerc.SelectedAccount()
|
acct := aerc.SelectedAccount()
|
||||||
composer := widgets.NewComposer(aerc.Config(), acct.AccountConfig())
|
composer := widgets.NewComposer(aerc.Config(), acct.AccountConfig())
|
||||||
// TODO: Change tab name when message subject changes
|
tab := aerc.NewTab(composer, "New email")
|
||||||
aerc.NewTab(composer, runewidth.Truncate(
|
composer.OnSubjectChange(func(subject string) {
|
||||||
"New email", 32, "…"))
|
if subject == "" {
|
||||||
|
tab.Name = "New email"
|
||||||
|
} else {
|
||||||
|
tab.Name = subject
|
||||||
|
}
|
||||||
|
tab.Content.Invalidate()
|
||||||
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,6 @@ package account
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/mattn/go-runewidth"
|
|
||||||
|
|
||||||
"git.sr.ht/~sircmpwn/aerc2/widgets"
|
"git.sr.ht/~sircmpwn/aerc2/widgets"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,8 +24,7 @@ func ViewMessage(aerc *widgets.Aerc, args []string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
viewer := widgets.NewMessageViewer(aerc.Config(), store, msg)
|
viewer := widgets.NewMessageViewer(aerc.Config(), store, msg)
|
||||||
aerc.NewTab(viewer, runewidth.Truncate(
|
aerc.NewTab(viewer, msg.Envelope.Subject)
|
||||||
msg.Envelope.Subject, 32, "…"))
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
|
"github.com/mattn/go-runewidth"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Tabs struct {
|
type Tabs struct {
|
||||||
|
@ -87,7 +88,8 @@ func (strip *TabStrip) Draw(ctx *Context) {
|
||||||
if strip.Selected == i {
|
if strip.Selected == i {
|
||||||
style = tcell.StyleDefault
|
style = tcell.StyleDefault
|
||||||
}
|
}
|
||||||
x += ctx.Printf(x, 0, style, " %s ", tab.Name)
|
trunc := runewidth.Truncate(tab.Name, 32, "…")
|
||||||
|
x += ctx.Printf(x, 0, style, " %s ", trunc)
|
||||||
}
|
}
|
||||||
style := tcell.StyleDefault.Reverse(true)
|
style := tcell.StyleDefault.Reverse(true)
|
||||||
ctx.Fill(x, 0, ctx.Width()-x, 1, ' ', style)
|
ctx.Fill(x, 0, ctx.Width()-x, 1, ' ', style)
|
||||||
|
|
|
@ -17,6 +17,7 @@ type TextInput struct {
|
||||||
prompt string
|
prompt string
|
||||||
scroll int
|
scroll int
|
||||||
text []rune
|
text []rune
|
||||||
|
change []func(ti *TextInput)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a new TextInput. TextInputs will render a "textbox" in the entire
|
// Creates a new TextInput. TextInputs will render a "textbox" in the entire
|
||||||
|
@ -69,6 +70,7 @@ func (ti *TextInput) insert(ch rune) {
|
||||||
ti.text = append(left, append([]rune{ch}, right...)...)
|
ti.text = append(left, append([]rune{ch}, right...)...)
|
||||||
ti.index++
|
ti.index++
|
||||||
ti.Invalidate()
|
ti.Invalidate()
|
||||||
|
ti.onChange()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ti *TextInput) deleteWord() {
|
func (ti *TextInput) deleteWord() {
|
||||||
|
@ -88,12 +90,14 @@ func (ti *TextInput) deleteWord() {
|
||||||
ti.text = append(ti.text[:i+1], ti.text[ti.index:]...)
|
ti.text = append(ti.text[:i+1], ti.text[ti.index:]...)
|
||||||
ti.index = i + 1
|
ti.index = i + 1
|
||||||
ti.Invalidate()
|
ti.Invalidate()
|
||||||
|
ti.onChange()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ti *TextInput) deleteChar() {
|
func (ti *TextInput) deleteChar() {
|
||||||
if len(ti.text) > 0 && ti.index != len(ti.text) {
|
if len(ti.text) > 0 && ti.index != len(ti.text) {
|
||||||
ti.text = append(ti.text[:ti.index], ti.text[ti.index+1:]...)
|
ti.text = append(ti.text[:ti.index], ti.text[ti.index+1:]...)
|
||||||
ti.Invalidate()
|
ti.Invalidate()
|
||||||
|
ti.onChange()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,9 +106,20 @@ func (ti *TextInput) backspace() {
|
||||||
ti.text = append(ti.text[:ti.index-1], ti.text[ti.index:]...)
|
ti.text = append(ti.text[:ti.index-1], ti.text[ti.index:]...)
|
||||||
ti.index--
|
ti.index--
|
||||||
ti.Invalidate()
|
ti.Invalidate()
|
||||||
|
ti.onChange()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ti *TextInput) onChange() {
|
||||||
|
for _, change := range ti.change {
|
||||||
|
change(ti)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ti *TextInput) OnChange(onChange func(ti *TextInput)) {
|
||||||
|
ti.change = append(ti.change, onChange)
|
||||||
|
}
|
||||||
|
|
||||||
func (ti *TextInput) Event(event tcell.Event) bool {
|
func (ti *TextInput) Event(event tcell.Event) bool {
|
||||||
switch event := event.(type) {
|
switch event := event.(type) {
|
||||||
case *tcell.EventKey:
|
case *tcell.EventKey:
|
||||||
|
|
|
@ -100,6 +100,12 @@ func NewComposer(conf *config.AercConfig,
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Composer) OnSubjectChange(fn func(subject string)) {
|
||||||
|
c.headers.subject.OnChange(func() {
|
||||||
|
fn(c.headers.subject.input.String())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Composer) Draw(ctx *ui.Context) {
|
func (c *Composer) Draw(ctx *ui.Context) {
|
||||||
c.grid.Draw(ctx)
|
c.grid.Draw(ctx)
|
||||||
}
|
}
|
||||||
|
@ -287,6 +293,12 @@ func (he *headerEditor) Event(event tcell.Event) bool {
|
||||||
return he.input.Event(event)
|
return he.input.Event(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (he *headerEditor) OnChange(fn func()) {
|
||||||
|
he.input.OnChange(func(_ *ui.TextInput) {
|
||||||
|
fn()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
type reviewMessage struct {
|
type reviewMessage struct {
|
||||||
composer *Composer
|
composer *Composer
|
||||||
grid *ui.Grid
|
grid *ui.Grid
|
||||||
|
|
Loading…
Reference in a new issue