Skip to content

Commit

Permalink
Merge commit 'refs/pull/2/head' of https://github.com/Nvveen/Gotty
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Campbell committed Apr 6, 2017
2 parents 44eeccf + 8ce7335 commit 44cc138
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions gotty.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"errors"
"fmt"
"os"
"path/filepath"
"reflect"
"strings"
"sync"
Expand All @@ -22,33 +23,29 @@ import (
// If something went wrong reading the terminfo database file, an error is
// returned.
func OpenTermInfo(termName string) (*TermInfo, error) {
var term *TermInfo
var err error
// Find the environment variables
termloc := os.Getenv("TERMINFO")
if len(termloc) == 0 {
if termloc := os.Getenv("TERMINFO"); len(termloc) > 0 {
path := filepath.Join(termloc, string(termName[0]), termName)
return readTermInfo(path)
} else {
// Search like ncurses
locations := []string{os.Getenv("HOME") + "/.terminfo/", "/etc/terminfo/",
"/lib/terminfo/", "/usr/share/terminfo/"}
var path string
locations := []string{}
if h := os.Getenv("HOME"); len(h) > 0 {
locations = append(locations, filepath.Join(h, ".terminfo"))
}
locations = append(locations,
"/etc/terminfo/",
"/lib/terminfo/",
"/usr/share/terminfo/")
for _, str := range locations {
// Construct path
path = str + string(termName[0]) + "/" + termName
// Check if path can be opened
file, _ := os.Open(path)
if file != nil {
// Path can open, fall out and use current path
file.Close()
break
path := filepath.Join(str, string(termName[0]), termName)
term, err := readTermInfo(path)
if err == nil {
return term, nil
}
}
if len(path) > 0 {
term, err = readTermInfo(path)
} else {
err = errors.New(fmt.Sprintf("No terminfo file(-location) found"))
}
return nil, errors.New("No terminfo file(-location) found")
}
return term, err
}

// Open a terminfo file from the environment variable containing the current
Expand Down

0 comments on commit 44cc138

Please sign in to comment.