From f2de431701d45424cc120a5c212b2fac069485f2 Mon Sep 17 00:00:00 2001 From: SeongChan Lee Date: Wed, 27 Apr 2022 11:42:53 +0900 Subject: [PATCH] fix: Change column number to 1-based index --- src/bin/typos-cli/report.rs | 5 +++-- tests/cmd/stdin-failure-multiwidth.stdout | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/bin/typos-cli/report.rs b/src/bin/typos-cli/report.rs index 87e7e75..352672a 100644 --- a/src/bin/typos-cli/report.rs +++ b/src/bin/typos-cli/report.rs @@ -181,7 +181,8 @@ fn print_long_correction(msg: &Typo, palette: Palette) -> Result<(), std::io::Er let line = String::from_utf8_lossy(msg.buffer.as_ref()); let line = line.replace('\t', " "); let start = String::from_utf8_lossy(&msg.buffer[0..msg.byte_offset]); - let column = unicode_segmentation::UnicodeSegmentation::graphemes(start.as_ref(), true).count(); + let column_number = + unicode_segmentation::UnicodeSegmentation::graphemes(start.as_ref(), true).count() + 1; match &msg.corrections { typos::Status::Valid => {} typos::Status::Invalid => { @@ -213,7 +214,7 @@ fn print_long_correction(msg: &Typo, palette: Palette) -> Result<(), std::io::Er " --> {}{}{}", palette.info.paint(context_display(&msg.context)), palette.info.paint(divider), - palette.info.paint(column) + palette.info.paint(column_number) )?; if let Some(Context::File(context)) = &msg.context { diff --git a/tests/cmd/stdin-failure-multiwidth.stdout b/tests/cmd/stdin-failure-multiwidth.stdout index e6cf44a..62f71cc 100644 --- a/tests/cmd/stdin-failure-multiwidth.stdout +++ b/tests/cmd/stdin-failure-multiwidth.stdout @@ -1,29 +1,29 @@ error: `Apropriate` should be `Appropriate` - --> -:5:2 + --> -:5:3 | 5 | 한 Apropriate world | ^^^^^^^^^^ | error: `Apropriate` should be `Appropriate` - --> -:12:2 + --> -:12:3 | 12 | 한 Apropriate world | ^^^^^^^^^^ | error: `Apropriate` should be `Appropriate` - --> -:19:2 + --> -:19:3 | 19 | 👁️‍🗨️ Apropriate world | ^^^^^^^^^^ | error: `Apropriate` should be `Appropriate` - --> -:26:2 + --> -:26:3 | 26 | 😵‍💫 Apropriate world | ^^^^^^^^^^ | error: `Apropriate` should be `Appropriate` - --> -:33:1 + --> -:33:2 | 33 | Apropriate world | ^^^^^^^^^^