mirror of
https://github.com/FliegendeWurst/tmux-thumbs.git
synced 2024-11-09 16:00:35 +00:00
Added support for wide characters such as cjk and emoji
This commit is contained in:
parent
9b677a67c6
commit
d57e594737
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -147,6 +147,7 @@ dependencies = [
|
|||||||
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"termion 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"termion 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -13,6 +13,7 @@ termion = "1.5"
|
|||||||
regex = "1.3.1"
|
regex = "1.3.1"
|
||||||
clap = "2.33.0"
|
clap = "2.33.0"
|
||||||
base64 = "0.11.0"
|
base64 = "0.11.0"
|
||||||
|
unicode-width = "0.1.7"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "thumbs"
|
name = "thumbs"
|
||||||
|
@ -8,6 +8,8 @@ use termion::raw::IntoRawMode;
|
|||||||
use termion::screen::AlternateScreen;
|
use termion::screen::AlternateScreen;
|
||||||
use termion::{color, cursor};
|
use termion::{color, cursor};
|
||||||
|
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
pub struct View<'a> {
|
pub struct View<'a> {
|
||||||
state: &'a mut state::State<'a>,
|
state: &'a mut state::State<'a>,
|
||||||
skip: usize,
|
skip: usize,
|
||||||
@ -110,7 +112,7 @@ impl<'a> View<'a> {
|
|||||||
// Find long utf sequences and extract it from mat.x
|
// Find long utf sequences and extract it from mat.x
|
||||||
let line = &self.state.lines[mat.y as usize];
|
let line = &self.state.lines[mat.y as usize];
|
||||||
let prefix = &line[0..mat.x as usize];
|
let prefix = &line[0..mat.x as usize];
|
||||||
let extra = prefix.len() - prefix.chars().count();
|
let extra = prefix.width_cjk() - prefix.chars().count();
|
||||||
let offset = (mat.x as u16) - (extra as u16);
|
let offset = (mat.x as u16) - (extra as u16);
|
||||||
let text = self.make_hint_text(mat.text);
|
let text = self.make_hint_text(mat.text);
|
||||||
|
|
||||||
@ -126,9 +128,9 @@ impl<'a> View<'a> {
|
|||||||
|
|
||||||
if let Some(ref hint) = mat.hint {
|
if let Some(ref hint) = mat.hint {
|
||||||
let extra_position = match self.position {
|
let extra_position = match self.position {
|
||||||
"right" => text.len() - hint.len(),
|
"right" => text.width_cjk() - hint.len(),
|
||||||
"off_left" => 0 - hint.len(),
|
"off_left" => 0 - hint.len(),
|
||||||
"off_right" => text.len(),
|
"off_right" => text.width_cjk(),
|
||||||
_ => 0,
|
_ => 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user