mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-25 17:57:19 +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 uuid::Uuid;
|
||||
|
||||
use chrono::{Local, NaiveDateTime, TimeZone, Datelike};
|
||||
use chrono::{Datelike, Local, NaiveDateTime, TimeZone};
|
||||
|
||||
use crate::calendar::Calendar;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
@ -167,7 +167,8 @@ impl TaskReportTable {
|
|||
.arg("report.next.columns")
|
||||
.output()
|
||||
.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') {
|
||||
if line.starts_with("report.next.columns") {
|
||||
|
@ -183,7 +184,8 @@ impl TaskReportTable {
|
|||
.arg("report.next.labels")
|
||||
.output()
|
||||
.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') {
|
||||
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())
|
||||
.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();
|
||||
}
|
||||
|
||||
|
@ -737,20 +745,23 @@ impl TTApp {
|
|||
}
|
||||
|
||||
fn style_for_task(&self, task: &Task) -> Style {
|
||||
|
||||
let tag_names_in_precedence = &self.config.rule_precedence_color;
|
||||
|
||||
let mut style = Style::default();
|
||||
|
||||
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 c = self.config.color.get(&color_tag_name).cloned().unwrap_or_default();
|
||||
style = style.fg(c.fg).bg(c.bg);
|
||||
for modifier in c.modifiers {
|
||||
style = style.add_modifier(modifier);
|
||||
}
|
||||
break
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -238,7 +238,7 @@ impl TConfig {
|
|||
|
||||
for line in data.split('\n') {
|
||||
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()
|
||||
|
@ -246,8 +246,7 @@ impl TConfig {
|
|||
|
||||
fn get_rule_precedence_color() -> Vec<String> {
|
||||
let data = Self::get_config("rule.precedence.color");
|
||||
data
|
||||
.split(',')
|
||||
data.split(',')
|
||||
.map(|s| s.trim_end_matches('.'))
|
||||
.map(|s| s.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
mod app;
|
||||
mod calendar;
|
||||
mod config;
|
||||
mod util;
|
||||
mod table;
|
||||
mod util;
|
||||
|
||||
use crate::util::{destruct_terminal, setup_terminal, Event, EventConfig, Events};
|
||||
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::{
|
||||
strength::{MEDIUM, REQUIRED, WEAK},
|
||||
WeightedRelation::*,
|
||||
|
@ -14,6 +8,12 @@ use std::{
|
|||
fmt::Display,
|
||||
iter::{self, Iterator},
|
||||
};
|
||||
use tui::{
|
||||
buffer::Buffer,
|
||||
layout::{Constraint, Rect},
|
||||
style::Style,
|
||||
widgets::{Block, StatefulWidget, Widget},
|
||||
};
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -245,9 +245,7 @@ where
|
|||
ccs.push(variables[i] | GE(WEAK) | 0.);
|
||||
ccs.push(match *constraint {
|
||||
Constraint::Length(v) => variables[i] | EQ(MEDIUM) | f64::from(v),
|
||||
Constraint::Percentage(v) => {
|
||||
variables[i] | EQ(WEAK) | (f64::from(v * area.width) / 100.0)
|
||||
}
|
||||
Constraint::Percentage(v) => variables[i] | EQ(WEAK) | (f64::from(v * area.width) / 100.0),
|
||||
Constraint::Ratio(n, d) => {
|
||||
variables[i] | EQ(WEAK) | (f64::from(area.width) * f64::from(n) / f64::from(d))
|
||||
}
|
||||
|
@ -257,24 +255,16 @@ where
|
|||
}
|
||||
solver
|
||||
.add_constraint(
|
||||
variables
|
||||
.iter()
|
||||
.fold(Expression::from_constant(0.), |acc, v| acc + *v)
|
||||
variables.iter().fold(Expression::from_constant(0.), |acc, v| acc + *v)
|
||||
| LE(REQUIRED)
|
||||
| f64::from(
|
||||
area.width - 2 - (self.column_spacing * (variables.len() as u16 - 1)),
|
||||
),
|
||||
| f64::from(area.width - 2 - (self.column_spacing * (variables.len() as u16 - 1))),
|
||||
)
|
||||
.unwrap();
|
||||
solver.add_constraints(&ccs).unwrap();
|
||||
let mut solved_widths = vec![0; variables.len()];
|
||||
for &(var, value) in solver.fetch_changes() {
|
||||
let index = var_indices[&var];
|
||||
let value = if value.is_sign_negative() {
|
||||
0
|
||||
} else {
|
||||
value as u16
|
||||
};
|
||||
let value = if value.is_sign_negative() { 0 } else { value as u16 };
|
||||
solved_widths[index] = value
|
||||
}
|
||||
|
||||
|
@ -296,9 +286,7 @@ where
|
|||
None => (None, self.style),
|
||||
};
|
||||
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>();
|
||||
|
||||
// Draw rows
|
||||
let default_style = Style::default();
|
||||
|
@ -319,9 +307,7 @@ where
|
|||
};
|
||||
for (i, row) in self.rows.skip(state.offset).take(remaining).enumerate() {
|
||||
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) => {
|
||||
(d, highlight_style, highlight_symbol)
|
||||
}
|
||||
Row::Data(d) => (d, default_style, blank_symbol.as_ref()),
|
||||
|
@ -363,7 +349,6 @@ mod tests {
|
|||
#[test]
|
||||
#[should_panic]
|
||||
fn table_invalid_percentages() {
|
||||
Table::new([""].iter(), vec![Row::Data([""].iter())].into_iter())
|
||||
.widths(&[Constraint::Percentage(110)]);
|
||||
Table::new([""].iter(), vec![Row::Data([""].iter())].into_iter()).widths(&[Constraint::Percentage(110)]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue