console-rs / dialoguer

Rust utility library for nice command line prompts and similar things
MIT License
1.34k stars 144 forks source link

Select: panicked at 'attempt to subtract with overflow' #76

Open kasvith opened 4 years ago

kasvith commented 4 years ago

When I used Select as follows

dialoguer::Select::new()
        .items(crate::generes::TYPES)
        .paged(false)
        .with_prompt("genere")
        .interact()?;

the terminal in Windows gives me the following error.

I tried GitBash, Powershell, Cmd and result are the same. When you scroll down with arrow keys program crashes

thread 'main' panicked at 'attempt to subtract with overflow', C:\Users\Kasun\.cargo\registry\src\github.com-1ecc6299db9ec823\console-0.11.3\src\windows_term.rs:152:32
stack backtrace:
   0: backtrace::backtrace::trace_unsynchronized
             at C:\Users\VssAdministrator\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.46\src\backtrace\mod.rs:66
   1: std::sys_common::backtrace::_print_fmt
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\sys_common\backtrace.rs:78
   2: std::sys_common::backtrace::_print::{{impl}}::fmt
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\sys_common\backtrace.rs:59
   3: core::fmt::write
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libcore\fmt\mod.rs:1069
   4: std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\io\mod.rs:1504
   5: std::sys_common::backtrace::_print
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\sys_common\backtrace.rs:62
   6: std::sys_common::backtrace::print
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\sys_common\backtrace.rs:49
   7: std::panicking::default_hook::{{closure}}
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\panicking.rs:198
   8: std::panicking::default_hook
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\panicking.rs:218
   9: std::panicking::rust_panic_with_hook
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\panicking.rs:511
  10: std::panicking::begin_panic_handler
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\panicking.rs:419
  11: core::panicking::panic_fmt
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libcore\panicking.rs:111
  12: core::panicking::panic
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libcore\panicking.rs:54
  13: console::windows_term::move_cursor_up
             at C:\Users\Kasun\.cargo\registry\src\github.com-1ecc6299db9ec823\console-0.11.3\src\windows_term.rs:152
  14: console::term::Term::move_cursor_up
             at C:\Users\Kasun\.cargo\registry\src\github.com-1ecc6299db9ec823\console-0.11.3\src\term.rs:362
  15: console::term::Term::clear_last_lines
             at C:\Users\Kasun\.cargo\registry\src\github.com-1ecc6299db9ec823\console-0.11.3\src\term.rs:396
  16: dialoguer::theme::TermThemeRenderer::clear
             at C:\Users\Kasun\.cargo\registry\src\github.com-1ecc6299db9ec823\dialoguer-0.6.2\src\theme.rs:755
  17: dialoguer::prompts::select::Select::_interact_on
             at C:\Users\Kasun\.cargo\registry\src\github.com-1ecc6299db9ec823\dialoguer-0.6.2\src\prompts\select.rs:209
  18: dialoguer::prompts::select::Select::interact_on
             at C:\Users\Kasun\.cargo\registry\src\github.com-1ecc6299db9ec823\dialoguer-0.6.2\src\prompts\select.rs:103
  19: dialoguer::prompts::select::Select::interact
             at C:\Users\Kasun\.cargo\registry\src\github.com-1ecc6299db9ec823\dialoguer-0.6.2\src\prompts\select.rs:89
  20: mp3t::commands::edit::edit
             at .\src\commands\edit.rs:27
  21: mp3t::run_app
             at .\src\bin\mp3t.rs:66
  22: mp3t::main
             at .\src\bin\mp3t.rs:79
  23: std::rt::lang_start::{{closure}}<()>
             at C:\Users\Kasun\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libstd\rt.rs:67
  24: std::rt::lang_start_internal::{{closure}}
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\rt.rs:52
  25: std::panicking::try::do_call
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\panicking.rs:331
  26: std::panicking::try
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\panicking.rs:274
  27: std::panic::catch_unwind
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\panic.rs:394
  28: std::rt::lang_start_internal
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\rt.rs:51
  29: std::rt::lang_start<()>
             at C:\Users\Kasun\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libstd\rt.rs:67
  30: main
  31: invoke_main
             at d:\agent\_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  32: __scrt_common_main_seh
             at d:\agent\_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  33: BaseThreadInitThunk
  34: RtlUserThreadStart
x0f5c3 commented 3 years ago

I have the same problem, but mine shows up when I use q or esc with interact_opt, only when I restrict the amount of items to <40 then it works on windows, but on linux it works perfectly with a lot more items.

