chore: Decrease tech debt

This commit is contained in:
Dheepak Krishnamurthy 2024-05-12 11:48:01 -04:00
parent 10b3ef7bb9
commit 32a73184e8
3 changed files with 22 additions and 24 deletions

View file

@ -43,8 +43,7 @@ use crate::{
action::Action, action::Action,
calendar::Calendar, calendar::Calendar,
completion::{get_start_word_under_cursor, CompletionList}, completion::{get_start_word_under_cursor, CompletionList},
config, config::{self, Config},
config::Config,
event::{Event, KeyCode}, event::{Event, KeyCode},
help::Help, help::Help,
history::HistoryContext, history::HistoryContext,
@ -928,8 +927,7 @@ impl TaskwarriorTui {
let maximum_column_width = area.width; let maximum_column_width = area.width;
let widths = self.calculate_widths(&contexts, &headers, maximum_column_width); let widths = self.calculate_widths(&contexts, &headers, maximum_column_width);
let selected = self.contexts.table_state.current_selection().unwrap_or_default(); let selected = self.contexts.table_state.selected().unwrap_or_default();
let header = headers.iter();
let mut rows = vec![]; let mut rows = vec![];
let mut highlight_style = Style::default(); let mut highlight_style = Style::default();
for (i, context) in contexts.iter().enumerate() { for (i, context) in contexts.iter().enumerate() {
@ -937,8 +935,8 @@ impl TaskwarriorTui {
if &self.contexts.rows[i].active == "yes" { if &self.contexts.rows[i].active == "yes" {
style = self.config.uda_style_context_active; style = self.config.uda_style_context_active;
} }
rows.push(Row::StyledData(context.iter(), style)); rows.push(ratatui::widgets::Row::new(context.clone()).style(style));
if i == self.contexts.table_state.current_selection().unwrap_or_default() { if i == self.contexts.table_state.selected().unwrap_or_default() {
highlight_style = style; highlight_style = style;
} }
} }
@ -949,14 +947,15 @@ impl TaskwarriorTui {
.collect(); .collect();
let highlight_style = highlight_style.add_modifier(Modifier::BOLD); 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())
.block( .block(
Block::default() Block::default()
.borders(Borders::ALL) .borders(Borders::ALL)
.border_type(BorderType::Rounded) .border_type(BorderType::Rounded)
.title(Line::from(vec![Span::styled("Context", Style::default().add_modifier(Modifier::BOLD))])), .title(Line::from(vec![Span::styled("Context", Style::default().add_modifier(Modifier::BOLD))])),
) )
.header_style( .header(
ratatui::widgets::Row::new(headers).style(
self self
.config .config
.color .color
@ -964,10 +963,10 @@ impl TaskwarriorTui {
.copied() .copied()
.unwrap_or_default() .unwrap_or_default()
.add_modifier(Modifier::UNDERLINED), .add_modifier(Modifier::UNDERLINED),
),
) )
.highlight_style(highlight_style) .highlight_style(highlight_style)
.highlight_symbol(&self.config.uda_selection_indicator) .highlight_symbol(self.config.uda_selection_indicator.clone());
.widths(&constraints);
f.render_stateful_widget(t, area, &mut self.contexts.table_state); f.render_stateful_widget(t, area, &mut self.contexts.table_state);
} }
@ -1442,7 +1441,7 @@ impl TaskwarriorTui {
} }
pub fn context_next(&mut self) { 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) => { Some(i) => {
if i >= self.contexts.len() - 1 { if i >= self.contexts.len() - 1 {
0 0
@ -1456,7 +1455,7 @@ impl TaskwarriorTui {
} }
pub fn context_previous(&mut self) { 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) => { Some(i) => {
if i == 0 { if i == 0 {
self.contexts.len() - 1 self.contexts.len() - 1
@ -1470,7 +1469,7 @@ impl TaskwarriorTui {
} }
pub fn context_select(&mut self) -> Result<()> { 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"); let mut command = std::process::Command::new("task");
command.arg("context").arg(&self.contexts.rows[i].name); command.arg("context").arg(&self.contexts.rows[i].name);
command.output()?; command.output()?;

View file

@ -32,7 +32,6 @@ use crate::{
app::{Mode, TaskwarriorTui}, app::{Mode, TaskwarriorTui},
event::KeyCode, event::KeyCode,
pane::Pane, pane::Pane,
table::TableState,
}; };
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
@ -55,7 +54,7 @@ impl ContextDetails {
} }
pub struct ContextsState { pub struct ContextsState {
pub table_state: TableState, pub table_state: ratatui::widgets::TableState,
pub report_height: u16, pub report_height: u16,
pub columns: Vec<String>, pub columns: Vec<String>,
pub rows: Vec<ContextDetails>, pub rows: Vec<ContextDetails>,
@ -64,7 +63,7 @@ pub struct ContextsState {
impl ContextsState { impl ContextsState {
pub(crate) fn new() -> Self { pub(crate) fn new() -> Self {
Self { Self {
table_state: TableState::default(), table_state: ratatui::widgets::TableState::default(),
report_height: 0, report_height: 0,
columns: vec![NAME.to_string(), TYPE.to_string(), DEFINITION.to_string(), ACTIVE.to_string()], columns: vec![NAME.to_string(), TYPE.to_string(), DEFINITION.to_string(), ACTIVE.to_string()],
rows: vec![], rows: vec![],

View file

@ -14,7 +14,7 @@ pub fn format_date_time(dt: NaiveDateTime) -> String {
pub fn format_date(dt: NaiveDateTime) -> String { pub fn format_date(dt: NaiveDateTime) -> String {
let offset = Local.offset_from_utc_datetime(&dt); 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() dt.format("%Y-%m-%d").to_string()
} }