-
Notifications
You must be signed in to change notification settings - Fork 44
Add classic and spacious TUI layouts #354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TyRichards
wants to merge
5
commits into
basecamp:main
Choose a base branch
from
TyRichards:feature/tui-layout-style
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e0451eb
Add classic and spacious TUI layouts
TyRichards 94834e1
Refine spacious TUI spacing
TyRichards 49a8707
Add TUI layout demo
TyRichards 301216d
Move the layout notes to docs/tui.md, where the manual now lives
jeremy 6cf8eba
Keep Ctrl+G live in The Screener, collapse gaps below five rows, and …
jeremy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,101 @@ | ||
| package tui | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "charm.land/lipgloss/v2" | ||
| ) | ||
|
|
||
| // Layout names the amount of structure and space the TUI gives its content. | ||
| // Classic is the original edge-to-edge presentation. Spacious separates list rows | ||
| // and adds vertical breathing room, while leaving the terminal theme in charge of color. | ||
| type Layout string | ||
|
|
||
| const ( | ||
| LayoutClassic Layout = "classic" | ||
| LayoutSpacious Layout = "spacious" | ||
| ) | ||
|
|
||
| // ParseLayout reads a layout name accepted by the tui command. | ||
| func ParseLayout(value string) (Layout, error) { | ||
| switch layout := Layout(strings.ToLower(strings.TrimSpace(value))); layout { | ||
| case LayoutClassic, LayoutSpacious: | ||
| return layout, nil | ||
| default: | ||
| return "", fmt.Errorf("layout must be classic or spacious (got %q)", value) | ||
| } | ||
| } | ||
|
|
||
| func (l Layout) normalized() Layout { | ||
| if l == LayoutSpacious { | ||
| return l | ||
| } | ||
| return LayoutClassic | ||
| } | ||
|
|
||
| func (l Layout) toggled() Layout { | ||
| if l.normalized() == LayoutSpacious { | ||
| return LayoutClassic | ||
| } | ||
| return LayoutSpacious | ||
| } | ||
|
|
||
| // layoutMetrics are the cells spent around and between content. A small terminal | ||
| // keeps the selected layout but collapses its chrome until there is room again. | ||
| type layoutMetrics struct { | ||
| spacious bool | ||
| paddingX int | ||
| paddingY int | ||
| itemGap int | ||
| } | ||
|
|
||
| func (l Layout) metrics(width, height int) layoutMetrics { | ||
| if l.normalized() != LayoutSpacious || width < 48 || height < 16 { | ||
| return layoutMetrics{} | ||
| } | ||
| return layoutMetrics{spacious: true, paddingY: 1, itemGap: 1} | ||
| } | ||
|
|
||
| func (m layoutMetrics) horizontalChrome() int { | ||
| if !m.spacious { | ||
| return 0 | ||
| } | ||
| return 2 * m.paddingX | ||
| } | ||
|
|
||
| func (m layoutMetrics) verticalChrome() int { | ||
| if !m.spacious { | ||
| return 0 | ||
| } | ||
| return 2 * m.paddingY | ||
| } | ||
|
|
||
| func (m layoutMetrics) headerGap() int { | ||
| if m.spacious { | ||
| return 1 | ||
| } | ||
| return 0 | ||
| } | ||
|
|
||
| func (m layoutMetrics) footerChrome() int { | ||
| if m.spacious { | ||
| return 0 | ||
| } | ||
| return 3 // two clear rows and the divider | ||
| } | ||
|
|
||
| func (m layoutMetrics) drawFooterRule() bool { | ||
| return !m.spacious | ||
| } | ||
|
|
||
| func (m layoutMetrics) render(content string, width, height int) string { | ||
| if !m.spacious { | ||
| return content | ||
| } | ||
| return lipgloss.NewStyle(). | ||
| Padding(m.paddingY, m.paddingX). | ||
| Width(width). | ||
| Height(height). | ||
| Render(content) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.