reedline icon indicating copy to clipboard operation
reedline copied to clipboard

Divide by zero when opening history_menu in narrow terminal

Open blindFS opened this issue 4 months ago • 1 comments

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

https://github.com/nushell/reedline/blob/871075e62b5703cfc584e4e02b14c2473f5b0b63/src/menu/list_menu.rs#L524-L528

and

https://github.com/nushell/reedline/blob/871075e62b5703cfc584e4e02b14c2473f5b0b63/src/menu/list_menu.rs#L180-L185

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

blindFS avatar Oct 08 '24 12:10 blindFS