use psdk_father::args::{ArgContext, PsdkArgBase, PsdkEasyArg};
use psdk_father::command::{CommandClause, PsdkTextCommand};
use psdk_father::errors::PsdkFatherResult;
use std::sync::{Arc, Mutex};
use crate::args::{CForm, CGap};
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Location {
NoLocation,
Skip,
}
#[derive(Clone, Debug)]
pub struct CPageModeOptions {
pub location: Location,
}
#[derive(Clone, Debug)]
pub struct CPageMode {
options: CPageModeOptions,
ctx: Arc<Mutex<ArgContext>>,
}
impl CPageMode {
pub fn new(options: CPageModeOptions) -> Self {
Self {
options,
ctx: Default::default(),
}
}
}
impl Default for CPageMode {
fn default() -> Self {
Self::new(CPageModeOptions {
location: Location::NoLocation,
})
}
}
impl From<Location> for CPageMode {
fn from(location: Location) -> Self {
Self::new(CPageModeOptions { location })
}
}
impl PsdkEasyArg<String> for CPageMode {
fn context(&self) -> Arc<Mutex<ArgContext>> {
self.ctx.clone()
}
}
impl PsdkArgBase<String> for CPageMode {
fn header(&self) -> String {
"".to_string()
}
fn clause(&self) -> PsdkFatherResult<CommandClause> {
if self.options.location == Location::Skip {
self.prepend(&CGap::new())?.prepend(&CForm::new())?;
}
let ptc = PsdkTextCommand::with_header_format_cpcl(self.header());
Ok(ptc.clause())
}
}
psdk_father::impl_psdk_arg_to_easy_arg!(String, CPageMode, true);