mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-09 06:47:59 -06:00
Remove old code
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
// use bincode::{Decode, Encode};
|
||||
|
||||
/// Mostly temporary server message type
|
||||
// #[derive(Clone, Debug, Encode, Decode)]
|
||||
pub enum Announcement {
|
||||
TestAnnouncement(String),
|
||||
// GetRuntimes,
|
||||
// GetRuntimesAck(usize),
|
||||
|
||||
// StartRuntime(RuntimeConfig),
|
||||
// StartRuntimeAck(bool),
|
||||
}
|
||||
|
||||
// const BINCODE_CONFIG: bincode::config::Configuration = bincode::config::standard();
|
||||
|
||||
// impl Announcement {
|
||||
// pub fn encode(&self) -> Vec<u8> {
|
||||
// bincode::encode_to_vec(self, BINCODE_CONFIG).unwrap()
|
||||
// }
|
||||
|
||||
// pub fn decode(bytes: &[u8]) -> Option<Self> {
|
||||
// if let Ok((decoded, _)) = bincode::decode_from_slice(&bytes[..], BINCODE_CONFIG) {
|
||||
// Some(decoded)
|
||||
// } else {
|
||||
// None
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
@@ -1,56 +0,0 @@
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::{
|
||||
ModuleError, Result,
|
||||
config::{ConfigStructField, InterfaceData, InterfaceStruct, TreeMessage},
|
||||
warn,
|
||||
};
|
||||
|
||||
pub type ConfigStructKeys = Vec<ConfigStructField>;
|
||||
pub type ConfigStructValues = Vec<Value>;
|
||||
|
||||
pub struct Config {
|
||||
keys: ConfigStructKeys,
|
||||
values: ConfigStructValues,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn new(keys: ConfigStructKeys) -> Self {
|
||||
let values = keys
|
||||
.iter()
|
||||
.map(|key| match key {
|
||||
ConfigStructField::Header(_) => Value::Null,
|
||||
ConfigStructField::Text(_) => Value::Null,
|
||||
ConfigStructField::String { default, .. } => json!(default),
|
||||
ConfigStructField::Integer { default, .. } => json!(default),
|
||||
})
|
||||
.collect();
|
||||
|
||||
Self { keys, values }
|
||||
}
|
||||
|
||||
pub fn get(&mut self, message: TreeMessage) -> Result<TreeMessage> {
|
||||
match message {
|
||||
TreeMessage::State(InterfaceData::ConfigStruct(values)) => {
|
||||
self.values = values;
|
||||
Ok(TreeMessage::Success)
|
||||
}
|
||||
|
||||
// TreeMessage::RequestStruct => Ok(TreeMessage::Interface(
|
||||
// InterfaceStruct::ConfigStruct(self.keys.clone()),
|
||||
// )),
|
||||
TreeMessage::RequestState => Ok(TreeMessage::State(InterfaceData::ConfigStruct(
|
||||
self.values.clone(),
|
||||
))),
|
||||
TreeMessage::RequestStructAndValue => Ok(TreeMessage::InterfaceAndValue(
|
||||
InterfaceStruct::ConfigStruct(self.keys.clone()),
|
||||
InterfaceData::ConfigStruct(self.values.clone()),
|
||||
)),
|
||||
|
||||
_ => {
|
||||
warn!("Tree got invalid message");
|
||||
Err(ModuleError::Error("Invalid Request".into()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::config::ConfigStructField;
|
||||
|
||||
pub type ConfigStructListKeys = Vec<ConfigStructField>;
|
||||
pub type ConfigStructListValues = Vec<Vec<Value>>;
|
||||
|
||||
pub struct ConfigStructList {
|
||||
keys: ConfigStructListKeys,
|
||||
values: ConfigStructListValues,
|
||||
}
|
||||
|
||||
impl ConfigStructList {
|
||||
pub fn new(keys: ConfigStructListKeys) -> Self {
|
||||
// let values = keys
|
||||
// .iter()
|
||||
// .map(|key| match key {
|
||||
// ConfigStructField::Header(_) => Value::Null,
|
||||
// ConfigStructField::Text(_) => Value::Null,
|
||||
// ConfigStructField::String { default, .. } => json!(default),
|
||||
// ConfigStructField::Integer { default, .. } => json!(default),
|
||||
// })
|
||||
// .collect();
|
||||
|
||||
Self {
|
||||
keys,
|
||||
values: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// impl Tree for ConfigStructList {}
|
||||
@@ -1,41 +0,0 @@
|
||||
pub mod config_struct;
|
||||
// pub mod config_struct_list;
|
||||
mod tree;
|
||||
|
||||
pub use tree::{InterfaceData, InterfaceStruct, Tree, TreeMessage};
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RuntimeConfig {
|
||||
pub parent_component: String,
|
||||
pub name: String,
|
||||
pub config: HashMap<String, String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
|
||||
pub enum ConfigStructField {
|
||||
Header(String),
|
||||
Text(String),
|
||||
String {
|
||||
// Default value of string edit in struct
|
||||
#[serde(default)]
|
||||
default: String,
|
||||
max_length: Option<usize>,
|
||||
// Display string edit as password
|
||||
#[serde(default)]
|
||||
protected: bool,
|
||||
},
|
||||
Integer {
|
||||
// Default value of integer in struct
|
||||
#[serde(default)]
|
||||
default: i32,
|
||||
min: Option<i32>,
|
||||
max: Option<i32>,
|
||||
},
|
||||
// Checkbox
|
||||
// Dropdown
|
||||
// Collapsing header
|
||||
// Slider
|
||||
// ...
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{ModuleError, Result, config::config_struct};
|
||||
|
||||
pub trait Tree {
|
||||
fn is_folder() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn get_children_string(&self) -> Vec<String> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn select_child(&mut self, child: &str, _message: TreeMessage) -> Result<TreeMessage>;
|
||||
|
||||
fn get_value(&self, _message: TreeMessage) -> TreeMessage {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn get_path(&mut self, elements: &mut Vec<&str>, message: TreeMessage) -> Result<TreeMessage> {
|
||||
if elements.is_empty() {
|
||||
return if Self::is_folder() {
|
||||
Ok(TreeMessage::Folder(self.get_children_string()))
|
||||
} else {
|
||||
Ok(self.get_value(message))
|
||||
};
|
||||
}
|
||||
|
||||
let child = elements.remove(0);
|
||||
|
||||
if Self::is_folder() {
|
||||
self.select_child(child, message)
|
||||
} else {
|
||||
Err(ModuleError::TreeMessageError(
|
||||
"This is a folder, not a file".into(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn get(&mut self, path: &str, message: TreeMessage) -> Result<TreeMessage> {
|
||||
let mut path = if path.is_empty() {
|
||||
Vec::new()
|
||||
} else {
|
||||
path.split("/").collect::<Vec<&str>>()
|
||||
};
|
||||
|
||||
self.get_path(&mut path, message)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub enum TreeMessage {
|
||||
RequestState,
|
||||
RequestStruct,
|
||||
RequestStructAndValue,
|
||||
|
||||
State(InterfaceData),
|
||||
// Interface(InterfaceStruct),
|
||||
InterfaceAndValue(InterfaceStruct, InterfaceData),
|
||||
|
||||
Success,
|
||||
Failure,
|
||||
|
||||
Folder(Vec<String>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub enum InterfaceStruct {
|
||||
ConfigStruct(config_struct::ConfigStructKeys),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub enum InterfaceData {
|
||||
ConfigStruct(config_struct::ConfigStructValues),
|
||||
}
|
||||
@@ -1,16 +1,11 @@
|
||||
#![no_main]
|
||||
|
||||
pub mod config;
|
||||
mod error;
|
||||
pub mod logger;
|
||||
pub mod tree;
|
||||
|
||||
mod announcement;
|
||||
|
||||
pub use error::{ModuleError, Result};
|
||||
|
||||
pub use announcement::Announcement;
|
||||
|
||||
// Re-exports
|
||||
pub use serde_json::{Value, json};
|
||||
pub use ush_obfuscate as obfuscate;
|
||||
|
||||
Reference in New Issue
Block a user