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

Fix parsing position cursor report escape sequences #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

azat
Copy link

@azat azat commented Sep 29, 2023

The format should be:

Cursor position report (CPR): Answer is ESC [ y ; x R, where x,y is the cursor location.

But if "R" will goes before ";", then it will panic:

> thread '<unnamed>' panicked at '`at` split index (is 53) should be <= len (is 31)', library/alloc/src/vec/mod.rs:2110:13
stack backtrace:
   0:         0x2978e6ea - std::backtrace_rs::backtrace::libunwind::trace::ha9053a9a07ca49cb
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:         0x2978e6ea - std::backtrace_rs::backtrace::trace_unsynchronized::h9c2852a457ad564e
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:         0x2978e6ea - std::sys_common::backtrace::_print_fmt::h457936fbfaa0070f
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:65:5
   3:         0x2978e6ea - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5779d7bf7f70cb0c
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:44:22
   4:         0x297f1dae - core::fmt::write::h5a4baaff1bcd3eb5
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/fmt/mod.rs:1232:17
   5:         0x29781695 - std::io::Write::write_fmt::h4bc1f301cb9e9cce
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/io/mod.rs:1684:15
   6:         0x2978e4b5 - std::sys_common::backtrace::_print::h5fcdc36060f177e8
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:47:5
   7:         0x2978e4b5 - std::sys_common::backtrace::print::h54ca9458b876c8bf
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:34:9
   8:         0x2979122f - std::panicking::default_hook::{{closure}}::hbe471161c7664ed6
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:271:22
   9:         0x29790f6b - std::panicking::default_hook::ha3500da57aa4ac4f
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:290:9
  10:         0x297918e8 - std::panicking::rust_panic_with_hook::h50c09d000dc561d2
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:692:13
  11:         0x297917e9 - std::panicking::begin_panic_handler::{{closure}}::h9e2b2176e00e0d9c
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:583:13
  12:         0x2978eb56 - std::sys_common::backtrace::__rust_end_short_backtrace::h5739b8e512c09d02
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:150:18
  13:         0x297914f2 - rust_begin_unwind
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:579:5
  14:         0x297ee103 - core::panicking::panic_fmt::hf33a1475b4dc5c3e
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:64:14
  15:         0x297e26e6 - alloc::vec::Vec<T,A>::split_off::assert_failed::h5d4cf9fcf561634c
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/vec/mod.rs:2110:13
  16:         0x301f7415 - alloc::vec::Vec<T,A>::split_off::ha953b379fad89c1d
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/vec/mod.rs:2114:13
  17:         0x302039ee - tuikit::input::KeyBoard::parse_cursor_report::h8a29b19f3df8e0ff

The format should be:

    Cursor position report (CPR): Answer is ESC [ y ; x R, where x,y is the cursor location.

But if "R" will goes before ";", then it will panic:

    > thread '<unnamed>' panicked at '`at` split index (is 53) should be <= len (is 31)', library/alloc/src/vec/mod.rs:2110:13
    stack backtrace:
       0:         0x2978e6ea - std::backtrace_rs::backtrace::libunwind::trace::ha9053a9a07ca49cb
                                   at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
       1:         0x2978e6ea - std::backtrace_rs::backtrace::trace_unsynchronized::h9c2852a457ad564e
                                   at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
       2:         0x2978e6ea - std::sys_common::backtrace::_print_fmt::h457936fbfaa0070f
                                   at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:65:5
       3:         0x2978e6ea - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5779d7bf7f70cb0c
                                   at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:44:22
       4:         0x297f1dae - core::fmt::write::h5a4baaff1bcd3eb5
                                   at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/fmt/mod.rs:1232:17
       5:         0x29781695 - std::io::Write::write_fmt::h4bc1f301cb9e9cce
                                   at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/io/mod.rs:1684:15
       6:         0x2978e4b5 - std::sys_common::backtrace::_print::h5fcdc36060f177e8
                                   at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:47:5
       7:         0x2978e4b5 - std::sys_common::backtrace::print::h54ca9458b876c8bf
                                   at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:34:9
       8:         0x2979122f - std::panicking::default_hook::{{closure}}::hbe471161c7664ed6
                                   at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:271:22
       9:         0x29790f6b - std::panicking::default_hook::ha3500da57aa4ac4f
                                   at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:290:9
      10:         0x297918e8 - std::panicking::rust_panic_with_hook::h50c09d000dc561d2
                                   at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:692:13
      11:         0x297917e9 - std::panicking::begin_panic_handler::{{closure}}::h9e2b2176e00e0d9c
                                   at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:583:13
      12:         0x2978eb56 - std::sys_common::backtrace::__rust_end_short_backtrace::h5739b8e512c09d02
                                   at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:150:18
      13:         0x297914f2 - rust_begin_unwind
                                   at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:579:5
      14:         0x297ee103 - core::panicking::panic_fmt::hf33a1475b4dc5c3e
                                   at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:64:14
      15:         0x297e26e6 - alloc::vec::Vec<T,A>::split_off::assert_failed::h5d4cf9fcf561634c
                                   at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/vec/mod.rs:2110:13
      16:         0x301f7415 - alloc::vec::Vec<T,A>::split_off::ha953b379fad89c1d
                                   at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/vec/mod.rs:2114:13
      17:         0x302039ee - tuikit::input::KeyBoard::parse_cursor_report::h8a29b19f3df8e0ff
azat added a commit to azat/ClickHouse that referenced this pull request Nov 24, 2023
Refs: skim-rs/tuikit#51
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
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.

1 participant