Skip to content
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

Divide by zero when opening history_menu in narrow terminal #842

Open
blindFS opened this issue Oct 8, 2024 · 1 comment
Open

Divide by zero when opening history_menu in narrow terminal #842

blindFS opened this issue Oct 8, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@blindFS
Copy link
Contributor

blindFS commented Oct 8, 2024

Platform: macOS
Terminal software: all kinds of terminals

Got these when pressing ctrl-r to open history menu in a narrow terminal:

▓  󰏫 Error:   × Main thread panicked. dev $!?   ├─▶ at /Users/brew/Library/Caches/Homebrew/
  │   cargo_cache/registry/src/index.crates.io-
  │   6f17d22bba15001f/reedline-0.35.0/src/
  │   painting/utils.rs:62:32
  ╰─▶ attempt to divide by zero
         0: 0x10f12a2b4 - _rust_begin_unwind
         1: 0x10f31a292 -
      core::panicking::panic_fmt::h2bf80d97c31b18
      c0
         2: 0x10f31a796 -
      core::panicking::panic_const::panic_const_d
      iv_by_zero::h6a4a844a42d12df2
         3: 0x10efffd56 -
      reedline::painting::utils::estimate_single_
      line_wraps::he2ce6a3ebf974298
         4: 0x10efde2ca -
      reedline::menu::list_menu::ListMenu::number
      _of_lines::h373afd30d8f7f4d2
         5: 0x10efde523 -
      reedline::menu::list_menu::ListMenu::printa
      ble_entries::hbb1243eafae1abf2
         6: 0x10efdf2ce -
      <reedline::menu::list_menu::ListMenu as
      reedline::menu::Menu>::update_working_detai
      ls::h7975cc53aa7ed67e
         7: 0x10efcfd63 -
      reedline::menu::ReedlineMenu::update_workin
      g_details::ha605d300e0726fd6
         8: 0x10f00c3e6 -
      reedline::engine::Reedline::repaint::hb3e14
      3826652f743
         9: 0x10f008be3 -
      reedline::engine::Reedline::read_line::hfb1
      16570925c290e
        10: 0x10e3ebe49 -
      nu_cli::repl::loop_iteration::h9698a4eb13f8
      568a
        11: 0x10e3e6e3e -
      std::panic::catch_unwind::hb6bb7f322d087986
        12: 0x10e4123d3 -
      nu_cli::repl::evaluate_repl::h4fcb0d54f7ae1
      239
        13: 0x10e3a9a3a -
      nu::run::run_repl::h24ced594c3095e12
        14: 0x10e39bb57 -
      nu::main::hf219ffa11f65f566
  help: set the `RUST_BACKTRACE=1` environment
        variable to display a backtrace.

Steps to reproduce

  1. set a long marker to history menu, I used to have ansi colors in the marker so width() will return a large number.
{
    name: history_menu
    only_buffer_difference: false
    # marker: (prompt_decorator $private_vars.prompt_symbol_color "light_blue" "")
    marker: "------------------------------------------------------------------------------------------"
    type: {
        layout: list
        page_size: 30
    }
    style: {
        text: $private_vars.menu_text_color
        selected_text: light_blue_reverse
        description_text: yellow
    }
}
  1. Shrink the terminal to be narrower than the marker
  2. Open the history menu

I don't get why we need to substract anything from the column number in

+ self.number_of_lines(
&suggestion.value,
terminal_columns.saturating_sub(
self.indicator().width() as u16 + count_digits(entry_index),
),

and

+ self.number_of_lines(
&suggestion.value,
// to account for the index and the indicator e.g. 0: XXXX
painter.screen_width().saturating_sub(
self.indicator().width() as u16 + count_digits(lines),
),

When I remove those, this bug disappeared and nothing seems to be broken

@blindFS blindFS added the bug Something isn't working label Oct 8, 2024
@blindFS
Copy link
Contributor Author

blindFS commented Oct 8, 2024

#428

BTW, I can't reproduce the bug in the recording with these changes reverted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant