~rockorager/shtc

0dae4a0a95ac45fab8aa6d20829321ba738271e4 — Tim Culverhouse 1 year, 4 months ago 590309e
git: add highlighting to filter

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
1 files changed, 45 insertions(+), 10 deletions(-)

M git/model.go
M git/model.go => git/model.go +45 -10
@@ 187,10 187,29 @@ func (m *Model) Draw(win vaxis.Window) {
		repo := m.filtered[repoIndex+m.top]

		w := vaxis.NewWindow(&listWin, 2, i, 0, 1)
		name := vaxis.Segment{
			Text:       repo.Owner.CanonicalName + "/" + repo.Name,
		nameBefore := vaxis.Segment{
			Text:       repo.Owner.CanonicalName + "/",
			Foreground: vaxis.IndexColor(4),
		}
		nameHi := vaxis.Segment{
			Foreground: vaxis.IndexColor(3),
		}
		nameAfter := vaxis.Segment{
			Foreground: vaxis.IndexColor(4),
		}
		ind := strings.Index(strings.ToLower(repo.Name), m.filter.Content.Text)
		switch ind {
		case -1:
			nameBefore.Text += repo.Name
		default:
			b := repo.Name[0:ind]
			hi := repo.Name[ind : ind+len(m.filter.Content.Text)]
			a := repo.Name[ind+len(m.filter.Content.Text):]
			nameBefore.Text += b
			nameHi.Text = hi
			nameAfter.Text = a
		}

		vis := vaxis.Segment{
			Attributes: vaxis.AttrItalic | vaxis.AttrDim,
		}


@@ 224,19 243,35 @@ func (m *Model) Draw(win vaxis.Window) {
			upd.Text = repo.Updated.Format("Jan 02 2006")
		}

		desc := vaxis.Segment{}
		if repo.Description != nil {
			desc.Text = *repo.Description
		}
		if repoIndex+m.top == m.selected {
			name.Attributes = vaxis.AttrReverse
			nameBefore.Attributes = vaxis.AttrReverse
			nameHi.Attributes = vaxis.AttrReverse
			nameAfter.Attributes = vaxis.AttrReverse
			drewSelected = true
		}
		vaxis.PrintSegments(w, name, vis, separator, upd)
		if desc.Text != "" {
		vaxis.PrintSegments(w, nameBefore, nameHi, nameAfter, vis, separator, upd)
		if repo.Description != nil {
			descBefore := vaxis.Segment{}
			descHi := vaxis.Segment{
				Foreground: vaxis.IndexColor(3),
			}
			descAfter := vaxis.Segment{}
			desc := *repo.Description
			ind := strings.Index(strings.ToLower(desc), m.filter.Content.Text)
			switch ind {
			case -1:
				descBefore.Text = desc
			default:
				b := desc[0:ind]
				hi := desc[ind : ind+len(m.filter.Content.Text)]
				a := desc[ind+len(m.filter.Content.Text):]
				descBefore.Text = b
				descHi.Text = hi
				descAfter.Text = a
			}
			dw := vaxis.NewWindow(&listWin, 6, i+1, 0, 1)
			i += 1
			vaxis.PrintSegments(dw, desc)
			vaxis.PrintSegments(dw, descBefore, descHi, descAfter)
		}
		repoIndex += 1
		i += 1