Add :term-close
This commit is contained in:
parent
16c3f0a893
commit
dee0f8938b
6 changed files with 85 additions and 17 deletions
commands
29
commands/term-close.go
Normal file
29
commands/term-close.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.sr.ht/~sircmpwn/aerc2/lib/ui"
|
||||
"git.sr.ht/~sircmpwn/aerc2/widgets"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Register("term-close", TermClose)
|
||||
}
|
||||
|
||||
func TermClose(aerc *widgets.Aerc, args []string) error {
|
||||
if len(args) != 1 {
|
||||
return errors.New("Usage: term-close")
|
||||
}
|
||||
grid, ok := aerc.SelectedTab().(*ui.Grid)
|
||||
if !ok {
|
||||
return errors.New("Error: not a terminal")
|
||||
}
|
||||
for _, child := range grid.Children() {
|
||||
if term, ok := child.(*widgets.Terminal); ok {
|
||||
term.Close(nil)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return errors.New("Error: not a terminal")
|
||||
}
|
|
@ -2,10 +2,12 @@ package commands
|
|||
|
||||
import (
|
||||
"os/exec"
|
||||
"time"
|
||||
|
||||
"git.sr.ht/~sircmpwn/aerc2/lib/ui"
|
||||
"git.sr.ht/~sircmpwn/aerc2/widgets"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/riywo/loginshell"
|
||||
)
|
||||
|
||||
|
@ -32,13 +34,20 @@ func Term(aerc *widgets.Aerc, args []string) error {
|
|||
{ui.SIZE_WEIGHT, 1},
|
||||
})
|
||||
grid.AddChild(term).At(0, 1)
|
||||
tab := aerc.NewTab(grid, "Terminal")
|
||||
tab := aerc.NewTab(grid, args[1])
|
||||
term.OnTitle = func(title string) {
|
||||
if title == "" {
|
||||
title = "Terminal"
|
||||
title = args[1]
|
||||
}
|
||||
tab.Name = title
|
||||
tab.Content.Invalidate()
|
||||
}
|
||||
term.OnClose = func(err error) {
|
||||
aerc.RemoveTab(grid)
|
||||
if err != nil {
|
||||
aerc.PushStatus(" "+err.Error(), 10*time.Second).
|
||||
Color(tcell.ColorRed, tcell.ColorWhite)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue