-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for non-color terminals
Closes #35
- Loading branch information
Showing
11 changed files
with
174 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package movie | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/charmbracelet/bubbles/help" | ||
"github.com/charmbracelet/bubbles/key" | ||
"github.com/charmbracelet/lipgloss" | ||
"github.com/muesli/termenv" | ||
) | ||
|
||
func RenderHelpWithProfile(p termenv.Profile, m help.Model, bindings []key.Binding) string { | ||
if len(bindings) == 0 { | ||
return "" | ||
} | ||
|
||
var b strings.Builder | ||
var totalWidth int | ||
separator := m.Styles.ShortSeparator.Inline(true).RenderWithProfile(p, m.ShortSeparator) | ||
|
||
for i, kb := range bindings { | ||
if !kb.Enabled() { | ||
continue | ||
} | ||
|
||
var sep string | ||
if totalWidth > 0 && i < len(bindings) { | ||
sep = separator | ||
} | ||
|
||
str := sep + | ||
m.Styles.ShortKey.Inline(true).RenderWithProfile(p, kb.Help().Key) + " " + | ||
m.Styles.ShortDesc.Inline(true).RenderWithProfile(p, kb.Help().Desc) | ||
|
||
w := lipgloss.Width(str) | ||
|
||
// If adding this help item would go over the available width, stop | ||
// drawing. | ||
if m.Width > 0 && totalWidth+w > m.Width { | ||
// Although if there's room for an ellipsis, print that. | ||
tail := " " + m.Styles.Ellipsis.Inline(true).RenderWithProfile(p, m.Ellipsis) | ||
tailWidth := lipgloss.Width(tail) | ||
|
||
if totalWidth+tailWidth < m.Width { | ||
b.WriteString(tail) | ||
} | ||
|
||
break | ||
} | ||
|
||
totalWidth += w | ||
b.WriteString(str) | ||
} | ||
|
||
return b.String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.