mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-26 21:27:19 +02:00
Make ID right align along with header
This commit is contained in:
parent
7f2ea5ab78
commit
bbfba5a5e7
2 changed files with 26 additions and 17 deletions
13
src/app.rs
13
src/app.rs
|
@ -577,6 +577,12 @@ impl TTApp {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (i, header) in headers.iter().enumerate() {
|
||||||
|
if header == "ID" {
|
||||||
|
// always give ID a couple of extra for indicator
|
||||||
|
widths[i] += self.config.uda_selection_indicator.as_str().graphemes(true).count();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// now start trimming
|
// now start trimming
|
||||||
while (widths.iter().sum::<usize>() as u16) >= maximum_column_width - (headers.len()) as u16 {
|
while (widths.iter().sum::<usize>() as u16) >= maximum_column_width - (headers.len()) as u16 {
|
||||||
|
@ -587,13 +593,6 @@ impl TTApp {
|
||||||
widths[index] -= 1;
|
widths[index] -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i, header) in headers.iter().enumerate() {
|
|
||||||
if header == "ID" {
|
|
||||||
// always give ID a couple of extra for indicator
|
|
||||||
widths[i] += 2;
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return widths
|
return widths
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
26
src/table.rs
26
src/table.rs
|
@ -15,6 +15,8 @@ use tui::{
|
||||||
widgets::{Block, StatefulWidget, Widget},
|
widgets::{Block, StatefulWidget, Widget},
|
||||||
};
|
};
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
use unicode_segmentation::Graphemes;
|
||||||
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct TableState {
|
pub struct TableState {
|
||||||
|
@ -274,7 +276,11 @@ where
|
||||||
// Draw header
|
// Draw header
|
||||||
if y < table_area.bottom() {
|
if y < table_area.bottom() {
|
||||||
for (w, t) in solved_widths.iter().zip(self.header.by_ref()) {
|
for (w, t) in solved_widths.iter().zip(self.header.by_ref()) {
|
||||||
|
if t.to_string() == "ID" {
|
||||||
|
buf.set_stringn(x, y, format!("{symbol:>width$}", symbol=t, width=*w as usize), *w as usize, self.header_style);
|
||||||
|
} else {
|
||||||
buf.set_stringn(x, y, format!("{}", t), *w as usize, self.header_style);
|
buf.set_stringn(x, y, format!("{}", t), *w as usize, self.header_style);
|
||||||
|
}
|
||||||
x += *w + self.column_spacing;
|
x += *w + self.column_spacing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -288,6 +294,8 @@ where
|
||||||
let highlight_symbol = self.highlight_symbol.unwrap_or("");
|
let highlight_symbol = self.highlight_symbol.unwrap_or("");
|
||||||
let blank_symbol = iter::repeat(" ").take(highlight_symbol.width()).collect::<String>();
|
let blank_symbol = iter::repeat(" ").take(highlight_symbol.width()).collect::<String>();
|
||||||
|
|
||||||
|
let header_index = self.header.by_ref().into_iter().position(|r| r.to_string() == "ID").unwrap_or_else(|| 0);
|
||||||
|
|
||||||
// Draw rows
|
// Draw rows
|
||||||
let default_style = Style::default();
|
let default_style = Style::default();
|
||||||
if y < table_area.bottom() {
|
if y < table_area.bottom() {
|
||||||
|
@ -305,7 +313,6 @@ where
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
let header_index = self.header.by_ref().into_iter().position(|r| r.to_string() == "ID").unwrap_or_else(|| 0);
|
|
||||||
for (i, row) in self.rows.skip(state.offset).take(remaining).enumerate() {
|
for (i, row) in self.rows.skip(state.offset).take(remaining).enumerate() {
|
||||||
let (data, style, symbol) = match row {
|
let (data, style, symbol) = match row {
|
||||||
Row::Data(d) | Row::StyledData(d, _) if Some(i) == state.selected.map(|s| s - state.offset) => {
|
Row::Data(d) | Row::StyledData(d, _) if Some(i) == state.selected.map(|s| s - state.offset) => {
|
||||||
|
@ -324,7 +331,11 @@ where
|
||||||
*w as usize,
|
*w as usize,
|
||||||
style,
|
style,
|
||||||
);
|
);
|
||||||
format!("{}{}", symbol, elt)
|
if c == header_index {
|
||||||
|
format!("{symbol}{elt:>width$}", symbol = symbol, elt = elt, width = *w as usize - symbol.to_string().graphemes(true).count())
|
||||||
|
} else {
|
||||||
|
format!("{symbol}{elt:<width$}", symbol = symbol, elt = elt, width = *w as usize - symbol.to_string().graphemes(true).count())
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
buf.set_stringn(
|
buf.set_stringn(
|
||||||
x - 1,
|
x - 1,
|
||||||
|
@ -333,14 +344,13 @@ where
|
||||||
*w as usize + 1,
|
*w as usize + 1,
|
||||||
style,
|
style,
|
||||||
);
|
);
|
||||||
format!("{}", elt)
|
if c == header_index {
|
||||||
};
|
format!("{elt:>width$}", elt = elt, width = *w as usize)
|
||||||
let cell = if c == header_index {
|
|
||||||
format!("{symbol:>width$}", symbol = s, width = *w as usize)
|
|
||||||
} else {
|
} else {
|
||||||
format!("{symbol:<width$}", symbol = s, width = *w as usize)
|
format!("{elt:<width$}", elt = elt, width = *w as usize)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
buf.set_stringn(x, y + i as u16, cell, *w as usize, style);
|
buf.set_stringn(x, y + i as u16, s, *w as usize, style);
|
||||||
x += *w + self.column_spacing;
|
x += *w + self.column_spacing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue