DEVELOPMENT ENVIRONMENT

~liljamo/tamma

ref: 0.3.1 tamma/components/confirm/keymap.go -rw-r--r-- 993 bytes
7115a178Jonni Liljamo fix: nix build 13 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * Copyright (C) 2025 Jonni Liljamo <jonni@liljamo.com>
 *
 * This file is licensed under GPL-3.0-only, see NOTICE and LICENSE for
 * more information.
 */

package confirm

import "github.com/charmbracelet/bubbles/key"

// KeyMap defines key bindings for the output viewport.
type KeyMap struct {
	Submit key.Binding
	Back   key.Binding
}

// NewKeyMap returns a new KeyMap.
func NewKeyMap() *KeyMap {
	return &KeyMap{
		Submit: key.NewBinding(
			key.WithKeys("enter"),
			key.WithHelp("enter", "submit"),
		),
		Back: key.NewBinding(
			key.WithKeys("q"),
			key.WithHelp("q", "back"),
		),
	}
}

// ShortHelp returns keybindings to be shown in the mini help view. It's part
// of the key.Map interface.
func (k KeyMap) ShortHelp() []key.Binding {
	return []key.Binding{k.Submit, k.Back}
}

// FullHelp returns keybindings for the expanded help view. It's part of the
// key.Map interface.
func (k KeyMap) FullHelp() [][]key.Binding {
	return [][]key.Binding{
		{k.Submit, k.Back},
	}
}