<commit_before>package tui

import (
	"image"

	"github.com/gdamore/tcell"
)

var _ UI = &tcellUI{}

type tcellUI struct {
	painter *Painter
	root    Widget

	keybindings []*keybinding

	quit chan struct{}

	screen tcell.Screen

	kbFocus *kbFocusController

	eventQueue chan event
}

func newTcellUI(root Widget) (*tcellUI, error) {
	screen, err := tcell.NewScreen()
	if err != nil {
		return nil, err
	}

	s := &tcellSurface{
		screen: screen,
	}
	p := NewPainter(s, DefaultTheme)

	return &tcellUI{
		painter:     p,
		root:        root,
		keybindings: make([]*keybinding, 0),
		quit:        make(chan struct{}, 1),
		screen:      screen,
		kbFocus:     &kbFocusController{chain: DefaultFocusChain},
		eventQueue:  make(chan event),
	}, nil
}

func (ui *tcellUI) SetWidget(w Widget) {
	ui.root = w
}

func (ui *tcellUI) SetTheme(t *Theme) {
	ui.painter.theme = t
}

func (ui *tcellUI) SetFocusChain(chain FocusChain) {
	ui.kbFocus.chain = chain
}

func (ui *tcellUI) SetKeybinding(seq string, fn func()) {
	ui.keybindings = append(ui.keybindings, &keybinding{
		sequence: seq,
		handler:  fn,<commit_msg>Update focusedWidget field when SetFocusChain() called<commit_after>package tui

import (
	"image"

	"github.com/gdamore/tcell"
)

var _ UI = &tcellUI{}

type tcellUI struct {
	painter *Painter
	root    Widget

	keybindings []*keybinding

	quit chan struct{}

	screen tcell.Screen

	kbFocus *kbFocusController

	eventQueue chan event
}

func newTcellUI(root Widget) (*tcellUI, error) {
	screen, err := tcell.NewScreen()
	if err != nil {
		return nil, err
	}

	s := &tcellSurface{
		screen: screen,
	}
	p := NewPainter(s, DefaultTheme)

	return &tcellUI{
		painter:     p,
		root:        root,
		keybindings: make([]*keybinding, 0),
		quit:        make(chan struct{}, 1),
		screen:      screen,
		kbFocus:     &kbFocusController{chain: DefaultFocusChain},
		eventQueue:  make(chan event),
	}, nil
}

func (ui *tcellUI) SetWidget(w Widget) {
	ui.root = w
}

func (ui *tcellUI) SetTheme(t *Theme) {
	ui.painter.theme = t
}

func (ui *tcellUI) SetFocusChain(chain FocusChain) {
	if ui.kbFocus.focusedWidget != nil {
		ui.kbFocus.focusedWidget.SetFocused(false)
	}

	ui.kbFocus.chain = chain
	ui.kbFocus.focusedWidget = chain.FocusDefault()

	if ui.kbFocus.focusedWidget != nil {
		ui.kbFocus.focusedWidget.SetFocused(true)
	}
}

func (ui *tcellUI) SetKeybinding(seq string, fn func()) {
	ui.keybindings = append(ui.keybindings, &keybinding{
		sequence: seq,
		handler:  fn,
{'fraction_non_alphanumeric': 0.12686868686868688, 'fraction_numerical': 0.0016161616161616162, 'mean_word_length': 3.8077669902912623, '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': '3040123', 'n_tokens_mistral': 986, 'n_tokens_neox': 920, 'n_words': 224}