thread 'main' panicked at 'attempt to subtract with overflow', C:\Users\xC5\.cargo\registry\src\github.com-1ecc6299db9ec823\cons
ole-0.13.0\src\windows_term.rs:153:32
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src\panicking.rs:483
   1: core::panicking::panic_fmt
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\core\src\panicking.rs:85
   2: core::panicking::panic
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\core\src\panicking.rs:50
   3: console::windows_term::move_cursor_up
             at C:\Users\xC5\.cargo\registry\src\github.com-1ecc6299db9ec823\console-0.13.0\src\windows_term.rs:153
   4: console::term::Term::move_cursor_up
             at C:\Users\xC5\.cargo\registry\src\github.com-1ecc6299db9ec823\console-0.13.0\src\term.rs:357
   5: console::term::Term::clear_last_lines
             at C:\Users\xC5\.cargo\registry\src\github.com-1ecc6299db9ec823\console-0.13.0\src\term.rs:391
   6: dialoguer::prompts::select::Select::_interact_on
             at C:\Users\xC5\.cargo\registry\src\github.com-1ecc6299db9ec823\dialoguer-0.7.1\src\prompts\select.rs:308
   7: dialoguer::prompts::select::Select::interact_on_opt
             at C:\Users\xC5\.cargo\registry\src\github.com-1ecc6299db9ec823\dialoguer-0.7.1\src\prompts\select.rs:242
   8: go_version_manager::ask_for_version
             at .\src\main.rs:65
   9: go_version_manager::main::{{closure}}::{{closure}}
             at .\src\main.rs:1
  10: core::future::from_generator::{{impl}}::poll<generator-0>
             at C:\Users\xC5\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\future\mod.r
s:80
  11: tokio::runtime::enter::{{impl}}::block_on::{{closure}}<core::future::from_generator::GenFuture<generator-0>>
             at C:\Users\xC5\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.22\src\runtime\enter.rs:160
  12: tokio::coop::with_budget::{{closure}}<core::task::poll::Poll<core::result::Result<tuple<>, go_version_manager::error::Erro
r>>,closure-0>
             at C:\Users\xC5\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.22\src\coop.rs:127
  13: std::thread::local::LocalKey<core::cell::Cell<tokio::coop::Budget>>::try_with<core::cell::Cell<tokio::coop::Budget>,closur
e-0,core::task::poll::Poll<core::result::Result<tuple<>, go_version_manager::error::Error>>>
             at C:\Users\xC5\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local.
rs:272
  14: std::thread::local::LocalKey<core::cell::Cell<tokio::coop::Budget>>::with<core::cell::Cell<tokio::coop::Budget>,closure-0,
re-0,core::task::poll::Poll<core::result::Result<tuple<>, go_version_manager::error::Error>>>
             at C:\Users\xC5\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local
.rs:272
  14: std::thread::local::LocalKey<core::cell::Cell<tokio::coop::Budget>>::with<core::cell::Cell<tokio::coop::Budget>,closure-0
,core::task::poll::Poll<core::result::Result<tuple<>, go_version_manager::error::Error>>>
             at C:\Users\xC5\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local
.rs:248
  15: tokio::coop::with_budget
             at C:\Users\xC5\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.22\src\coop.rs:120
  16: tokio::coop::budget
             at C:\Users\xC5\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.22\src\coop.rs:96
  17: tokio::runtime::enter::Enter::block_on<core::future::from_generator::GenFuture<generator-0>>
             at C:\Users\xC5\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.22\src\runtime\enter.rs:160
  18: tokio::runtime::thread_pool::ThreadPool::block_on<core::future::from_generator::GenFuture<generator-0>>
             at C:\Users\xC5\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.22\src\runtime\thread_pool\mod.rs:82
  19: tokio::runtime::{{impl}}::block_on::{{closure}}<core::future::from_generator::GenFuture<generator-0>>
             at C:\Users\xC5\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.22\src\runtime\mod.rs:446
  20: tokio::runtime::context::enter<closure-0,core::result::Result<tuple<>, go_version_manager::error::Error>>
             at C:\Users\xC5\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.22\src\runtime\context.rs:72
  21: tokio::runtime::handle::Handle::enter<closure-0,core::result::Result<tuple<>, go_version_manager::error::Error>>
             at C:\Users\xC5\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.22\src\runtime\handle.rs:76
  22: tokio::runtime::Runtime::block_on<core::future::from_generator::GenFuture<generator-0>>
             at C:\Users\xC5\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.22\src\runtime\mod.rs:441
  23: go_version_manager::main::{{closure}}
             at .\src\main.rs:27
  24: std::panicking::try::do_call<closure-0,core::result::Result<tuple<>, go_version_manager::error::Error>>
             at C:\Users\xC5\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\panicking.rs
:381
  25: std::panicking::try::do_catch<std::panic::AssertUnwindSafe<closure-0>,core::task::poll::Poll<core::result::Result<core::r
esult::Result<tuple<>, std::io::error::Error>, tokio::runtime::task::error::JoinError>>>
  26: std::panicking::try<core::result::Result<tuple<>, go_version_manager::error::Error>,closure-0>
             at C:\Users\xC5\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\panicking.rs
:345
  27: std::panic::catch_unwind<closure-0,core::result::Result<tuple<>, go_version_manager::error::Error>>
             at C:\Users\xC5\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\panic.rs:382

  28: quit::__run<closure-0,core::result::Result<tuple<>, go_version_manager::error::Error>>
             at C:\Users\xC5\.cargo\registry\src\github.com-1ecc6299db9ec823\quit-1.1.2\src\lib.rs:74
  29: go_version_manager::main
             at .\src\main.rs:1
  30: core::ops::function::FnOnce::call_once<fn() -> core::result::Result<tuple<>, go_version_manager::error::Error>,tuple<>>
             at C:\Users\xC5\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\functio
n.rs:227
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.