~rockorager/shtc

4c6fa7be9d0637d96743330de94935887cf2f63a — Tim Culverhouse 1 year, 7 days ago eed9269
git: stream in repos

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
2 files changed, 29 insertions(+), 30 deletions(-)

M client/client.go
M git/model.go
M client/client.go => client/client.go +10 -18
@@ 78,32 78,25 @@ func serviceURI(service string) string {
func (w *Worker) HandleCmd(cmd vaxis.Msg) {
	switch cmd := cmd.(type) {
	case shtc.FetchMyRepoList:
		var (
			cursor *git.Cursor
			repos  []git.Repository
		)
		var cursor *git.Cursor
		for {
			resp, err := git.Repositories(w.git, cmd.Context, cursor)
			if err != nil {
				log.Error(err)
				return
			}
			repos = append(repos, resp.Results...)
			vaxis.PostMsg(vaxis.SendMsg{
				Msg:   resp.Results,
				Model: cmd.From,
			})
			if resp.Cursor == nil {
				break
			}
			cursor = resp.Cursor
		}

		vaxis.PostMsg(vaxis.SendMsg{
			Msg:   repos,
			Model: cmd.From,
		})
	case shtc.FetchUserRepoList:
		var (
			cursor *git.Cursor
			repos  []git.Repository
		)
		var cursor *git.Cursor
		for {
			user, err := git.RepositoriesByUser(w.git, cmd.Context, cmd.Username, cursor)
			if err != nil {


@@ 117,16 110,15 @@ func (w *Worker) HandleCmd(cmd vaxis.Msg) {
			if user.Repositories == nil {
				log.Errorf("unknown error fetching repositories for user %s", cmd.Username)
			}
			repos = append(repos, user.Repositories.Results...)
			vaxis.PostMsg(vaxis.SendMsg{
				Msg:   user.Repositories.Results,
				Model: cmd.From,
			})
			if user.Repositories.Cursor == nil {
				break
			}
			cursor = user.Repositories.Cursor
		}
		vaxis.PostMsg(vaxis.SendMsg{
			Msg:   repos,
			Model: cmd.From,
		})
	case shtc.OpenRepo:
		// see if the destination already exists, in which case we pull
		dest := path.Join(w.cache, cmd.Name)

M git/model.go => git/model.go +19 -12
@@ 43,18 43,25 @@ func NewModel() *Model {
	return m
}

func (m *Model) updateFiltered() {
	m.filtered = []Repository{}
	for _, repo := range m.repos {
		if m.filterMatch(repo) {
			m.filtered = append(m.filtered, repo)
		}
	}
}

func (m *Model) Update(msg vaxis.Msg) {
	switch msg := msg.(type) {
	case *widgets.Tab:
		m.tab = msg
	case []Repository:
		m.selected = 0
		m.top = 0
		m.filtered = msg
		m.repos = msg
		if m.tab != nil {
			m.tab.Spinner.Stop()
		}
		m.repos = append(m.repos, msg...)
		m.updateFiltered()
	case vaxis.Key:
		if m.editor != nil {
			m.editor.Update(msg)


@@ 71,12 78,7 @@ func (m *Model) Update(msg vaxis.Msg) {
				m.top = 0
				m.selected = 0
				m.filter.Update(msg)
				m.filtered = []Repository{}
				for _, repo := range m.repos {
					if m.filterMatch(repo) {
						m.filtered = append(m.filtered, repo)
					}
				}
				m.updateFiltered()
				return
			}
		}


@@ 145,6 147,10 @@ func (m *Model) Update(msg vaxis.Msg) {
	case shtc.Cmdline:
		switch {
		case strings.HasPrefix(msg.Args[0], "~"):
			m.repos = []Repository{}
			m.filtered = m.repos
			m.top = 0
			m.selected = 0
			m.tab.Spinner.Start()
			vaxis.PostCmd(shtc.FetchUserRepoList{
				Context:  context.Background(),


@@ 169,6 175,7 @@ func (m *Model) Draw(win vaxis.Window) {
		Text:       " | ",
		Foreground: vaxis.IndexColor(7),
	}
	listWin := vaxis.NewWindow(&win, 0, 0, 0, h-1)
	// h-1 because we leave the bottom row empty
	for i := 0; i < (h - 1); i += 1 {
		if len(m.filtered) == 0 {


@@ 179,7 186,7 @@ func (m *Model) Draw(win vaxis.Window) {
		}
		repo := m.filtered[repoIndex+m.top]

		w := vaxis.NewWindow(&win, 2, i, 0, 1)
		w := vaxis.NewWindow(&listWin, 2, i, 0, 1)
		name := vaxis.Segment{
			Text:       repo.Owner.CanonicalName + "/" + repo.Name,
			Foreground: vaxis.IndexColor(4),


@@ 227,7 234,7 @@ func (m *Model) Draw(win vaxis.Window) {
		}
		vaxis.PrintSegments(w, name, vis, separator, upd)
		if desc.Text != "" {
			dw := vaxis.NewWindow(&win, 6, i+1, 0, 1)
			dw := vaxis.NewWindow(&listWin, 6, i+1, 0, 1)
			i += 1
			vaxis.PrintSegments(dw, desc)
		}