Skip to content

Add configuration for columnar menu traversal direction - #16724

Merged
fdncred merged 6 commits into
nushell:mainfrom
simonborje:add_configuration_for_columnar_menu_traversal_direction
Sep 22, 2025
Merged

fdncred merged 6 commits into
nushell:mainfrom
simonborje:add_configuration_for_columnar_menu_traversal_direction

Conversation

@simonborje

@simonborje simonborje commented Sep 20, 2025 •

Copy link
Copy Markdown
Contributor

Make columnar menu tab traversal direction configurable. The configurable traversal direction feature was added to reedline with nushell/reedline#951. This PR makes that configuration option available in nushell.

Release notes summary - What our users need to know

The feature makes it possible to choose the direction that items are placed in the columnar menu. With the default value of "horizontal", items are ordered left-to-right in each row, with later items appearing in rows below earlier items.

1   2   3   4
5   6   7   8
9   10

With the value set to "vertical", items are ordered top-to-bottom in each column, with later items appearing in columns to the right of earlier items.

1   4   7   10
2   5   8
3   6   9

The configuration option is currently called "tab_traversal" with a default value of "horizontal".

In order to toggle horizontal or vertical, add or update the completion_menu in your config.nu

# Example - Completion menu configuration
$env.config.menus ++= [{
    name: completion_menu
    only_buffer_difference: false     # Search is done on the text written after activating the menu
    marker: "| "                      # Indicator that appears with the menu is active
    type: {
        layout: columnar              # Type of menu
        columns: 4                    # Number of columns where the options are displayed
        col_width: 20                 # Optional value. If missing all the screen width is used to calculate column width
        col_padding: 2                # Padding between columns
        tab_traversal: "horizontal"   # Direction in which pressing <Tab> will cycle through options, "horizontal" or "vertical"
    }
    style: {
        text: green                   # Text style
        selected_text: green_reverse  # Text style for selected option
        description_text: yellow      # Text style for description
    }
}]

Tasks after submitting

@fdncred

fdncred commented Sep 20, 2025

Copy link
Copy Markdown
Contributor

Thanks for adding this. I think we should also add some documentation to the doc_config.nu to help people understand how to change from vertical to horizontal. Perhaps somewhere in this section. This could be in a separate PR if needed.

Comment thread Cargo.toml Resolved
Comment thread Cargo.lock Resolved
@simonborje

Copy link
Copy Markdown
Contributor Author

Thanks for adding this. I think we should also add some documentation to the doc_config.nu to help people understand how to change from vertical to horizontal. Perhaps somewhere in this section. This could be in a separate PR if needed.

I'm not sure how to best introduce the new information in that file, there doesn't seem to be a lot of details about menus there currently. The file does suggest going to https://www.nushell.sh/book/line_editor.html#menus for more details, and updating the sample configuration under the "columnar menu" heading to include the traversal setting would likely be helpful. That's where I ended up when I searched for the available settings for the menu.

@fdncred

fdncred commented Sep 21, 2025 •

Copy link
Copy Markdown
Contributor

I'm not sure how to best introduce the new information in that file, there doesn't seem to be a lot of details about menus there currently. The file does suggest going to https://www.nushell.sh/book/line_editor.html#menus for more details, and updating the sample configuration under the "columnar menu" heading to include the traversal setting would likely be helpful. That's where I ended up when I searched for the available settings for the menu.

You might just put the completion menu in there with the new setting but have the whole thing commented out but with a description of the new option. I'm really just trying to figure out how people will discover this feature and be able to toggle it.

@simonborje

Copy link
Copy Markdown
Contributor Author

I'm not sure how to best introduce the new information in that file, there doesn't seem to be a lot of details about menus there currently. The file does suggest going to https://www.nushell.sh/book/line_editor.html#menus for more details, and updating the sample configuration under the "columnar menu" heading to include the traversal setting would likely be helpful. That's where I ended up when I searched for the available settings for the menu.

You might just put the completion menu in there with the new setting but have the whole thing commented out but with a description of the new option. I'm really just trying to figure out how people will discover this feature and be able to toggle it.

I added a configuration example with a short description as a comment - is that description enough or should it be expanded in some way?
Most other examples in the file were not commented out so I left this one uncommented as well as it makes the example get printed with syntax highlighting when using the suggested config nu --doc | nu-highlight | less -R command.

When we are happy with the comment I could create a PR for adding the option and comment to https://www.nushell.sh/book/line_editor.html#completion-menu as well.

@fdncred

fdncred commented Sep 22, 2025

Copy link
Copy Markdown
Contributor

I think it looks good. Thanks!

@fdncred
fdncred merged commit 378404e into nushell:main Sep 22, 2025
@github-actions github-actions Bot added this to the v0.108.0 milestone Sep 22, 2025
@fdncred fdncred added notes:ready Indicates Ready for Release notes notes:additions Noted in "Additions" section labels Sep 22, 2025
@fdncred

fdncred commented Sep 22, 2025

Copy link
Copy Markdown
Contributor

@simonborje Can you please look into this. I'm not seeing horizontal or vertical even though my current settings are setting it.

  {
    name: completion_menu
    only_buffer_difference: false
    marker: $" \n❯ (char -u '1f4ce') "
    type: {
      layout: columnar
      columns: 4
      col_width: 20   # Optional value. If missing all the screen width is used to calculate column width
      col_padding: 2
      tab_traversal: "horizontal"   # Direction in which pressing <Tab> will cycle through options, "horizontal" or "vertical"
    }
    style: {
      text: { fg: "#33ff00" }
      selected_text: {attr: r}
      description_text: yellow
      match_text: {attr: u}
      selected_match_text: {attr: ur}
    }
  }

This is what I'm seeing on my Mac.
image

It's working great on Windows. I wonder if there is some CRLF issue?

@simonborje

Copy link
Copy Markdown
Contributor Author

Does it work as expected when no suggestions have descriptions?

@fdncred

fdncred commented Sep 22, 2025 •

Copy link
Copy Markdown
Contributor

I'm not sure how to test that. Here's what it looks like in Windows.
image

I guess it could theoretically be something funky with cd and completions on MacOS since i shouldn't be able to cd into commands. Maybe that's what's breaking it?

That's got to be it. I wonder why commands are getting into the cd list on MacOS and not Windows. 🤔

@simonborje

Copy link
Copy Markdown
Contributor Author

I think that the menu will only use one column if any of the options has a description.
I have seen commands among cd suggestions at some point on Linux but I can't reproduce it right now.

@fdncred

fdncred commented Sep 22, 2025

Copy link
Copy Markdown
Contributor

it's $env.config.completion.algorithm = fuzzy that causes this. changing it to prefix fixes the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:completions Issues related to tab completion notes:additions Noted in "Additions" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants