Skip to content

Commit

Permalink
When advising on a TERM upgrade, use tcell's database too
Browse files Browse the repository at this point in the history
Tcell comes with a built-in database of terminal types. It can also use
infocmp to construct one on the target machine. Termshark will advise a
user to use a more colorful TERM variable if the -256color definition is
available. This change has termshark check tcell's DB first, falling
back to infocmp if necessary.
  • Loading branch information
gcla committed Sep 3, 2021
1 parent 3f46d2f commit 9ed046d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
13 changes: 1 addition & 12 deletions ui/lastline.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"github.com/gcla/termshark/v2/theme"
"github.com/gcla/termshark/v2/widgets/mapkeys"
"github.com/gcla/termshark/v2/widgets/minibuffer"
"github.com/gdamore/tcell/terminfo"
"github.com/gdamore/tcell/terminfo/dynamic"
"github.com/rakyll/statik/fs"
"github.com/shibukawa/configdir"

Expand Down Expand Up @@ -311,15 +309,6 @@ func parseOnOff(str string) (bool, error) {
return false, strconv.ErrSyntax
}

func validateTerm(term string) error {
var err error
_, err = terminfo.LookupTerminfo(term)
if err != nil {
_, _, err = dynamic.LoadTerminfo(term)
}
return err
}

type setCommand struct{}

var _ minibuffer.IAction = setCommand{}
Expand Down Expand Up @@ -359,7 +348,7 @@ func (d setCommand) Run(app gowid.IApp, args ...string) error {
OpenMessage(fmt.Sprintf("Packet colors are now %s", gwutil.If(b, "on", "off").(string)), appView, app)
}
case "term":
if err = validateTerm(args[2]); err == nil {
if err = termshark.ValidateTerm(args[2]); err == nil {
termshark.SetConf("main.term", args[2])
OpenMessage(fmt.Sprintf("Terminal type is now %s\n(Requires restart)", args[2]), appView, app)
}
Expand Down
2 changes: 1 addition & 1 deletion ui/switchterm.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func SuggestSwitchingTerm(app gowid.IApp) {
term256 := term + "-256color"

switchTerm = dialog.New(
framed.NewSpace(paragraph.New(fmt.Sprintf("Termshark is running with TERM=%s. Your terminal database contains %s. Would you like to switch for a more colorful experience? Termshark will need to restart.", term, term256))),
framed.NewSpace(paragraph.New(fmt.Sprintf("Termshark is running with TERM=%s. The terminal database contains %s. Would you like to switch for a more colorful experience? Termshark will need to restart.", term, term256))),
dialog.Options{
Buttons: []dialog.Button{Yes, No, NoAsk},
NoShadow: true,
Expand Down
13 changes: 11 additions & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/gcla/termshark/v2/system"
"github.com/gcla/termshark/v2/widgets/resizable"
"github.com/gdamore/tcell"
"github.com/gdamore/tcell/terminfo"
"github.com/gdamore/tcell/terminfo/dynamic"
"github.com/mattn/go-isatty"
"github.com/pkg/errors"
Expand Down Expand Up @@ -1327,8 +1328,16 @@ func FileSizeDifferentTo(filename string, cur int64) (int64, bool) {
}

func Does256ColorTermExist() error {
_, _, e := dynamic.LoadTerminfo(fmt.Sprintf("%s-256color", os.Getenv("TERM")))
return e
return ValidateTerm(fmt.Sprintf("%s-256color", os.Getenv("TERM")))
}

func ValidateTerm(term string) error {
var err error
_, err = terminfo.LookupTerminfo(term)
if err != nil {
_, _, err = dynamic.LoadTerminfo(term)
}
return err
}

//======================================================================
Expand Down

0 comments on commit 9ed046d

Please sign in to comment.