| 71 | } |
| 72 | |
| 73 | func TestMenu_ShortcutsLeftAlignedKeysRightAligned(t *testing.T) { |
| 74 | menu := NewMenu( |
| 75 | MenuItem{Label: "Go", Key: 0, Shortcut: WithHelp(NewKeyBinding("g"), "g", "")}, |
| 76 | MenuItem{Label: "Stop", Key: 1, Shortcut: WithHelp(NewKeyBinding("s"), "s", "")}, |
| 77 | ) |
| 78 | menu.SetWidth(20) |
| 79 | |
| 80 | view := ansi.Strip(menu.View()) |
| 81 | lines := strings.Split(view, "\n") |
| 82 | |
| 83 | for _, line := range lines { |
| 84 | assert.Equal(t, 20, lipgloss.Width(line)) |
| 85 | } |
| 86 | |
| 87 | // Labels left-aligned |
| 88 | assert.True(t, strings.HasPrefix(lines[0], "Go")) |
| 89 | assert.True(t, strings.HasPrefix(lines[1], "Stop")) |
| 90 | |
| 91 | // Shortcut keys right-aligned |
| 92 | assert.True(t, strings.HasSuffix(lines[0], "g")) |
| 93 | assert.True(t, strings.HasSuffix(lines[1], "s")) |
| 94 | } |
| 95 | |
| 96 | func TestMenu_ShortcutsAlignedWithMixedLabelLengths(t *testing.T) { |
| 97 | menu := NewMenu( |