-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from mark-pitblado/develop
Add priority parsing and adjust column widths
- Loading branch information
Showing
8 changed files
with
107 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
mod api; | ||
mod app; | ||
mod models; | ||
mod parser; | ||
mod ui; | ||
|
||
use crate::api::fetch_tasks; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use regex::Regex; | ||
|
||
pub struct ParsedTask { | ||
pub title: String, | ||
pub priority: Option<u8>, | ||
} | ||
|
||
pub fn parse_task_input(input: &str) -> ParsedTask { | ||
// Regex for priority pattern, e.g. !1 to !5 | ||
let priority_re = Regex::new(r"!(\d)").unwrap(); | ||
|
||
let mut priority = None; | ||
let mut title = input.to_string(); | ||
|
||
// Capture priority if it exists | ||
if let Some(caps) = priority_re.captures(input) { | ||
if let Some(priority_match) = caps.get(1) { | ||
if let Ok(p) = priority_match.as_str().parse::<u8>() { | ||
if (1..=5).contains(&p) { | ||
priority = Some(p); | ||
} | ||
} | ||
} | ||
// Remove the priority pattern from the title | ||
title = priority_re.replace(input, "").trim().to_string(); | ||
} | ||
|
||
ParsedTask { title, priority } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters