<commit_before>package widgets

import (
	"fmt"
	"io"

	"github.com/jroimartin/gocui"
)

type Items interface {
	Display(w io.Writer)
	Len() int
}

type EmptyItems struct{}

func (e *EmptyItems) Display(w io.Writer) {}
func (e *EmptyItems) Len() int            { return 0 }

type SelectionEvent int
type Selected struct {
	Type  SelectionEvent
	Index int
	Items Items
}

const (
	OnSelect SelectionEvent = iota
	OnEnter
)

type list struct {
	*UI
	items    Items
	current  int
	selected chan *Selected
}

func NewList(ui *UI) (*list, chan *Selected) {
	selected := make(chan *Selected)
	l := &list{
		ui,
		&EmptyItems{},
		-1,
		selected,
	}

	l.AddLocalKey(gocui.KeyArrowUp, "Move selection up one line", l.Previous)
	l.AddLocalKey(gocui.KeyArrowDown, "Move selection down one line", l.Next)
	l.AddLocalKey(gocui.KeyEnter, "Select current line", func() { l.fire(OnEnter) })

	return l, selected
}

func (l *list) SetSelection(index int) {
	l.Update(func(v *gocui.View) {
		count := l.items.Len()<commit_msg>Added j,k to move selection up and down.<commit_after>package widgets

import (
	"fmt"
	"io"

	"github.com/jroimartin/gocui"
)

type Items interface {
	Display(w io.Writer)
	Len() int
}

type EmptyItems struct{}

func (e *EmptyItems) Display(w io.Writer) {}
func (e *EmptyItems) Len() int            { return 0 }

type SelectionEvent int
type Selected struct {
	Type  SelectionEvent
	Index int
	Items Items
}

const (
	OnSelect SelectionEvent = iota
	OnEnter
)

type list struct {
	*UI
	items    Items
	current  int
	selected chan *Selected
}

func NewList(ui *UI) (*list, chan *Selected) {
	selected := make(chan *Selected)
	l := &list{
		ui,
		&EmptyItems{},
		-1,
		selected,
	}

	l.AddLocalKey(gocui.KeyArrowUp, "Move selection up one line", l.Previous)
	l.AddLocalKey('k', "Move selection up one line", l.Previous)
	l.AddLocalKey(gocui.KeyArrowDown, "Move selection down one line", l.Next)
	l.AddLocalKey('j', "Move selection down one line", l.Next)

	l.AddLocalKey(gocui.KeyEnter, "Select current line", func() { l.fire(OnEnter) })

	return l, selected
}

func (l *list) SetSelection(index int) {
	l.Update(func(v *gocui.View) {
		count := l.items.Len()
{'fraction_non_alphanumeric': 0.1282287822878229, 'fraction_numerical': 0.0018450184501845018, 'mean_word_length': 3.9295454545454547, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4784089', 'n_tokens_mistral': 829, 'n_tokens_neox': 799, 'n_words': 226}