Skip to content

Commit

Permalink
improved search performance and add smart pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
isacikgoz committed Jan 2, 2019
1 parent 76c3f01 commit a653d95
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (

func main() {

kingpin.Version("tldr++ version 0.4.0")
kingpin.Version("tldr++ version 0.5.0")
kingpin.Parse()

config.StartUp(*clear, *update)
Expand Down
9 changes: 7 additions & 2 deletions pkg/config/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"time"

"gopkg.in/src-d/go-git.v4"
git "gopkg.in/src-d/go-git.v4"
)

const (
Expand Down Expand Up @@ -55,7 +55,11 @@ func PullSource() error {
Progress: os.Stdout,
})
if err != nil {
fmt.Printf("%s\n", err.Error())
if err == git.NoErrAlreadyUpToDate {
fmt.Printf("%s\n", "No changes at tldr-pages repository.")
} else {
fmt.Printf("%s\n", err.Error())
}
} else {
fmt.Printf("Successfully pulled into: %s\n", dir)
}
Expand Down Expand Up @@ -96,5 +100,6 @@ func staled() (bool, error) {
if diff > 24*7*2*time.Hour {
return true, nil
}
file.Close()
return false, nil
}
16 changes: 14 additions & 2 deletions pkg/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/c-bata/go-prompt/completer"
"github.com/isacikgoz/survey"
"github.com/isacikgoz/tldr/pkg/pages"
xterm "golang.org/x/crypto/ssh/terminal"
"gopkg.in/AlecAivazis/survey.v1/core"
"gopkg.in/AlecAivazis/survey.v1/terminal"
)
Expand Down Expand Up @@ -43,12 +44,23 @@ func (p *Prompt) RenderPage(static bool) error {
options = append(options, t.Display())
}
core.ErrorTemplate = ""

var mxRows int
if len(p.Page.Tips) > 7 {
_, height, err := xterm.GetSize(0)
if err != nil || len(p.Page.Tips) > 10 {
mxRows = 7
} else {
mxRows = len(p.Page.Tips)
mxRows = (height - 7) / (3)
if mxRows < 3 {
mxRows = 3
}
}

// if len(p.Page.Tips) > 7 {
// mxRows = 7
// } else {
// mxRows = len(p.Page.Tips)
// }
// genereate questions to ask
p.Questions = []*survey.Question{
{
Expand Down

0 comments on commit a653d95

Please sign in to comment.