mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-27 15:47:19 +02:00
fix: Revert project tab feature
This commit is contained in:
parent
af21791838
commit
4bd3549037
3 changed files with 15 additions and 112 deletions
76
src/app.rs
76
src/app.rs
|
@ -362,79 +362,17 @@ impl TaskwarriorTui {
|
|||
|
||||
self.projects.report_height = split_task_layout[0].height;
|
||||
self.draw_projects_report_window(f, split_task_layout[0], title);
|
||||
let selected = self.projects.current_selection;
|
||||
|
||||
// TODO: what do to with selected project?
|
||||
if self.projects.list.is_empty() {
|
||||
} else {
|
||||
match self.projects.table_state.mode() {
|
||||
TableMode::SingleSelection => vec![self.projects.list[selected].clone()],
|
||||
TableMode::MultipleSelection => {
|
||||
let mut chosed = vec![];
|
||||
for project in &self.projects.marked {
|
||||
chosed.push(project.clone());
|
||||
}
|
||||
chosed
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_projects_report_window(&mut self, f: &mut Frame<impl Backend>, rect: Rect, title: Vec<Span>) {
|
||||
let table = self.projects.simplified_view();
|
||||
let maximum_column_width = rect.width;
|
||||
let widths = self.calculate_widths(&table.0, &table.1, maximum_column_width);
|
||||
//TODO add spacing to content so it justed to right side
|
||||
let selected = self.projects.current_selection;
|
||||
let header = table.1.iter();
|
||||
let mut rows = vec![];
|
||||
let mut highlight_style = Style::default();
|
||||
for (i, project) in table.0.iter().enumerate() {
|
||||
let style = self.style_for_project(project);
|
||||
if i == selected {
|
||||
highlight_style = style;
|
||||
if self.config.uda_selection_bold {
|
||||
highlight_style = highlight_style.add_modifier(Modifier::BOLD);
|
||||
}
|
||||
if self.config.uda_selection_italic {
|
||||
highlight_style = highlight_style.add_modifier(Modifier::ITALIC);
|
||||
}
|
||||
if self.config.uda_selection_dim {
|
||||
highlight_style = highlight_style.add_modifier(Modifier::DIM);
|
||||
}
|
||||
if self.config.uda_selection_blink {
|
||||
highlight_style = highlight_style.add_modifier(Modifier::SLOW_BLINK);
|
||||
}
|
||||
}
|
||||
rows.push(Row::StyledData(project.iter(), style));
|
||||
}
|
||||
let constraints: Vec<Constraint> = widths
|
||||
.iter()
|
||||
.map(|i| Constraint::Length((*i).try_into().unwrap_or(maximum_column_width as u16)))
|
||||
.collect();
|
||||
|
||||
let t = Table::new(header, rows.into_iter())
|
||||
.block(
|
||||
let data = self.projects.data.clone();
|
||||
let p = Paragraph::new(Text::from(&data[..])).block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.title(Spans::from(title)),
|
||||
)
|
||||
.header_style(
|
||||
self.config
|
||||
.color
|
||||
.get("color.label")
|
||||
.copied()
|
||||
.unwrap_or_default()
|
||||
.add_modifier(Modifier::UNDERLINED),
|
||||
)
|
||||
.highlight_style(highlight_style)
|
||||
.highlight_symbol(&self.config.uda_selection_indicator)
|
||||
.mark_symbol(&self.config.uda_mark_indicator)
|
||||
.unmark_symbol(&self.config.uda_unmark_indicator)
|
||||
.widths(&constraints);
|
||||
|
||||
f.render_stateful_widget(t, rect, &mut self.projects.table_state);
|
||||
.title(title),
|
||||
);
|
||||
f.render_widget(p, rect);
|
||||
}
|
||||
|
||||
fn style_for_project(&self, project: &[String]) -> Style {
|
||||
|
@ -1307,8 +1245,8 @@ impl TaskwarriorTui {
|
|||
self.last_export = Some(std::time::SystemTime::now());
|
||||
self.task_report_table.export_headers(None, &self.report)?;
|
||||
self.export_tasks()?;
|
||||
self.projects.update_data()?;
|
||||
self.contexts.update_data()?;
|
||||
self.projects.update_data()?;
|
||||
self.update_tags();
|
||||
self.task_details.clear();
|
||||
self.dirty = false;
|
||||
|
@ -2212,8 +2150,6 @@ impl TaskwarriorTui {
|
|||
match output {
|
||||
Ok(output) => {
|
||||
if output.status.success() {
|
||||
String::from_utf8_lossy(&output.stdout);
|
||||
String::from_utf8_lossy(&output.stderr);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(format!(
|
||||
|
|
|
@ -39,6 +39,7 @@ pub struct ProjectsState {
|
|||
pub report_height: u16,
|
||||
pub columns: Vec<String>,
|
||||
pub rows: Vec<ProjectDetails>,
|
||||
pub data: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
|
@ -63,6 +64,7 @@ impl ProjectsState {
|
|||
AVG_AGE_HEADER.to_string(),
|
||||
COMPLETE_HEADER.to_string(),
|
||||
],
|
||||
data: Default::default(),
|
||||
rows: vec![],
|
||||
}
|
||||
}
|
||||
|
@ -128,42 +130,7 @@ impl ProjectsState {
|
|||
.context("Unable to run `task summary`")
|
||||
.unwrap();
|
||||
let data = String::from_utf8_lossy(&output.stdout);
|
||||
|
||||
let lines = data
|
||||
.split('\n')
|
||||
.into_iter()
|
||||
.filter(|s| !s.trim().is_empty())
|
||||
.collect::<Vec<&str>>();
|
||||
let header = lines.first().unwrap();
|
||||
let contains_avg_age = header.contains("Avg age");
|
||||
if contains_avg_age {
|
||||
let name_index = header.find("Remaining").unwrap();
|
||||
let remaining_index = header.find("Remaining").unwrap() + "Remaining".len();
|
||||
let average_age_index = header.find("Avg age").unwrap() + "Avg age".len();
|
||||
let complete_index = header.find("Complete").unwrap() + "Complete".len();
|
||||
|
||||
for line in lines.into_iter().skip(2) {
|
||||
if line.is_empty() || self.last_line(line) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let line = line.to_string();
|
||||
let name = line[0..name_index].trim().to_string();
|
||||
let remaining = line[name_index..remaining_index].trim().parse();
|
||||
let remaining = if let Ok(v) = remaining { v } else { 0 };
|
||||
let avg_age = line[remaining_index..average_age_index].trim().to_string();
|
||||
let complete = line[average_age_index..complete_index].trim().to_string();
|
||||
|
||||
self.rows.push(ProjectDetails {
|
||||
name,
|
||||
remaining,
|
||||
avg_age,
|
||||
complete,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
self.list = self.rows.iter().map(|x| x.name.clone()).collect_vec();
|
||||
self.data = data.into();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -203,7 +170,7 @@ impl Pane for ProjectsState {
|
|||
}
|
||||
|
||||
fn focus_on_next_project(app: &mut TaskwarriorTui) {
|
||||
if app.projects.current_selection < app.projects.list.len() - 1 {
|
||||
if app.projects.current_selection < app.projects.list.len().saturating_sub(1) {
|
||||
app.projects.current_selection += 1;
|
||||
app.projects.table_state.select(Some(app.projects.current_selection));
|
||||
}
|
||||
|
|
|
@ -296,7 +296,7 @@ impl TaskReportTable {
|
|||
let c = if let Some(a) = task.annotations() {
|
||||
format!("[{}]", a.len())
|
||||
} else {
|
||||
format!("")
|
||||
Default::default()
|
||||
};
|
||||
format!("{} {}", task.description(), c)
|
||||
}
|
||||
|
@ -304,7 +304,7 @@ impl TaskReportTable {
|
|||
let c = if let Some(a) = task.annotations() {
|
||||
format!("[{}]", a.len())
|
||||
} else {
|
||||
format!("")
|
||||
Default::default()
|
||||
};
|
||||
let d = task.description().to_string();
|
||||
let mut available_width = self.description_width;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue