mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-26 03:07:18 +02:00
Run cargo fmt
This commit is contained in:
parent
37a1dafc7e
commit
6e194fe76e
4 changed files with 34 additions and 39 deletions
25
src/app.rs
25
src/app.rs
|
@ -12,7 +12,7 @@ use task_hookrs::task::Task;
|
||||||
use task_hookrs::uda::UDAValue;
|
use task_hookrs::uda::UDAValue;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use chrono::{Local, NaiveDateTime, TimeZone, Datelike};
|
use chrono::{Datelike, Local, NaiveDateTime, TimeZone};
|
||||||
|
|
||||||
use crate::calendar::Calendar;
|
use crate::calendar::Calendar;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
@ -167,7 +167,8 @@ impl TaskReportTable {
|
||||||
.arg("report.next.columns")
|
.arg("report.next.columns")
|
||||||
.output()
|
.output()
|
||||||
.expect("Unable to run `task show report.next.columns`. Check documentation for more information");
|
.expect("Unable to run `task show report.next.columns`. Check documentation for more information");
|
||||||
let data = String::from_utf8(output.stdout).expect("Unable to decode utf8 from stdout of `task show report.next.columns`");
|
let data = String::from_utf8(output.stdout)
|
||||||
|
.expect("Unable to decode utf8 from stdout of `task show report.next.columns`");
|
||||||
|
|
||||||
for line in data.split('\n') {
|
for line in data.split('\n') {
|
||||||
if line.starts_with("report.next.columns") {
|
if line.starts_with("report.next.columns") {
|
||||||
|
@ -183,7 +184,8 @@ impl TaskReportTable {
|
||||||
.arg("report.next.labels")
|
.arg("report.next.labels")
|
||||||
.output()
|
.output()
|
||||||
.expect("Unable to run `task show report.next.labels`. Check documentation for more information");
|
.expect("Unable to run `task show report.next.labels`. Check documentation for more information");
|
||||||
let data = String::from_utf8(output.stdout).expect("Unable to decode utf8 from stdout of `task show report.next.labels`");
|
let data = String::from_utf8(output.stdout)
|
||||||
|
.expect("Unable to decode utf8 from stdout of `task show report.next.labels`");
|
||||||
|
|
||||||
for line in data.split('\n') {
|
for line in data.split('\n') {
|
||||||
if line.starts_with("report.next.labels") {
|
if line.starts_with("report.next.labels") {
|
||||||
|
@ -404,7 +406,13 @@ impl TTApp {
|
||||||
.expect(format!("Unable to run `task _get rc.context.{}`", self.context_name).as_str())
|
.expect(format!("Unable to run `task _get rc.context.{}`", self.context_name).as_str())
|
||||||
.stdout,
|
.stdout,
|
||||||
)
|
)
|
||||||
.expect(format!("Unable to decode utf8 from stdout of `task _get rc.context.{}`", self.context_name).as_str());
|
.expect(
|
||||||
|
format!(
|
||||||
|
"Unable to decode utf8 from stdout of `task _get rc.context.{}`",
|
||||||
|
self.context_name
|
||||||
|
)
|
||||||
|
.as_str(),
|
||||||
|
);
|
||||||
self.context_filter = self.context_filter.strip_suffix('\n').unwrap_or("").to_string();
|
self.context_filter = self.context_filter.strip_suffix('\n').unwrap_or("").to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -737,20 +745,23 @@ impl TTApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn style_for_task(&self, task: &Task) -> Style {
|
fn style_for_task(&self, task: &Task) -> Style {
|
||||||
|
|
||||||
let tag_names_in_precedence = &self.config.rule_precedence_color;
|
let tag_names_in_precedence = &self.config.rule_precedence_color;
|
||||||
|
|
||||||
let mut style = Style::default();
|
let mut style = Style::default();
|
||||||
|
|
||||||
for tag_name in tag_names_in_precedence {
|
for tag_name in tag_names_in_precedence {
|
||||||
if task.tags().unwrap_or(&vec![]).contains(&tag_name.to_string().replace(".", "").to_uppercase()) {
|
if task
|
||||||
|
.tags()
|
||||||
|
.unwrap_or(&vec![])
|
||||||
|
.contains(&tag_name.to_string().replace(".", "").to_uppercase())
|
||||||
|
{
|
||||||
let color_tag_name = format!("color.{}", tag_name);
|
let color_tag_name = format!("color.{}", tag_name);
|
||||||
let c = self.config.color.get(&color_tag_name).cloned().unwrap_or_default();
|
let c = self.config.color.get(&color_tag_name).cloned().unwrap_or_default();
|
||||||
style = style.fg(c.fg).bg(c.bg);
|
style = style.fg(c.fg).bg(c.bg);
|
||||||
for modifier in c.modifiers {
|
for modifier in c.modifiers {
|
||||||
style = style.add_modifier(modifier);
|
style = style.add_modifier(modifier);
|
||||||
}
|
}
|
||||||
break
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -238,7 +238,7 @@ impl TConfig {
|
||||||
|
|
||||||
for line in data.split('\n') {
|
for line in data.split('\n') {
|
||||||
if line.starts_with(config) {
|
if line.starts_with(config) {
|
||||||
return line.trim_start_matches(config).trim_start().trim_end().to_string()
|
return line.trim_start_matches(config).trim_start().trim_end().to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"• ".to_string()
|
"• ".to_string()
|
||||||
|
@ -246,8 +246,7 @@ impl TConfig {
|
||||||
|
|
||||||
fn get_rule_precedence_color() -> Vec<String> {
|
fn get_rule_precedence_color() -> Vec<String> {
|
||||||
let data = Self::get_config("rule.precedence.color");
|
let data = Self::get_config("rule.precedence.color");
|
||||||
data
|
data.split(',')
|
||||||
.split(',')
|
|
||||||
.map(|s| s.trim_end_matches('.'))
|
.map(|s| s.trim_end_matches('.'))
|
||||||
.map(|s| s.to_string())
|
.map(|s| s.to_string())
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
mod app;
|
mod app;
|
||||||
mod calendar;
|
mod calendar;
|
||||||
mod config;
|
mod config;
|
||||||
mod util;
|
|
||||||
mod table;
|
mod table;
|
||||||
|
mod util;
|
||||||
|
|
||||||
use crate::util::{destruct_terminal, setup_terminal, Event, EventConfig, Events};
|
use crate::util::{destruct_terminal, setup_terminal, Event, EventConfig, Events};
|
||||||
use clap::{App, Arg};
|
use clap::{App, Arg};
|
||||||
|
|
41
src/table.rs
41
src/table.rs
|
@ -1,9 +1,3 @@
|
||||||
use tui::{
|
|
||||||
buffer::Buffer,
|
|
||||||
layout::{Constraint, Rect},
|
|
||||||
style::Style,
|
|
||||||
widgets::{Block, StatefulWidget, Widget},
|
|
||||||
};
|
|
||||||
use cassowary::{
|
use cassowary::{
|
||||||
strength::{MEDIUM, REQUIRED, WEAK},
|
strength::{MEDIUM, REQUIRED, WEAK},
|
||||||
WeightedRelation::*,
|
WeightedRelation::*,
|
||||||
|
@ -14,6 +8,12 @@ use std::{
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
iter::{self, Iterator},
|
iter::{self, Iterator},
|
||||||
};
|
};
|
||||||
|
use tui::{
|
||||||
|
buffer::Buffer,
|
||||||
|
layout::{Constraint, Rect},
|
||||||
|
style::Style,
|
||||||
|
widgets::{Block, StatefulWidget, Widget},
|
||||||
|
};
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -245,9 +245,7 @@ where
|
||||||
ccs.push(variables[i] | GE(WEAK) | 0.);
|
ccs.push(variables[i] | GE(WEAK) | 0.);
|
||||||
ccs.push(match *constraint {
|
ccs.push(match *constraint {
|
||||||
Constraint::Length(v) => variables[i] | EQ(MEDIUM) | f64::from(v),
|
Constraint::Length(v) => variables[i] | EQ(MEDIUM) | f64::from(v),
|
||||||
Constraint::Percentage(v) => {
|
Constraint::Percentage(v) => variables[i] | EQ(WEAK) | (f64::from(v * area.width) / 100.0),
|
||||||
variables[i] | EQ(WEAK) | (f64::from(v * area.width) / 100.0)
|
|
||||||
}
|
|
||||||
Constraint::Ratio(n, d) => {
|
Constraint::Ratio(n, d) => {
|
||||||
variables[i] | EQ(WEAK) | (f64::from(area.width) * f64::from(n) / f64::from(d))
|
variables[i] | EQ(WEAK) | (f64::from(area.width) * f64::from(n) / f64::from(d))
|
||||||
}
|
}
|
||||||
|
@ -257,24 +255,16 @@ where
|
||||||
}
|
}
|
||||||
solver
|
solver
|
||||||
.add_constraint(
|
.add_constraint(
|
||||||
variables
|
variables.iter().fold(Expression::from_constant(0.), |acc, v| acc + *v)
|
||||||
.iter()
|
|
||||||
.fold(Expression::from_constant(0.), |acc, v| acc + *v)
|
|
||||||
| LE(REQUIRED)
|
| LE(REQUIRED)
|
||||||
| f64::from(
|
| f64::from(area.width - 2 - (self.column_spacing * (variables.len() as u16 - 1))),
|
||||||
area.width - 2 - (self.column_spacing * (variables.len() as u16 - 1)),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
solver.add_constraints(&ccs).unwrap();
|
solver.add_constraints(&ccs).unwrap();
|
||||||
let mut solved_widths = vec![0; variables.len()];
|
let mut solved_widths = vec![0; variables.len()];
|
||||||
for &(var, value) in solver.fetch_changes() {
|
for &(var, value) in solver.fetch_changes() {
|
||||||
let index = var_indices[&var];
|
let index = var_indices[&var];
|
||||||
let value = if value.is_sign_negative() {
|
let value = if value.is_sign_negative() { 0 } else { value as u16 };
|
||||||
0
|
|
||||||
} else {
|
|
||||||
value as u16
|
|
||||||
};
|
|
||||||
solved_widths[index] = value
|
solved_widths[index] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,9 +286,7 @@ where
|
||||||
None => (None, self.style),
|
None => (None, self.style),
|
||||||
};
|
};
|
||||||
let highlight_symbol = self.highlight_symbol.unwrap_or("");
|
let highlight_symbol = self.highlight_symbol.unwrap_or("");
|
||||||
let blank_symbol = iter::repeat(" ")
|
let blank_symbol = iter::repeat(" ").take(highlight_symbol.width()).collect::<String>();
|
||||||
.take(highlight_symbol.width())
|
|
||||||
.collect::<String>();
|
|
||||||
|
|
||||||
// Draw rows
|
// Draw rows
|
||||||
let default_style = Style::default();
|
let default_style = Style::default();
|
||||||
|
@ -319,9 +307,7 @@ where
|
||||||
};
|
};
|
||||||
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, _)
|
Row::Data(d) | Row::StyledData(d, _) if Some(i) == state.selected.map(|s| s - state.offset) => {
|
||||||
if Some(i) == state.selected.map(|s| s - state.offset) =>
|
|
||||||
{
|
|
||||||
(d, highlight_style, highlight_symbol)
|
(d, highlight_style, highlight_symbol)
|
||||||
}
|
}
|
||||||
Row::Data(d) => (d, default_style, blank_symbol.as_ref()),
|
Row::Data(d) => (d, default_style, blank_symbol.as_ref()),
|
||||||
|
@ -363,7 +349,6 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn table_invalid_percentages() {
|
fn table_invalid_percentages() {
|
||||||
Table::new([""].iter(), vec![Row::Data([""].iter())].into_iter())
|
Table::new([""].iter(), vec![Row::Data([""].iter())].into_iter()).widths(&[Constraint::Percentage(110)]);
|
||||||
.widths(&[Constraint::Percentage(110)]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue