-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Dynamic width terminal calculation for help #815
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThe pull request includes modifications to enhance the handling of flag descriptions in the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
internal/tui/templates/templater.go (1)
32-46
: Consider documenting the padding constant and adding bounds checking.The implementation looks solid, warrior! A few suggestions to make it even more robust:
- The magic number
-2
for padding should be documented or defined as a constant.- Consider adding an upper bound check to prevent unreasonably large terminal widths.
func getTerminalWidth() int { defaultWidth := 80 + const terminalPadding = 2 // Padding for terminal margins screenWidth := defaultWidth // Detect terminal width and use it by default if available if term.IsTerminal(int(os.Stdout.Fd())) { termWidth, _, err := term.GetSize(int(os.Stdout.Fd())) - if err == nil && termWidth > 0 { - screenWidth = termWidth - 2 + if err == nil && termWidth > 0 { + // Cap width at reasonable maximum (e.g., 200 columns) + if termWidth > 200 { + termWidth = 200 + } + screenWidth = termWidth - terminalPadding } } return screenWidth }internal/tui/templates/help_printer.go (1)
93-100
: Enhance code clarity with constants and better variable names.Strong implementation, warrior! A few suggestions to make it even clearer:
- The magic number
4
in the width calculation should be a named constant- Consider more descriptive names for clarity
+const ( + // ... existing constants ... + descriptionPadding = 4 // Padding between flag name and description +) - availWidth := int(p.wrapLimit) - p.maxFlagLen - 4 + descriptionWidth := int(p.wrapLimit) - p.maxFlagLen - descriptionPadding - if availWidth < minDescWidth { + if descriptionWidth < minDescWidth { if _, err := fmt.Fprintf(p.out, "%s\n", flagName); err != nil { return } flagName = strings.Repeat(" ", p.maxFlagLen) - availWidth = int(p.wrapLimit) - 4 + descriptionWidth = int(p.wrapLimit) - descriptionPadding }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (2)
internal/tui/templates/help_printer.go
(3 hunks)internal/tui/templates/templater.go
(3 hunks)
🔇 Additional comments (2)
internal/tui/templates/templater.go (1)
79-80
: Well done on the dynamic width integration!
The change from static width to dynamic calculation aligns perfectly with the PR objectives.
internal/tui/templates/help_printer.go (1)
Line range hint 110-124
: Excellent handling of multi-line descriptions!
The word wrapping implementation is robust and maintains consistent formatting. Good error handling on the writes!
if term.IsTerminal(int(os.Stdout.Fd())) { | ||
termWidth, _, err := term.GetSize(int(os.Stdout.Fd())) | ||
if err == nil && termWidth > 0 { | ||
screenWidth = termWidth - 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider documenting the padding constant and adding bounds checking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Cerebrovinny can we fix the column widths to be a little bit more responsive too? Note they are too narrow. |
what
Help should detect proper screen width
why
Terminal Width should be dynamic calculated when the user prints help menu
references
Summary by CodeRabbit
New Features
Bug Fixes