phink_lib/cli/ui/
traits.rs

1use crate::{
2    cli::config::{
3        PFiles,
4        PhinkFiles,
5    },
6    ResultOf,
7};
8use anyhow::bail;
9use ratatui::{
10    layout::Rect,
11    Frame,
12};
13use std::path::PathBuf;
14
15pub trait Paint {
16    fn render(&self, f: &mut Frame, area: Rect);
17}
18
19pub trait FromPath {
20    type Output;
21    fn from_fullpath(fullpath: PathBuf) -> ResultOf<Self::Output> {
22        match fullpath.exists() {
23            true => Ok(Self::create_instance(fullpath)),
24            false => bail!("The {fullpath:?} fullpath isn't correct"),
25        }
26    }
27
28    fn from_output(output: PathBuf) -> ResultOf<Self::Output> {
29        let path = PhinkFiles::new(output).path(Self::get_filetype());
30
31        match path.exists() {
32            true => Self::from_fullpath(path),
33            false => bail!("Couldn't spot {path:?}"),
34        }
35    }
36
37    fn create_instance(path: PathBuf) -> Self::Output;
38
39    fn get_filetype() -> PFiles;
40}