Compare commits
2 Commits
v0.2.0
...
cdc04ab266
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cdc04ab266 | ||
|
|
46aff0e6b1 |
@@ -1,3 +1,4 @@
|
||||
//! Abstraction around event sourcing for the checklist application.
|
||||
use anyhow::Result;
|
||||
use crossterm::event::{self, Event};
|
||||
use std::time::Duration;
|
||||
|
||||
18
src/main.rs
18
src/main.rs
@@ -1,10 +1,10 @@
|
||||
/// A simple terminal checklist application.
|
||||
//! A simple terminal checklist application.
|
||||
mod event_source;
|
||||
mod terminal_guard;
|
||||
/// UI components (todo list)
|
||||
mod todo_list;
|
||||
|
||||
use anyhow::{Context as _, Result, anyhow, bail};
|
||||
use argh::FromArgs;
|
||||
use core::time::Duration;
|
||||
use crossterm::event::{self, EnableMouseCapture, Event, KeyCode};
|
||||
use crossterm::execute;
|
||||
@@ -16,11 +16,14 @@ use ratatui::backend::CrosstermBackend;
|
||||
use std::io::{self, Read as _};
|
||||
use terminal_guard::TerminalModeGuard;
|
||||
use todo_list::TodoList;
|
||||
use argh::FromArgs;
|
||||
|
||||
#[derive(FromArgs)]
|
||||
/// chkr - terminal checklist
|
||||
struct Args {
|
||||
/// load checklist from file instead of stdin
|
||||
#[argh(option, short = 'f', long = "file")]
|
||||
file: Option<String>,
|
||||
|
||||
/// print version and exit
|
||||
#[argh(switch, short = 'V', long = "version")]
|
||||
version: bool,
|
||||
@@ -34,13 +37,20 @@ fn main() -> Result<()> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let input: String = if let Some(path) = args.file {
|
||||
std::fs::read_to_string(&path).with_context(|| format!("reading file {path}"))?
|
||||
} else {
|
||||
let mut input = String::new();
|
||||
io::stdin()
|
||||
.read_to_string(&mut input)
|
||||
.context("reading stdin")?;
|
||||
input
|
||||
};
|
||||
|
||||
if input.trim().is_empty() {
|
||||
eprintln!("Provide text via stdin (pipe or heredoc). Example: \n cat file.txt | chkr");
|
||||
eprintln!(
|
||||
"Provide text via stdin (pipe or heredoc), or use --file. Example: \n cat file.txt | chkr"
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//! Todo list UI component for the checklist application.
|
||||
use ratatui::style::Style;
|
||||
use ratatui::widgets::{Block, Borders, List, ListItem, ListState};
|
||||
// use Frame via the crate root type `ratatui::Frame` in the signature below
|
||||
|
||||
Reference in New Issue
Block a user