Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Decrease tech debt #574

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 26 additions & 27 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
action::Action,
calendar::Calendar,
completion::{get_start_word_under_cursor, CompletionList},
config,
config::Config,
config::{self, Config},
event::{Event, KeyCode},
help::Help,
history::HistoryContext,
Expand Down Expand Up @@ -928,17 +927,16 @@
let maximum_column_width = area.width;
let widths = self.calculate_widths(&contexts, &headers, maximum_column_width);

let selected = self.contexts.table_state.current_selection().unwrap_or_default();
let header = headers.iter();
let selected = self.contexts.table_state.selected().unwrap_or_default();
let mut rows = vec![];
let mut highlight_style = Style::default();
for (i, context) in contexts.iter().enumerate() {
let mut style = Style::default();
if &self.contexts.rows[i].active == "yes" {
style = self.config.uda_style_context_active;
}
rows.push(Row::StyledData(context.iter(), style));
if i == self.contexts.table_state.current_selection().unwrap_or_default() {
rows.push(ratatui::widgets::Row::new(context.clone()).style(style));
if i == self.contexts.table_state.selected().unwrap_or_default() {
highlight_style = style;
}
}
Expand All @@ -949,25 +947,26 @@
.collect();

let highlight_style = highlight_style.add_modifier(Modifier::BOLD);
let t = Table::new(header, rows.into_iter())
let t = ratatui::widgets::Table::new(rows.into_iter(), constraints.clone())

Check failure on line 950 in src/app.rs

View workflow job for this annotation

GitHub Actions / Clippy

explicit call to `.into_iter()` in function argument accepting `IntoIterator`
.block(
Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.title(Line::from(vec![Span::styled("Context", Style::default().add_modifier(Modifier::BOLD))])),
)
.header_style(
self
.config
.color
.get("color.label")
.copied()
.unwrap_or_default()
.add_modifier(Modifier::UNDERLINED),
.header(
ratatui::widgets::Row::new(headers).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)
.widths(&constraints);
.highlight_symbol(self.config.uda_selection_indicator.clone());

f.render_stateful_widget(t, area, &mut self.contexts.table_state);
}
Expand Down Expand Up @@ -1442,7 +1441,7 @@
}

pub fn context_next(&mut self) {
let i = match self.contexts.table_state.current_selection() {
let i = match self.contexts.table_state.selected() {
Some(i) => {
if i >= self.contexts.len() - 1 {
0
Expand All @@ -1456,7 +1455,7 @@
}

pub fn context_previous(&mut self) {
let i = match self.contexts.table_state.current_selection() {
let i = match self.contexts.table_state.selected() {
Some(i) => {
if i == 0 {
self.contexts.len() - 1
Expand All @@ -1470,7 +1469,7 @@
}

pub fn context_select(&mut self) -> Result<()> {
let i = self.contexts.table_state.current_selection().unwrap_or_default();
let i = self.contexts.table_state.selected().unwrap_or_default();
let mut command = std::process::Command::new("task");
command.arg("context").arg(&self.contexts.rows[i].name);
command.output()?;
Expand Down Expand Up @@ -3844,11 +3843,11 @@
view.push('"');
for (x, c) in cells.iter().enumerate() {
if skip == 0 {
view.push_str(&c.symbol);
view.push_str(c.symbol());
} else {
overwritten.push((x, &c.symbol))
overwritten.push((x, c.symbol()))
}
skip = std::cmp::max(skip, c.symbol.width()).saturating_sub(1);
skip = std::cmp::max(skip, c.symbol().width()).saturating_sub(1);
}
view.push('"');
if !overwritten.is_empty() {
Expand Down Expand Up @@ -4095,22 +4094,22 @@
assert_eq!(app.tasks.len(), 26);
assert_eq!(app.current_context_filter, "");

assert_eq!(app.contexts.table_state.current_selection(), Some(0));
assert_eq!(app.contexts.table_state.selected(), Some(0));
app.context_next();
app.context_next();
app.context_select().unwrap();
assert_eq!(app.contexts.table_state.current_selection(), Some(2));
assert_eq!(app.contexts.table_state.selected(), Some(2));

assert!(app.update(true).await.is_ok());

assert_eq!(app.tasks.len(), 1);
assert_eq!(app.current_context_filter, "+finance -private");

assert_eq!(app.contexts.table_state.current_selection(), Some(2));
assert_eq!(app.contexts.table_state.selected(), Some(2));
app.context_previous();
app.context_previous();
app.context_select().unwrap();
assert_eq!(app.contexts.table_state.current_selection(), Some(0));
assert_eq!(app.contexts.table_state.selected(), Some(0));

assert!(app.update(true).await.is_ok());

Expand Down
5 changes: 2 additions & 3 deletions src/pane/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use crate::{
app::{Mode, TaskwarriorTui},
event::KeyCode,
pane::Pane,
table::TableState,
};

#[derive(Debug, Clone, Default)]
Expand All @@ -55,7 +54,7 @@ impl ContextDetails {
}

pub struct ContextsState {
pub table_state: TableState,
pub table_state: ratatui::widgets::TableState,
pub report_height: u16,
pub columns: Vec<String>,
pub rows: Vec<ContextDetails>,
Expand All @@ -64,7 +63,7 @@ pub struct ContextsState {
impl ContextsState {
pub(crate) fn new() -> Self {
Self {
table_state: TableState::default(),
table_state: ratatui::widgets::TableState::default(),
report_height: 0,
columns: vec![NAME.to_string(), TYPE.to_string(), DEFINITION.to_string(), ACTIVE.to_string()],
rows: vec![],
Expand Down
2 changes: 1 addition & 1 deletion src/task_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn format_date_time(dt: NaiveDateTime) -> String {

pub fn format_date(dt: NaiveDateTime) -> String {
let offset = Local.offset_from_utc_datetime(&dt);
let dt = DateTime::<Local>::from_utc(dt, offset);
let dt = DateTime::<Local>::from_naive_utc_and_offset(dt, offset);
dt.format("%Y-%m-%d").to_string()
}

Expand Down
Loading