Turn hardcoded strings into constants to resolve #4

This commit is contained in:
2024-07-10 20:04:11 -04:00
parent 0d50da7ceb
commit 4fbd53efa5
5 changed files with 146 additions and 132 deletions

View File

@@ -3,6 +3,7 @@ use std::collections::HashMap;
use std::io::stdout;
use std::rc::Rc;
use std::time::{Duration, Instant};
mod constants;
mod window;
use ratatui::{
@@ -144,7 +145,7 @@ impl App {
self.user_duration = Duration::ZERO;
}
window::minimize_other("AntiDrift");
window::minimize_other(&constants::APP_TITLE);
}
State::InProgress => {
let elapsed = self.session_start.elapsed();
@@ -157,7 +158,7 @@ impl App {
}
State::ShouldQuit => {}
State::End => {
window::minimize_other("AntiDrift");
window::minimize_other(&constants::APP_TITLE);
}
}
@@ -375,7 +376,7 @@ fn ui(frame: &mut Frame, app: &App) {
Paragraph::new(input_intention).block(
Block::bordered()
.border_type(border_type_intention)
.title("Intention"),
.title(constants::INTENTION_TITLE),
),
layout_intention,
);
@@ -395,7 +396,7 @@ fn ui(frame: &mut Frame, app: &App) {
Paragraph::new(input_duration).block(
Block::bordered()
.border_type(border_type_duration)
.title("Duration"),
.title(constants::DURATION_TITLE),
),
layout_duration,
);
@@ -403,26 +404,30 @@ fn ui(frame: &mut Frame, app: &App) {
if app.state == State::InputIntention || app.state == State::InputDuration {
let results = app.get_session_results();
frame.render_widget(
Paragraph::new(results).block(Block::bordered().title("Previous Sessions")),
Paragraph::new(results)
.block(Block::bordered().title(constants::PREVIOUS_SESSIONS_TITLE)),
layout_titles,
);
} else {
let stats = app.get_session_stats();
frame.render_widget(
Paragraph::new(stats).block(Block::bordered().title("Session Stats")),
Paragraph::new(stats).block(Block::bordered().title(constants::SESSION_STATS_TITLE)),
layout_titles,
);
}
let mut spans: Vec<Span> = Vec::new();
if app.user_intention.len() == 0 {
let span = Span::styled("Provide intention! ", Style::new().fg(Color::LightRed));
let span = Span::styled(
constants::PROVIDE_INTENTION,
Style::new().fg(Color::LightRed),
);
spans.push(span);
}
if app.user_duration == Duration::ZERO {
let span = Span::styled(
"Provide valid duration in minutes! ",
constants::PROVIDE_VALID_DURATION,
Style::new().fg(Color::LightRed),
);
spans.push(span);
@@ -432,29 +437,29 @@ fn ui(frame: &mut Frame, app: &App) {
State::InputIntention | State::InputDuration => {
if spans.len() == 0 {
let span = Span::styled(
"Ready to start next session.",
constants::READY_TO_START,
Style::new().fg(Color::LightGreen),
);
spans.push(span);
}
}
State::InProgress => {
let span = Span::styled("Session In-Progress", Style::new().fg(Color::LightGreen));
let span = Span::styled(
constants::SESSION_IN_PROGRESS,
Style::new().fg(Color::LightGreen),
);
spans.push(span);
}
State::ShouldQuit => {}
State::End => {
let span = Span::styled(
"Press 1, 2, 3 to rate titles!",
Style::new().fg(Color::LightBlue),
);
let span = Span::styled(constants::RATE_TITLES, Style::new().fg(Color::LightBlue));
spans.push(span);
}
}
let input_status: Vec<Line> = vec![Line::from(spans)];
frame.render_widget(
Paragraph::new(input_status).block(Block::bordered().title("Status")),
Paragraph::new(input_status).block(Block::bordered().title(constants::STATUS_TITLE)),
layout_status,
);
}