Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@sei40kr
Copy link
Contributor

@sei40kr sei40kr commented Dec 13, 2025

Improve menu display by aligning keys and labels in columns. Keys are right-padded to match the longest key in each column.

When multiple key bindings are grouped for the same operation (e.g., "k/up" or "ctrl+k/ctrl+up"), the maximum width is calculated based on the combined string length.

Before:

 Y Show Refs              b Branch
 k/up Up                  c Commit
 ctrl+k/ctrl+up Up line   h/? Help

After:

 Y              Show Refs   b   Branch
 k/up           Up          c   Commit
 ctrl+k/ctrl+up Up line     h/? Help

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.5 [email protected]

Improve menu display by aligning keys and labels in columns. Keys
are right-padded to match the longest key in each column.

When multiple key bindings are grouped for the same operation (e.g.,
"k/up" or "ctrl+k/ctrl+up"), the maximum width is calculated based
on the combined string length.

Before:
```
 Y Show Refs              b Branch
 k/up Up                  c Commit
 ctrl+k/ctrl+up Up line   h/? Help
```

After:
```
 Y              Show Refs   b   Branch
 k/up           Up          c   Commit
 ctrl+k/ctrl+up Up line     h/? Help
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@sei40kr
Copy link
Contributor Author

sei40kr commented Dec 13, 2025

Note: This PR will likely conflict with #475 as both modify the menu rendering code in src/ui/menu.rs.

- Extract key string formatting into helper functions with shared macro
- Extract padding calculation into dedicated function
- Eliminate duplicate iteration by collecting grouped bindings once
- Improve code maintainability while preserving functionality
Copy link
Owner

@altsem altsem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

layout.vertical(None, OPTS, |layout| {
        ui::repeat_chars(layout, width, ui::DASHES, ui::STYLE);

        layout.horizontal(None, OPTS.gap(3).pad(1), |layout| {
            layout.vertical(None, OPTS, |layout| {
                // TODO Print header e.g. "Help"

                layout.horizontal(None, OPTS.gap(1), |layout| {
                    layout.vertical(None, OPTS, |layout| {
                        for (op, _binds) in grouped_bindings.iter() {
                            // TODO Print keys e.g. "q/esc"
                        }
                    });

                    layout.vertical(None, OPTS, |layout| {
                        for (_op, binds) in grouped_bindings.iter() {
                            // TODO Print op e.g. "Quit/Close"
                        }
                    });
                });
            });

            // etc...

Replace manual padding calculation with layout system's automatic
column width alignment. Introduces `layout_keybinds_table` helper
function that uses horizontal layout with two vertical columns
(keys and labels) separated by gap(1).

Key improvements:
- Removed `calc_padding` function and max width calculations
- Use `partition` to efficiently split bindings by type
- Use `into_iter` instead of `iter` where ownership can be moved
- Extract common key-value table pattern into helper function
- Let layout system handle column alignment automatically
- Fix `layout_line` to properly merge Line and Span styles

The visual output remains unchanged.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants