diff options
| author | mo8it <mo8it@proton.me> | 2024-04-14 16:03:49 +0200 |
|---|---|---|
| committer | mo8it <mo8it@proton.me> | 2024-04-14 16:03:49 +0200 |
| commit | 8aef915ee732af1480cd7b93818f7d71c3ba178c (patch) | |
| tree | 636743c5e14896a8caa96f4408fe38ddc600c4fb /src/main.rs | |
| parent | 3da860927d131eacc288764672ed8799a6a8cfca (diff) | |
Show the welcome message
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index a96e323..aeb9432 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,15 @@ use anyhow::{Context, Result}; +use app_state::StateFileStatus; use clap::{Parser, Subcommand}; -use std::{path::Path, process::exit}; +use crossterm::{ + terminal::{Clear, ClearType}, + ExecutableCommand, +}; +use std::{ + io::{self, BufRead, Write}, + path::Path, + process::exit, +}; mod app_state; mod embedded; @@ -67,7 +76,26 @@ fn main() -> Result<()> { exit(1); } - let mut app_state = AppState::new(info_file); + let (mut app_state, state_file_status) = AppState::new( + info_file.exercises, + info_file.final_message.unwrap_or_default(), + ); + + if let Some(welcome_message) = info_file.welcome_message { + match state_file_status { + StateFileStatus::NotRead => { + let mut stdout = io::stdout().lock(); + stdout.execute(Clear(ClearType::All))?; + + let welcome_message = welcome_message.trim(); + write!(stdout, "{welcome_message}\n\nPress ENTER to continue ")?; + stdout.flush()?; + + io::stdin().lock().read_until(b'\n', &mut Vec::new())?; + } + StateFileStatus::Read => (), + } + } match args.command { None => { |
