<commit_before>package gui

import (
	"github.com/felixangell/phi/cfg"
	"github.com/felixangell/strife"
	"github.com/veandco/go-sdl2/sdl"
	"log"
	"strings"
)

type CommandPalette struct {
	BaseComponent
	buff       *Buffer
	parentBuff *Buffer
}

func NewCommandPalette(conf cfg.TomlConfig, view *View) *CommandPalette {
	conf.Editor.Show_Line_Numbers = false
	conf.Editor.Highlight_Line = false

	palette := &CommandPalette{
		buff:       NewBuffer(&conf, nil, 0),
		parentBuff: nil,
	}
	palette.buff.appendLine("")

	palette.Resize(view.w/3, 48)
	palette.Translate((view.w/2)-(palette.w/2), 10)
	palette.buff.Resize(palette.w, palette.h)
	palette.buff.Translate((view.w/2)-(palette.w/2), 10)

	return palette
}

func (b *CommandPalette) OnInit() {
	b.buff.Translate(b.x, b.y)
	b.buff.Resize(b.w, b.h)
}

func (b *CommandPalette) processCommand() {
	tokenizedLine := strings.Split(b.buff.contents[0].String(), " ")

	command := tokenizedLine[0]

	action, exists := actions[command]
	if !exists {
		return
	}

	action(b.parentBuff)
}

func (b *CommandPalette) clearInput() {
	actions["delete_line"](b.buff)
}

func (b *CommandPalette) OnUpdate() bool {
	if !b.HasFocus() {
		return false
	}

	override := func(k int) bool {
		if k != sdl.K_RETURN {
			return false
		}

		b.processCommand()
		b.parentBuff.parent.hidePalette()<commit_msg>palette closes on esc keypress<commit_after>package gui

import (
	"github.com/felixangell/phi/cfg"
	"github.com/felixangell/strife"
	"github.com/veandco/go-sdl2/sdl"
	"log"
	"strings"
)

type CommandPalette struct {
	BaseComponent
	buff       *Buffer
	parentBuff *Buffer
}

func NewCommandPalette(conf cfg.TomlConfig, view *View) *CommandPalette {
	conf.Editor.Show_Line_Numbers = false
	conf.Editor.Highlight_Line = false

	palette := &CommandPalette{
		buff:       NewBuffer(&conf, nil, 0),
		parentBuff: nil,
	}
	palette.buff.appendLine("")

	palette.Resize(view.w/3, 48)
	palette.Translate((view.w/2)-(palette.w/2), 10)
	palette.buff.Resize(palette.w, palette.h)
	palette.buff.Translate((view.w/2)-(palette.w/2), 10)

	return palette
}

func (b *CommandPalette) OnInit() {
	b.buff.Translate(b.x, b.y)
	b.buff.Resize(b.w, b.h)
}

func (b *CommandPalette) processCommand() {
	tokenizedLine := strings.Split(b.buff.contents[0].String(), " ")

	command := tokenizedLine[0]

	action, exists := actions[command]
	if !exists {
		return
	}

	action(b.parentBuff)
}

func (b *CommandPalette) clearInput() {
	actions["delete_line"](b.buff)
}

func (b *CommandPalette) OnUpdate() bool {
	if !b.HasFocus() {
		return false
	}

	override := func(k int) bool {
		if k != sdl.K_RETURN && k != sdl.K_ESCAPE {
			return false
		}

		b.processCommand()
		b.parentBuff.parent.hidePalette()
{'fraction_non_alphanumeric': 0.1544985250737463, 'fraction_numerical': 0.011061946902654867, 'mean_word_length': 4.157794676806084, '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': '1146823', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1065, 'n_words': 191}