Wrap Terminal in TermHost
This commit is contained in:
parent
dee0f8938b
commit
60b17c473a
5 changed files with 64 additions and 20 deletions
|
@ -3,7 +3,6 @@ package commands
|
|||
import (
|
||||
"errors"
|
||||
|
||||
"git.sr.ht/~sircmpwn/aerc2/lib/ui"
|
||||
"git.sr.ht/~sircmpwn/aerc2/widgets"
|
||||
)
|
||||
|
||||
|
@ -15,15 +14,10 @@ func TermClose(aerc *widgets.Aerc, args []string) error {
|
|||
if len(args) != 1 {
|
||||
return errors.New("Usage: term-close")
|
||||
}
|
||||
grid, ok := aerc.SelectedTab().(*ui.Grid)
|
||||
thost, ok := aerc.SelectedTab().(*widgets.TermHost)
|
||||
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")
|
||||
thost.Terminal().Close(nil)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"os/exec"
|
||||
"time"
|
||||
|
||||
"git.sr.ht/~sircmpwn/aerc2/lib/ui"
|
||||
"git.sr.ht/~sircmpwn/aerc2/widgets"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
|
@ -27,14 +26,8 @@ func Term(aerc *widgets.Aerc, args []string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
grid := ui.NewGrid().Rows([]ui.GridSpec{
|
||||
{ui.SIZE_WEIGHT, 1},
|
||||
}).Columns([]ui.GridSpec{
|
||||
{ui.SIZE_EXACT, aerc.Config().Ui.SidebarWidth},
|
||||
{ui.SIZE_WEIGHT, 1},
|
||||
})
|
||||
grid.AddChild(term).At(0, 1)
|
||||
tab := aerc.NewTab(grid, args[1])
|
||||
host := widgets.NewTermHost(term, aerc.Config())
|
||||
tab := aerc.NewTab(host, args[1])
|
||||
term.OnTitle = func(title string) {
|
||||
if title == "" {
|
||||
title = args[1]
|
||||
|
@ -43,7 +36,7 @@ func Term(aerc *widgets.Aerc, args []string) error {
|
|||
tab.Content.Invalidate()
|
||||
}
|
||||
term.OnClose = func(err error) {
|
||||
aerc.RemoveTab(grid)
|
||||
aerc.RemoveTab(host)
|
||||
if err != nil {
|
||||
aerc.PushStatus(" "+err.Error(), 10*time.Second).
|
||||
Color(tcell.ColorRed, tcell.ColorWhite)
|
||||
|
|
|
@ -122,6 +122,11 @@ func (aerc *Aerc) Event(event tcell.Event) bool {
|
|||
aerc.BeginExCommand()
|
||||
return true
|
||||
}
|
||||
interactive, ok := aerc.tabs.Tabs[aerc.tabs.Selected].Content.(ui.Interactive)
|
||||
if ok {
|
||||
return interactive.Event(event)
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
|
52
widgets/termhost.go
Normal file
52
widgets/termhost.go
Normal file
|
@ -0,0 +1,52 @@
|
|||
package widgets
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
|
||||
"git.sr.ht/~sircmpwn/aerc2/config"
|
||||
"git.sr.ht/~sircmpwn/aerc2/lib/ui"
|
||||
)
|
||||
|
||||
type TermHost struct {
|
||||
grid *ui.Grid
|
||||
term *Terminal
|
||||
}
|
||||
|
||||
// Thin wrapper around terminal which puts it in a grid and passes through
|
||||
// input events. A bit of a hack tbh
|
||||
func NewTermHost(term *Terminal, conf *config.AercConfig) *TermHost {
|
||||
grid := ui.NewGrid().Rows([]ui.GridSpec{
|
||||
{ui.SIZE_WEIGHT, 1},
|
||||
}).Columns([]ui.GridSpec{
|
||||
{ui.SIZE_EXACT, conf.Ui.SidebarWidth},
|
||||
{ui.SIZE_WEIGHT, 1},
|
||||
})
|
||||
grid.AddChild(term).At(0, 1)
|
||||
return &TermHost{grid, term}
|
||||
}
|
||||
|
||||
func (th *TermHost) Draw(ctx *ui.Context) {
|
||||
th.grid.Draw(ctx)
|
||||
}
|
||||
|
||||
func (th TermHost) Invalidate() {
|
||||
th.grid.Invalidate()
|
||||
}
|
||||
|
||||
func (th *TermHost) OnInvalidate(fn func(d ui.Drawable)) {
|
||||
th.grid.OnInvalidate(func(_ ui.Drawable) {
|
||||
fn(th)
|
||||
})
|
||||
}
|
||||
|
||||
func (th *TermHost) Event(event tcell.Event) bool {
|
||||
return th.term.Event(event)
|
||||
}
|
||||
|
||||
func (th *TermHost) Focus(focus bool) {
|
||||
th.term.Focus(focus)
|
||||
}
|
||||
|
||||
func (th *TermHost) Terminal() *Terminal {
|
||||
return th.term
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package widgets
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
gocolor "image/color"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
@ -188,7 +189,6 @@ func (term *Terminal) Focus(focus bool) {
|
|||
}
|
||||
|
||||
func (term *Terminal) Event(event tcell.Event) bool {
|
||||
// TODO
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue