use super::{input_translate, output_translate};
use crate::{
cin_implements::common::{generate_command, generate_command_vm},
runtimes::CommandVmRuntime,
};
use anyhow::Result;
use nar_dev_utils::pipe;
use navm::{
cmd::Cmd,
vm::{VmLauncher, VmRuntime},
};
use std::path::PathBuf;
const COMMAND_ARGS_ONA: [&str; 1] = ["shell"];
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct ONA {
exe_path: PathBuf,
initial_volume: Option<usize>,
}
impl ONA {
pub fn new(exe_path: impl Into<PathBuf>) -> Self {
Self {
exe_path: exe_path.into(),
..Default::default()
}
}
}
impl VmLauncher for ONA {
type Runtime = CommandVmRuntime;
fn launch(self) -> Result<CommandVmRuntime> {
let mut runtime = pipe! {
self.exe_path
=> generate_command(_, None::<String>, COMMAND_ARGS_ONA.into_iter().by_ref())
=> generate_command_vm(_, (input_translate, output_translate))
=> .launch()
}?;
if let Some(volume) = self.initial_volume {
if let Err(e) = runtime.input_cmd(Cmd::VOL(volume)) {
println!("无法设置初始音量「{volume}」:{e}");
}
};
Ok(runtime)
}
}