1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
This commit is contained in:
Nicholas Eden 2018-11-22 08:25:12 -08:00
commit 8350dbbf8c
5 changed files with 108 additions and 19 deletions

View File

@ -365,8 +365,21 @@
"name": "Matei Alexandru Gardus",
"avatar_url": "https://avatars0.githubusercontent.com/u/11583824?v=4",
"profile": "http://stormfirefox1.github.io",
"contributions": [
]
"contributions": []
},
{
"login": "Seanstoppable",
"name": "Sean Smith",
"avatar_url": "https://avatars2.githubusercontent.com/u/1523955?v=4",
"profile": "https://github.com/Seanstoppable",
"contributions": []
},
{
"login": "kaskavalci",
"name": "Halil Kaskavalci",
"avatar_url": "https://avatars1.githubusercontent.com/u/1646238?v=4",
"profile": "http://kaskavalci.com",
"contributions": []
}
]
}

View File

@ -1,5 +1,5 @@
[![All Contributors](https://img.shields.io/badge/all_contributors-51-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-53-orange.svg?style=flat-square)](#contributors)
[![Build Status](https://travis-ci.com/senorprogrammer/wtf.svg?branch=master)](https://travis-ci.com/senorprogrammer/wtf)
[![Gitter Chat](https://badges.gitter.im/wtfutil/Lobby.svg)](https://gitter.im/wtfutil/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Twitter](https://img.shields.io/badge/follow-on%20twitter-blue.svg)](https://twitter.com/wtfutil)
@ -71,7 +71,7 @@ project:
| [<img src="https://avatars0.githubusercontent.com/u/889171?v=4" width="48px;"/><br /><sub><b>Lineu Felipe</b></sub>](https://github.com/darkSasori)<br /> | [<img src="https://avatars2.githubusercontent.com/u/159124?v=4" width="48px;"/><br /><sub><b>Konstantin</b></sub>](https://github.com/kvj)<br /> | [<img src="https://avatars2.githubusercontent.com/u/6044920?v=4" width="48px;"/><br /><sub><b>Brendan O'Leary</b></sub>](http://www.brendanoleary.com)<br /> | [<img src="https://avatars2.githubusercontent.com/u/1226441?v=4" width="48px;"/><br /><sub><b>bertl4398</b></sub>](https://github.com/bertl4398)<br /> | [<img src="https://avatars2.githubusercontent.com/u/6553695?v=4" width="48px;"/><br /><sub><b>Ferenc-</b></sub>](https://github.com/Ferenc-)<br /> | [<img src="https://avatars1.githubusercontent.com/u/952036?v=4" width="48px;"/><br /><sub><b>Rohan Verma</b></sub>](http://rohanverma.net)<br /> |
| [<img src="https://avatars1.githubusercontent.com/u/19293566?v=4" width="48px;"/><br /><sub><b>Tim Fitzgerald</b></sub>](https://github.com/fimtitzgerald)<br /> | [<img src="https://avatars2.githubusercontent.com/u/1081051?v=4" width="48px;"/><br /><sub><b>Federico Ruggi</b></sub>](https://github.com/ruggi)<br /> | [<img src="https://avatars2.githubusercontent.com/u/7293328?v=4" width="48px;"/><br /><sub><b>Craig Woodward</b></sub>](https://github.com/ctwoodward)<br /> | [<img src="https://avatars3.githubusercontent.com/u/15367484?v=4" width="48px;"/><br /><sub><b>ReadmeCritic</b></sub>](https://twitter.com/ReadmeCritic)<br /> | [<img src="https://avatars0.githubusercontent.com/u/141402?v=4" width="48px;"/><br /><sub><b>Eugene</b></sub>](https://github.com/jdevelop)<br /> | [<img src="https://avatars1.githubusercontent.com/u/12983705?s=460&v=4" width="48px;"/><br /><sub><b>Kenny Wu</b></sub>](https://github.com/Trinergy)<br /> |
| [<img src="https://avatars0.githubusercontent.com/u/538234?v=4" width="48px;"/><br /><sub><b>Renán Romero</b></sub>](http://www.romeroruiz.com)<br /> | [<img src="https://avatars1.githubusercontent.com/u/5031240?v=4" width="48px;"/><br /><sub><b>Bastian Groß</b></sub>](https://github.com/sticreations)<br /> | [<img src="https://avatars1.githubusercontent.com/u/2496835?v=4" width="48px;"/><br /><sub><b>nicholas-eden</b></sub>](https://github.com/nicholas-eden)<br /> | [<img src="https://avatars1.githubusercontent.com/u/279390?v=4" width="48px;"/><br /><sub><b>Dan Rabinowitz</b></sub>](https://github.com/danrabinowitz)<br /> | [<img src="https://avatars1.githubusercontent.com/u/6897575?v=4" width="48px;"/><br /><sub><b>David Missmann</b></sub>](https://github.com/dvdmssmnn)<br /> | [<img src="https://avatars2.githubusercontent.com/u/882006?v=4" width="48px;"/><br /><sub><b>Mathias Weber</b></sub>](https://github.com/mweb)<br /> |
| [<img src="https://avatars1.githubusercontent.com/u/32081703?v=4" width="48px;"/><br /><sub><b>TheRedSpy15</b></sub>](https://github.com/TheRedSpy15)<br /> | [<img src="https://avatars0.githubusercontent.com/u/9569897?v=4" width="48px;"/><br /><sub><b>Harald Nordgren</b></sub>](https://www.linkedin.com/in/harald-nordgren-44778192)<br /> | [<img src="https://avatars0.githubusercontent.com/u/11583824?v=4" width="48px;"/><br /><sub><b>Matei Alexandru Gardus</b></sub>](http://stormfirefox1.github.io)<br /> |
| [<img src="https://avatars1.githubusercontent.com/u/32081703?v=4" width="48px;"/><br /><sub><b>TheRedSpy15</b></sub>](https://github.com/TheRedSpy15)<br /> | [<img src="https://avatars0.githubusercontent.com/u/9569897?v=4" width="48px;"/><br /><sub><b>Harald Nordgren</b></sub>](https://www.linkedin.com/in/harald-nordgren-44778192)<br /> | [<img src="https://avatars0.githubusercontent.com/u/11583824?v=4" width="48px;"/><br /><sub><b>Matei Alexandru Gardus</b></sub>](http://stormfirefox1.github.io)<br /> | [<img src="https://avatars2.githubusercontent.com/u/1523955?v=4" width="48px;"/><br /><sub><b>Sean Smith</b></sub>](https://github.com/Seanstoppable)<br /> | [<img src="https://avatars1.githubusercontent.com/u/1646238?v=4" width="48px;"/><br /><sub><b>Halil Kaskavalci</b></sub>](http://kaskavalci.com)<br /> |
<!-- ALL-CONTRIBUTORS-LIST:END -->
## Acknowledgments

View File

@ -18,7 +18,7 @@ func (widget *Widget) display() {
title := fmt.Sprintf("%s - [green]%s[white]", widget.Name, repoData.Repository)
widget.View.SetTitle(widget.ContextualTitle(title))
str := wtf.SigilStr(len(widget.Data), widget.Idx, widget.View) + "\n"
str := wtf.SigilStr(len(widget.GitRepos), widget.Idx, widget.View) + "\n"
str = str + " [red]Branch[white]\n"
str = str + fmt.Sprintf(" %s", repoData.Branch)
str = str + "\n"

View File

@ -4,6 +4,10 @@ import (
"github.com/gdamore/tcell"
"github.com/rivo/tview"
"github.com/senorprogrammer/wtf/wtf"
"io/ioutil"
"log"
"sort"
"strings"
)
const HelpText = `
@ -29,7 +33,7 @@ type Widget struct {
wtf.TextWidget
app *tview.Application
Data []*GitRepo
GitRepos []*GitRepo
pages *tview.Pages
}
@ -59,7 +63,7 @@ func (widget *Widget) Checkout() {
checkoutFctn := func() {
text := form.GetFormItem(0).(*tview.InputField).GetText()
repoToCheckout := widget.Data[widget.Idx]
repoToCheckout := widget.GitRepos[widget.Idx]
repoToCheckout.checkout(text)
widget.pages.RemovePage("modal")
widget.app.SetFocus(widget.View)
@ -72,7 +76,7 @@ func (widget *Widget) Checkout() {
}
func (widget *Widget) Pull() {
repoToPull := widget.Data[widget.Idx]
repoToPull := widget.GitRepos[widget.Idx]
repoToPull.pull()
widget.Refresh()
@ -81,7 +85,10 @@ func (widget *Widget) Pull() {
func (widget *Widget) Refresh() {
repoPaths := wtf.ToStrs(wtf.Config.UList("wtf.mods.git.repositories"))
widget.Data = widget.gitRepos(repoPaths)
widget.GitRepos = widget.gitRepos(repoPaths)
sort.Slice(widget.GitRepos, func(i, j int) bool {
return widget.GitRepos[i].Path < widget.GitRepos[j].Path
})
widget.display()
}
@ -141,28 +148,84 @@ func (widget *Widget) modalFrame(form *tview.Form) *tview.Frame {
}
func (widget *Widget) currentData() *GitRepo {
if len(widget.Data) == 0 {
if len(widget.GitRepos) == 0 {
return nil
}
if widget.Idx < 0 || widget.Idx >= len(widget.Data) {
if widget.Idx < 0 || widget.Idx >= len(widget.GitRepos) {
return nil
}
return widget.Data[widget.Idx]
return widget.GitRepos[widget.Idx]
}
func (widget *Widget) gitRepos(repoPaths []string) []*GitRepo {
repos := []*GitRepo{}
for _, repoPath := range repoPaths {
if strings.HasSuffix(repoPath, "/") {
repos = append(repos, findGitRepositories(make([]*GitRepo, 0), repoPath)...)
} else {
repo := NewGitRepo(repoPath)
repos = append(repos, repo)
}
}
return repos
}
func findGitRepositories(repositories []*GitRepo, directory string) []*GitRepo {
directory = strings.TrimSuffix(directory, "/")
files, err := ioutil.ReadDir(directory)
if err != nil {
log.Fatal(err)
}
var path string
for _, file := range files {
if file.IsDir() {
path = directory + "/" + file.Name()
if file.Name() == ".git" {
path = strings.TrimSuffix(path, "/.git")
repo := NewGitRepo(path)
repositories = append(repositories, repo)
continue
}
if file.Name() == "vendor" || file.Name() == "node_modules" {
continue
}
repositories = findGitRepositories(repositories, path)
}
}
return repositories
}
func (widget *Widget) Next() {
widget.Idx = widget.Idx + 1
if widget.Idx == len(widget.GitRepos) {
widget.Idx = 0
}
if widget.DisplayFunction != nil {
widget.DisplayFunction()
}
}
func (widget *Widget) Prev() {
widget.Idx = widget.Idx - 1
if widget.Idx < 0 {
widget.Idx = len(widget.GitRepos) - 1
}
if widget.DisplayFunction != nil {
widget.DisplayFunction()
}
}
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
switch string(event.Rune()) {
case "/":

View File

@ -2,12 +2,13 @@ package hackernews
import (
"fmt"
"github.com/gdamore/tcell"
"github.com/rivo/tview"
"github.com/senorprogrammer/wtf/wtf"
"net/url"
"strconv"
"strings"
"github.com/gdamore/tcell"
"github.com/rivo/tview"
"github.com/senorprogrammer/wtf/wtf"
)
const HelpText = `
@ -22,6 +23,7 @@ const HelpText = `
arrow up: Select the previous story in the list
return: Open the selected story in a browser
c: Open the comments of the article
`
type Widget struct {
@ -151,6 +153,14 @@ func (widget *Widget) openStory() {
}
}
func (widget *Widget) openComments() {
sel := widget.selected
if sel >= 0 && widget.stories != nil && sel < len(widget.stories) {
story := &widget.stories[widget.selected]
wtf.OpenFile(fmt.Sprintf("https://news.ycombinator.com/item?id=%d", story.ID))
}
}
func (widget *Widget) unselect() {
widget.selected = -1
widget.display()
@ -169,6 +179,9 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
case "r":
widget.Refresh()
return nil
case "c":
widget.openComments()
return nil
}
switch event.Key() {