mirror of
https://github.com/bobwen-dev/hunter
synced 2025-04-12 00:55:41 +02:00
more robust handling of cjk characters
This commit is contained in:
parent
1826fced28
commit
09b50562ec
@ -167,14 +167,19 @@ impl Widget for FileBrowser {
|
||||
self.refresh();
|
||||
}
|
||||
fn render_header(&self) -> String {
|
||||
let xsize = self.get_coordinates().xsize();
|
||||
let file = self.selected_file();
|
||||
let name = &file.name;
|
||||
|
||||
let color = if file.is_dir() || file.color.is_none() {
|
||||
crate::term::highlight_color() } else {
|
||||
crate::term::from_lscolor(file.color.as_ref().unwrap()) };
|
||||
|
||||
let path = file.path.parent().unwrap().to_string_lossy().to_string();
|
||||
format!("{}/{}{}", path, &color, name )
|
||||
|
||||
let pretty_path = format!("{}/{}{}", path, &color, name );
|
||||
let sized_path = crate::term::sized_string(&pretty_path, xsize);
|
||||
sized_path
|
||||
}
|
||||
fn refresh(&mut self) {
|
||||
self.columns.refresh();
|
||||
|
@ -89,21 +89,27 @@ where
|
||||
|
||||
let xsize = self.get_size().xsize();
|
||||
let sized_string = term::sized_string(&name, xsize);
|
||||
let size_pos = xsize - (size.to_string().len() as u16
|
||||
+ unit.to_string().len() as u16);
|
||||
let padding = sized_string.len() - sized_string.width_cjk();
|
||||
let padding = xsize - padding as u16;
|
||||
|
||||
format!(
|
||||
"{}{}{}{}{}",
|
||||
"{}{}{}{}{}{}{}",
|
||||
termion::cursor::Save,
|
||||
match &file.color {
|
||||
Some(color) => format!("{}{:padding$}",
|
||||
term::from_lscolor(color),
|
||||
&sized_string,
|
||||
padding = xsize as usize),
|
||||
padding = padding as usize),
|
||||
_ => format!("{}{:padding$}",
|
||||
term::normal_color(),
|
||||
&sized_string,
|
||||
padding = xsize as usize),
|
||||
padding = padding as usize),
|
||||
} ,
|
||||
termion::cursor::Restore,
|
||||
termion::cursor::Right(size_pos),
|
||||
term::highlight_color(),
|
||||
term::cursor_left((size.to_string().width() + unit.width()) as u16),
|
||||
size,
|
||||
unit
|
||||
)
|
||||
@ -287,6 +293,8 @@ impl Widget for ListView<Files> {
|
||||
self.move_up();
|
||||
self.refresh();
|
||||
}
|
||||
Key::Char('P') => for _ in 0..10 { self.move_up() }
|
||||
Key::Char('N') => for _ in 0..10 { self.move_down() }
|
||||
Key::Down | Key::Char('n') => {
|
||||
self.move_down();
|
||||
self.refresh();
|
||||
|
@ -18,8 +18,10 @@ impl TextView {
|
||||
pub fn new_from_file(file: &File) -> TextView {
|
||||
let file = std::fs::File::open(&file.path).unwrap();
|
||||
let file = std::io::BufReader::new(file);
|
||||
let lines = file.lines().map(|line| line.unwrap()).collect();
|
||||
|
||||
let lines = file.lines().map(|line|
|
||||
line.unwrap()
|
||||
.replace("\t", " ")).collect();
|
||||
|
||||
TextView {
|
||||
lines: lines,
|
||||
buffer: String::new(),
|
||||
@ -63,12 +65,10 @@ impl Widget for TextView {
|
||||
.enumerate()
|
||||
.map(|(i, line)| {
|
||||
format!(
|
||||
"{}{}{:xsize$}",
|
||||
"{}{}{}",
|
||||
crate::term::goto_xy(xpos, i as u16 + ypos),
|
||||
crate::term::reset(),
|
||||
sized_string(&line, xsize),
|
||||
xsize = xsize as usize
|
||||
)
|
||||
sized_string(&line, xsize))
|
||||
})
|
||||
.collect::<String>();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user