use std::sync::{Arc, Mutex};
use psdk_father::{
args::{ArgContext, PsdkArgBase, PsdkEasyArg},
command::{CommandClause, PsdkTextCommand},
errors::PsdkFatherResult,
};
#[derive(Clone, Debug)]
pub struct CPageHeightOptions {
pub height: i32,
pub copies: i32,
}
#[derive(Clone, Debug)]
pub struct CPageHeight {
options: CPageHeightOptions,
ctx: Arc<Mutex<ArgContext>>,
}
impl CPageHeight {
pub fn new(options: CPageHeightOptions) -> Self {
Self {
options,
ctx: Default::default(),
}
}
}
impl From<i32> for CPageHeight {
fn from(height: i32) -> Self {
Self::new(CPageHeightOptions { height, copies: 1 })
}
}
impl PsdkEasyArg<String> for CPageHeight {
fn context(&self) -> Arc<Mutex<ArgContext>> {
self.ctx.clone()
}
}
impl PsdkArgBase<String> for CPageHeight {
fn header(&self) -> String {
"! 0 200 200".to_string()
}
fn clause(&self) -> PsdkFatherResult<CommandClause> {
let mut ptc = PsdkTextCommand::with_header_format_cpcl(self.header());
ptc.append(self.options.height).append(self.options.copies);
Ok(ptc.clause())
}
}
psdk_father::impl_psdk_arg_to_easy_arg!(String, CPageHeight, true);