<commit_before>package keys

import (
	"fmt"

	"github.com/ambientsound/pms/console"
	"github.com/ambientsound/pms/keysequence"
	"github.com/gdamore/tcell/v2"
)

// Binding holds a parsed, user provided key sequence.
type Binding struct {
	Command  string
	Sequence keysequence.KeySequence
}

// Sequencer holds all the keyboard bindings and their action mappings.
type Sequencer struct {
	binds []Binding
	event *tcell.EventKey
	input keysequence.KeySequence
}

// NewSequencer returns Sequencer.
func NewSequencer() *Sequencer {
	return &Sequencer{
		binds: make([]Binding, 0),
		input: make(keysequence.KeySequence, 0),
	}
}

// AddBind creates a new key mapping.
func (s *Sequencer) AddBind(seq keysequence.KeySequence, command string) error {
	if s.dupes(seq) {
		return fmt.Errorf("Can't bind: conflicting with already bound key sequence")
	}
	s.binds = append(s.binds, Binding{Sequence: seq, Command: command})
	return nil
}

// RemoveBind removes a key mapping.
func (s *Sequencer) RemoveBind(seq keysequence.KeySequence) error {
	for i := range s.binds {
		if keysequence.Compare(s.binds[i].Sequence, seq) {
			// Overwrite this position with the last in the list
			s.binds[i] = s.binds[len(s.binds)-1]

			// Truncate to remove the (now duplicate) last entry
			s.binds = s.binds[:len(s.binds)-1]

			return nil
		}
	}

	return fmt.Errorf("Can't unbind: sequence not bound")
}

// KeyInput feeds a keypress to the sequencer. Returns true if there is one match or more, or false if there is no match.
func (s *Sequencer) KeyInput(ev *tcell.EventKey) bool {
	console.Log("Key event: %s", keysequence.FormatKey(ev))
	s.input = append(s.input, ev)
	if len(s.find(s.input)) == 0 {
		s.input = make(keysequence.KeySequence, 0)<commit_msg>Pet the static checker: Error messages should start lowercase<commit_after>package keys

import (
	"fmt"

	"github.com/ambientsound/pms/console"
	"github.com/ambientsound/pms/keysequence"
	"github.com/gdamore/tcell/v2"
)

// Binding holds a parsed, user provided key sequence.
type Binding struct {
	Command  string
	Sequence keysequence.KeySequence
}

// Sequencer holds all the keyboard bindings and their action mappings.
type Sequencer struct {
	binds []Binding
	event *tcell.EventKey
	input keysequence.KeySequence
}

// NewSequencer returns Sequencer.
func NewSequencer() *Sequencer {
	return &Sequencer{
		binds: make([]Binding, 0),
		input: make(keysequence.KeySequence, 0),
	}
}

// AddBind creates a new key mapping.
func (s *Sequencer) AddBind(seq keysequence.KeySequence, command string) error {
	if s.dupes(seq) {
		return fmt.Errorf("can't bind: conflicting with already bound key sequence")
	}
	s.binds = append(s.binds, Binding{Sequence: seq, Command: command})
	return nil
}

// RemoveBind removes a key mapping.
func (s *Sequencer) RemoveBind(seq keysequence.KeySequence) error {
	for i := range s.binds {
		if keysequence.Compare(s.binds[i].Sequence, seq) {
			// Overwrite this position with the last in the list
			s.binds[i] = s.binds[len(s.binds)-1]

			// Truncate to remove the (now duplicate) last entry
			s.binds = s.binds[:len(s.binds)-1]

			return nil
		}
	}

	return fmt.Errorf("can't unbind: sequence not bound")
}

// KeyInput feeds a keypress to the sequencer. Returns true if there is one match or more, or false if there is no match.
func (s *Sequencer) KeyInput(ev *tcell.EventKey) bool {
	console.Log("Key event: %s", keysequence.FormatKey(ev))
	s.input = append(s.input, ev)
	if len(s.find(s.input)) == 0 {
		s.input = make(keysequence.KeySequence, 0)
{'fraction_non_alphanumeric': 0.11686474250141483, 'fraction_numerical': 0.003961516694963215, 'mean_word_length': 4.145560407569141, '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': '7346885', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1178, 'n_words': 361}