# HG changeset patch # User Richard Westhaver # Date 1722215932 14400 # Node ID cc2204bc6109d45407d75a0220713ad564fd759a # Parent 5c58d05abae6f87ab218442868050e65939e59f8 revamp diff -r 5c58d05abae6 -r cc2204bc6109 .gitlab-ci.yml --- a/.gitlab-ci.yml Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -image: fukamachi/sbcl -before_script: -- apt-get mercurial -- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -- rustup default nightly -- hg clone https://lab.rwest.io/otom8/demo ~/quicklisp/local-projects/demo -stages: - - build - - test - - deploy -build-job: - stage: build - script: - - echo "Compiling the code..." - - make build - - echo "Compile complete." -unit-test-job: - stage: test - script: - - echo "Running unit tests..." - - make test -lint-test-job: - stage: test - script: - - echo "Linting code..." - - make fmt - - echo "No lint issues found." -deploy-job: - stage: deploy - script: - - echo "Deploying application..." - - echo "Application successfully deployed." \ No newline at end of file diff -r 5c58d05abae6 -r cc2204bc6109 Cargo.toml --- a/Cargo.toml Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -[workspace] -members = ["src/crates/obj","src/crates/ui","src/crates/service"] diff -r 5c58d05abae6 -r cc2204bc6109 Containerfile --- a/Containerfile Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -FROM clfoundation/sbcl:latest -ENV QUICKLISP_ADD_TO_INIT_FILE=true -ENV QUICKLISP_DIST_VERSION=latest -ENV LISP=sbcl -WORKDIR /usr/src/demo -COPY . . -RUN mkdir -p ~/.config/common-lisp/source-registry.conf.d && \ - echo '(:tree "/usr/src/demo")' > ~/.config/common-lisp/source-registry.conf.d/workspace.conf && \ - /usr/local/bin/install-quicklisp -CMD [ "make", "ci" ] \ No newline at end of file diff -r 5c58d05abae6 -r cc2204bc6109 demo.asd --- a/demo.asd Thu Jun 20 22:31:58 2024 -0400 +++ b/demo.asd Sun Jul 28 21:18:52 2024 -0400 @@ -1,40 +1,15 @@ ;;; demo.asd (defsystem "demo" :version "0.1.0" - :author "ellis " - :maintainer "ellis " + :author "Richard Westhaver " + :maintainer "Richard Westhaver " :description "comp demo system" :homepage "https://rwest.io/demo" - :bug-tracker "https://lab.rwest.io/otom8/demo/issues" - :source-control (:hg "https://lab.rwest.io/otom8/demo") + :bug-tracker "https://vc.compiler.ocmpany/demo/issues" + :source-control (:hg "https://vc.compiler.company/demo") :license "WTF" - :depends-on (:sxp :log4cl :bordeaux-threads :clog) - :in-order-to ((test-op (test-op "demo/tests"))) - :components ((:file "src/package") - (:file "src/cfg"))) + :depends-on (:user) + :components ((:file "pkg"))) (defmethod perform :after ((op load-op) (c (eql (find-system :demo)))) (pushnew :demo *features*)) - -(defsystem "demo/cli" - :depends-on ("demo" "clingon") - :components ((:module "src/cli" - :components ((:file "cli")))) - :in-order-to ((test-op (test-op "demo/tests"))) - :build-operation "program-op" - :build-pathname "bin/demo") - -(defsystem "demo/tests" - :depends-on ("demo" "demo-cli" "fiveam") - :components ((:module "src/tests" - :serial t - :components - ((:file "package") - (:file "utils") - (:module "clients" - :serial t - :components - ((:file "cli") - (:file "web")))))) - :perform (test-op (op component) - (uiop:symbol-call '#:demo-tests '#:run-tests))) diff -r 5c58d05abae6 -r cc2204bc6109 makefile --- a/makefile Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -# otom8/demo makefile -MODE?=release -LISP?=sbcl -CFG?=default.cfg -L_C=$(L) --no-userinit -L_D=$(L) --load demo.asd --eval '(ql:quickload "demo")' -L_S=$(L) --script -ARCH?= -A_C=ifeq ($(ARCH),x86_64) A_C=arch -$(ARCH) endif -.PHONY:build -RS:Cargo.toml rustfmt.toml src/crates/* -CL:*/*.asd */*.lisp -deps:; -clean:;rm -rf **/*.fasl;cargo clean -fmt:$(RS);cargo fmt -build:$(RS) $(CL);cargo build --$(MODE);$(L_D) - --eval '(asdf:make "demo")' \ - --eval '(quit)' -docs:$(RS);cargo doc -test:$(RS) $(CL);cargo test;$(L_D) --eval '(asdf:test "demo")' --eval '(quit)' -#pack:;scripts/pack.ros -#check:;scripts/check.ros -ci:clean fmt build docs test; diff -r 5c58d05abae6 -r cc2204bc6109 pkg.lisp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pkg.lisp Sun Jul 28 21:18:52 2024 -0400 @@ -0,0 +1,9 @@ +;; demo packages.lisp +(defpackage :demo-int + (:use :cl :std)) + +(defpackage :demo + (:use #:cl #:demo-int)) + +(std:defpkg :demo-user + (:use-reexport :demo)) diff -r 5c58d05abae6 -r cc2204bc6109 run.lisp --- a/run.lisp Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -(defparameter *cwd* (asdf:system-source-directory :demo)) -(load (merge-pathnames "tools/build-image.lisp" *cwd*)) diff -r 5c58d05abae6 -r cc2204bc6109 rustfmt.toml --- a/rustfmt.toml Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -edition = "2021" -tab_spaces = 2 -wrap_comments = true \ No newline at end of file diff -r 5c58d05abae6 -r cc2204bc6109 skelfile --- a/skelfile Thu Jun 20 22:31:58 2024 -0400 +++ b/skelfile Sun Jul 28 21:18:52 2024 -0400 @@ -1,4 +1,4 @@ -;;; demo/skelfile --- Demo Skeleton +;;; demo/skelfile --- Demo Skelfile :name demo :author "Richard Westhaver " :version "0.1.0" diff -r 5c58d05abae6 -r cc2204bc6109 src/cfg.lisp diff -r 5c58d05abae6 -r cc2204bc6109 src/cli/cli.lisp --- a/src/cli/cli.lisp Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -;; cli.lisp -(in-package :demo-cli) - -(defparameter demo-path (merge-pathnames "demo" (uiop:temporary-directory))) - -(defvar db-path (merge-pathnames "db" demo-path)) - -(defun cli-opts () - "Returns the top-level CLI options." - (list - (clingon:make-option - :string - :description "demo app to run" - :short-name #\x - :long-name "app" - :initial-value "client" - :env-vars '("DEMO_APP") - :key :app) - (clingon:make-option - :string - :description "path to config" - :short-name #\c - :long-name "config" - :initial-value "$DEMO_PATH/.fig" - :env-vars '("DEMO_CONFIG")))) - -(defun cli-handler (cmd) - "Handler for the `demo' command." - (let ((app (clingon:getopt cmd :app))) - (format t "running: ~A!~%" app))) - -(defun cli-cmd () - "Our demo command." - (clingon:make-command - :name "demo" - :description "A collection of demos" - :version "1.0.0" - :authors '("ellis ") - :license "WTFPL" - :options (cli-opts) - :handler #'cli-handler)) - -(defun run-cli () - "A demo of some common-lisp functionality." - (clingon:run (cli-cmd))) diff -r 5c58d05abae6 -r cc2204bc6109 src/cli/package.lisp --- a/src/cli/package.lisp Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -(defpackage :demo-cli - (:use :demo) - (:export - #:run-cli - #:demo-path - #:db-path - #:cli-opts - #:cli-handler - #:cli-cmd)) diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/obj/Cargo.toml --- a/src/crates/obj/Cargo.toml Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -[package] -name = "obj" -version = "0.1.0" -edition = "2021" -[features] -oauth = ["yup-oauth2"] - -[dependencies] -ron = "0.7.0" -bincode = "1.3.3" -serde_json = "1.0.68" -serde = { version = "1.0.130", features = ["derive"] } -chrono = { version = "0.4.19", features = ["serde"] } -mime = "0.3.16" -regex = "1.5.4" -rusty_ulid = "0.11.0" -uuid = { version = "0.8", features = ["serde"] } -yup-oauth2 = { version = "5.1.0", optional = true } -blake3 = "1.0.0" -hashbrown = "0.11.2" -rand = "0.8.0" -sha2 = "0.9.5" -hex = "0.4.3" -ulid = "1.0.0" - -[target.'cfg(target_arch = "wasm32")'.dependencies] -uuid = { version = "0.8", features = ["wasm-bindgen"] } diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/obj/proc_macros/Cargo.toml --- a/src/crates/obj/proc_macros/Cargo.toml Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -[package] -name = "proc_macros" -version = "0.1.0" -edition = "2021" -[lib] -proc-macro = true -[dependencies] -quote = "1.0" -proc-macro2 = "1.0" -syn = "1.0" \ No newline at end of file diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/obj/proc_macros/src/derive.rs --- a/src/crates/obj/proc_macros/src/derive.rs Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -mod derive; -use proc_macro::TokenStream; -pub fn derive_static_type(input: TokenStream) -> TokenStream { - derive::derive_static_type(input) -} diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/obj/proc_macros/src/lib.rs --- a/src/crates/obj/proc_macros/src/lib.rs Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ - diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/obj/src/auth.rs --- a/src/crates/obj/src/auth.rs Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -//! Auth Configs -use serde::{Deserialize, Serialize}; - -#[cfg(feature = "oauth")] -use yup_oauth2::ApplicationSecret; - -#[derive(Serialize, Deserialize, Debug, Default, Hash)] -pub struct AuthConfig { - pub provider: String, - #[cfg(feature = "oauth")] - pub oauth: Option, - pub ssh: Option, - pub pw: Option, -} - -#[derive(Serialize, Deserialize, Default, Debug, Hash)] -pub struct PasswordConfig(String, String); - -#[cfg(feature = "oauth")] -#[derive(Serialize, Deserialize, Hash, Debug, PartialEq, Clone, Default)] -pub struct Oauth2Config { - pub client_id: String, - pub client_secret: String, - pub redirect_uris: Vec, - pub auth_uri: String, - pub token_uri: String, - pub project_id: Option, //for apptoken - pub client_email: Option, - /// The URL of the public x509 certificate, used to verify the signature on - /// JWTs, such as ID tokens, signed by the authentication provider. - pub auth_provider_x509_cert_url: Option, - /// The URL of the public x509 certificate, used to verify JWTs signed by the - /// client. - pub client_x509_cert_url: Option, -} - -#[cfg(feature = "oauth")] -impl From for Oauth2Config { - fn from(shh: ApplicationSecret) -> Self { - Oauth2Config { - client_id: shh.client_id, - client_secret: shh.client_secret, - redirect_uris: shh.redirect_uris, - auth_uri: shh.auth_uri, - token_uri: shh.token_uri, - project_id: shh.project_id, - client_email: shh.client_email, - auth_provider_x509_cert_url: shh.auth_provider_x509_cert_url, - client_x509_cert_url: shh.client_x509_cert_url, - } - } -} - -#[cfg(feature = "oauth")] -impl From for ApplicationSecret { - fn from(cfg: Oauth2Config) -> Self { - ApplicationSecret { - client_id: cfg.client_id, - client_secret: cfg.client_secret, - redirect_uris: cfg.redirect_uris, - auth_uri: cfg.auth_uri, - token_uri: cfg.token_uri, - project_id: cfg.project_id, - client_email: cfg.client_email, - auth_provider_x509_cert_url: cfg.auth_provider_x509_cert_url, - client_x509_cert_url: cfg.client_x509_cert_url, - } - } -} - -#[derive(Serialize, Deserialize, Hash, Debug, PartialEq, Clone, Default)] -pub struct SshConfig {} diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/obj/src/cfg.rs --- a/src/crates/obj/src/cfg.rs Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/// common trait for all config modules. This trait provides functions -/// for de/serializing to/from RON, updating fields, and formatting. -use serde::{Serialize, Deserialize}; -use crate::Objective; -use std::collections::HashMap as M; -use std::path::PathBuf; -use std::string::String as S; -use std::error::Error as E; -use std::boxed::Box as B; -type R = std::result::Result>; - -pub trait Configure: Objective { - fn update(&self) -> R<()> { - Ok(()) - } -} - -#[derive(Serialize, Deserialize, Debug, Default)] -pub struct ShellConfig { - pub env: M, - pub cmds: M, - pub shell: ShellType, -} - -impl Objective for ShellConfig {} - -#[derive(Serialize, Deserialize, Debug, Hash, Default)] -pub enum ShellType { - #[default] - Bash, - Zsh, - Sh, -} - -#[derive(Serialize, Deserialize, Debug, Default)] -pub enum EditorType { - #[default] - Emacs, - Vi, - Nano, -} - -#[derive(Serialize, Deserialize, Debug, Default)] -pub struct EditorConfig { - pub editor: EditorType, - pub cmds: M, - pub init_file: PathBuf, -} - -#[cfg(test)] -mod tests; diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/obj/src/database.rs --- a/src/crates/obj/src/database.rs Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -//! cfg::config::database -//! -//! Database configuration primitives -use serde::{Deserialize, Serialize}; - -#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq)] -pub struct DatabaseConfig { - engine: DatabaseType, - path: String, - cfs: Vec, -} - -#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq)] -pub enum DatabaseType { - RocksDB, - Postgres, - Alch, -} diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/obj/src/err.rs --- a/src/crates/obj/src/err.rs Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -//! obj errors -use std::{fmt, io}; - -/// obj Result wrapper -pub type Result = std::result::Result; - -/// obj Error type -#[derive(Debug)] -pub enum Error { - Message(String), - Ron(ron::error::Error), - Json(serde_json::error::Error), - Io(io::Error), - Bincode(bincode::Error), - Utf8(std::string::FromUtf8Error), - Parse(std::string::ParseError), -} - -impl serde::ser::Error for Error { - fn custom(msg: T) -> Self { - Error::Message(msg.to_string()) - } -} - -impl serde::de::Error for Error { - fn custom(msg: T) -> Self { - Error::Message(msg.to_string()) - } -} - -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - Error::Message(msg) => f.write_str(msg), - Error::Io(ref err) => write!(f, "obj IO error: {}", err), - Error::Ron(ref err) => write!(f, "obj Ron error: {}", err), - Error::Json(ref err) => write!(f, "obj Json error: {}", err), - Error::Bincode(ref err) => write!(f, "obj Bincode error: {}", err), - Error::Utf8(ref err) => write!(f, "obj Utf8 error: {}", err), - Error::Parse(ref err) => write!(f, "obj Parse error: {}", err), - } - } -} - -impl From for Error { - fn from(e: io::Error) -> Self { - Error::Io(e) - } -} - -impl From for Error { - fn from(e: std::string::ParseError) -> Self { - Error::Parse(e) - } -} - -impl From for Error { - fn from(err: std::string::FromUtf8Error) -> Self { - Error::Utf8(err) - } -} - -impl From for Error { - fn from(e: ron::Error) -> Self { - Error::Ron(e) - } -} - -impl From for Error { - fn from(e: serde_json::Error) -> Self { - Error::Json(e) - } -} - -impl From for Error { - fn from(e: bincode::Error) -> Self { - Error::Bincode(e) - } -} - -impl std::error::Error for Error {} diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/obj/src/hash.rs --- a/src/crates/obj/src/hash.rs Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -//! hash - wrapper for hash algorithms and types - -pub use blake3::{derive_key, hash, keyed_hash, Hash as B3Hash, Hasher as B3Hasher, OutputReader}; -pub use hex; -pub use sha2::Sha512; - -pub use std::hash::{Hash, Hasher}; - -pub const KEY_LEN: usize = 32; -pub const OUT_LEN: usize = 32; -pub const OUT_LEN_HEX: usize = OUT_LEN * 2; - -#[cfg(test)] -mod tests { - use super::*; - use crate::*; - #[test] - fn id_state_hash() { - let id = id::Id(vec![0; KEY_LEN]); - let hash = id.state_hash(&mut B3Hasher::new()); - assert_eq!(hash, id.state_hash(&mut B3Hasher::new())); - } - - #[test] - fn id_hex() { - let id = id::Id(vec![255; KEY_LEN]); - - assert_eq!( - hex::decode("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap(), - id.0 - ); - } - - #[test] - fn rand_id() { - let id = id::Id::rand(); - let hash = id.state_hash(&mut B3Hasher::new()); - assert_eq!(hash, id.state_hash(&mut B3Hasher::new())); - } - - #[test] - fn random_demon_id_is_valid() { - use id::PeerId; - for _ in 0..5000 { - let did = PeerId::rand(); - let did2 = PeerId::rand(); - assert_eq!(did, did); - assert_ne!(did, did2); - } - } -} diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/obj/src/id.rs --- a/src/crates/obj/src/id.rs Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,120 +0,0 @@ -use crate::hash::{B3Hasher, KEY_LEN, OUT_LEN}; -use rand::Rng; -use serde::{Deserialize, Serialize}; -use std::{fmt, str::FromStr}; -pub use ulid::Ulid; -pub use uuid::Uuid; -/// a simple Id abstraction -#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Serialize, Deserialize, Hash)] -pub struct Id(pub Vec); - -impl Id { - pub fn rand() -> Self { - let mut rng = rand::thread_rng(); - let vals: Vec = (0..KEY_LEN).map(|_| rng.gen_range(0..u8::MAX)).collect(); - Id(vals) - } - - pub fn state_hash(&self, state: &mut B3Hasher) -> Self { - let mut output = vec![0; OUT_LEN]; - state.update(&self.0); - let mut res = state.finalize_xof(); - res.fill(&mut output); - Id(output) - } - - pub fn to_hex(&self) -> String { - hex::encode(&self.0) - } -} - -/// PeerId -/// -/// identifies a unique Peer -#[derive(Clone, Eq, Hash, Ord, PartialEq, PartialOrd, Debug)] -pub struct PeerId { - id: [u8; 32], -} - -impl PeerId { - pub fn new() -> Self { - Self::default() - } - - pub fn rand() -> Self { - let pd = rand::thread_rng().gen::<[u8; 32]>(); - Self { id: pd } - } - - pub fn from_bytes(data: &[u8]) -> Self { - let pd = blake3::hash(data); - let hash = pd.as_bytes(); - Self { id: *hash } - } -} - -impl Default for PeerId { - fn default() -> Self { - PeerId { id: [0; 32] } - } -} - -/// Identity trait -/// -/// Defines Identity-related behaviors -pub trait Identity: Sized { - /// return the hashed bytes of an ObjectId - fn id(&self) -> Id; -} - -#[derive(Debug, Copy, Clone, Eq, PartialEq)] -pub struct ObjectId(u128); - -pub struct NameSpace { - pub prefix: Option, - pub capacity: u64, - pub route: Vec, - pub key: Option, -} - -pub struct Domain { - pub ns: NameSpace, - pub id: Id, -} - -impl From for ObjectId { - fn from(uuid: Uuid) -> Self { - ObjectId(uuid.as_u128()) - } -} - -impl From for ObjectId { - fn from(ulid: Ulid) -> Self { - ObjectId(u128::from(ulid)) - } -} - -impl From for ObjectId { - fn from(src: u128) -> Self { - ObjectId(src) - } -} - -impl FromStr for ObjectId { - type Err = (); - fn from_str(input: &str) -> std::result::Result { - match input { - i => Ok(ObjectId(u128::from(Ulid::from_str(i).unwrap()))), - } - } -} - -impl fmt::Display for ObjectId { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - ObjectId(i) => { - write!(f, "{}", Ulid::from(i)) - } - } - } -} diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/obj/src/lib.rs --- a/src/crates/obj/src/lib.rs Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,148 +0,0 @@ -//! obj/src/lib.rs --- Objective type library -#![feature(associated_type_bounds)] -mod err; -pub use err::{Error, Result}; -mod types; -pub use types::*; -pub mod auth; -pub mod database; -pub mod hash; -pub mod id; -pub mod network; -pub use bincode; -pub use ron; -use ron::extensions::Extensions; -use serde::{de::DeserializeOwned, Deserialize, Serialize}; -pub use serde_json; -use std::collections::{BTreeMap, HashMap}; -use std::io; - -/// Objective trait -/// Define Object behaviors, implemented by Objects -pub trait Objective { - fn encode(&self) -> Result> - where - Self: Serialize, - { - Ok(bincode::serialize(self)?) - } - - fn encode_into(&self, writer: W) -> Result<()> - where - W: io::Write, - Self: Serialize, - { - Ok(bincode::serialize_into(writer, self)?) - } - - fn decode<'a>(bytes: &'a [u8]) -> Result - where - Self: Deserialize<'a>, - { - Ok(bincode::deserialize(bytes)?) - } - - fn decode_from(&self, rdr: R) -> Result - where - R: io::Read, - Self: DeserializeOwned, - { - Ok(bincode::deserialize_from(rdr)?) - } - - fn to_ron_writer(&self, writer: W) -> Result<()> - where - W: io::Write, - Self: Serialize, - { - Ok(ron::ser::to_writer_pretty( - writer, - &self, - ron::ser::PrettyConfig::new() - .indentor(" ".to_owned()) - .extensions(Extensions::all()), - )?) - } - - fn to_ron_string(&self) -> Result - where - Self: Serialize, - { - Ok(ron::ser::to_string_pretty( - &self, - ron::ser::PrettyConfig::new().indentor(" ".to_owned()), - )?) - } - - fn from_ron_reader(&self, mut rdr: R) -> Result - where - R: io::Read, - Self: DeserializeOwned, - { - let mut bytes = Vec::new(); - rdr.read_to_end(&mut bytes)?; - Ok(ron::de::from_bytes(&bytes)?) - } - - fn from_ron_str<'a>(s: &'a str) -> Result - where - Self: Deserialize<'a>, - { - Ok(ron::de::from_bytes(s.as_bytes())?) - } - - fn to_json_writer(&self, writer: W) -> Result<()> - where - W: io::Write, - Self: Serialize, - { - // let formatter = serde_json::ser::PrettyFormatter::with_indent(b" "); - Ok(serde_json::ser::to_writer_pretty(writer, &self)?) - } - - fn to_json_string(&self) -> Result - where - Self: Serialize, - { - Ok(serde_json::ser::to_string_pretty(&self)?) - } - - fn from_json_reader(&self, mut rdr: R) -> Result - where - R: io::Read, - Self: DeserializeOwned, - { - let mut bytes = Vec::new(); - rdr.read_to_end(&mut bytes)?; - Ok(serde_json::de::from_slice(&bytes)?) - } - - fn from_json_str<'a>(s: &'a str) -> Result - where - Self: Deserialize<'a>, - { - Ok(serde_json::de::from_slice(s.as_bytes())?) - } -} - -impl Objective for Vec {} -impl Objective for HashMap {} -impl Objective for BTreeMap {} -impl Objective for std::path::PathBuf {} -impl Objective for std::path::Path {} -impl Objective for std::string::String {} -impl Objective for std::any::TypeId {} -impl Objective for u8 {} -impl Objective for u16 {} -impl Objective for u32 {} -impl Objective for u64 {} -impl Objective for u128 {} -impl Objective for i8 {} -impl Objective for i16 {} -impl Objective for i32 {} -impl Objective for i64 {} -impl Objective for i128 {} -impl Objective for isize {} -impl Objective for usize {} -impl Objective for f32 {} -impl Objective for f64 {} diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/obj/src/network.rs --- a/src/crates/obj/src/network.rs Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -//! cfg::config::network -//! -//! Network configuration primitives -use serde::{Deserialize, Serialize}; -use std::{fmt, net::SocketAddr}; - -/// Network configuration -#[derive(Serialize, Deserialize, Hash, Debug, PartialEq, Clone)] -pub struct NetworkConfig { - /// a socket to bind - pub socket: SocketAddr, - /// a proxy to forward packets from - pub proxy: Option, - /// tunnel to use - pub tunnel: Option, - /// network engine to attach - pub engine: EngineType, - /// peers to register AOT - pub peers: Option>, -} - -impl Default for NetworkConfig { - fn default() -> Self { - NetworkConfig { - socket: "127.0.0.1:0".parse().unwrap(), - proxy: None, - tunnel: None, - engine: EngineType::default(), - peers: None, - } - } -} - -#[derive(Serialize, Deserialize, Hash, Debug, PartialEq, Clone)] -pub enum EngineType { - Quic, - Http, - Dns, - Ssh, - Uds, -} - -impl Default for EngineType { - fn default() -> Self { - Self::Http - } -} - -impl std::fmt::Display for EngineType { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - EngineType::Quic => write!(f, "quic"), - EngineType::Http => write!(f, "http"), - EngineType::Dns => write!(f, "dns"), - EngineType::Ssh => write!(f, "ssh"), - EngineType::Uds => write!(f, "uds"), - } - } -} diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/obj/src/types.rs --- a/src/crates/obj/src/types.rs Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -//! obj/src/types.rs --- OBJ type descriptions used by our demo -use crate::{Deserialize, Objective, Result, Serialize}; -use std::collections::HashMap; - -/// APPLICATION TYPES -#[derive(Serialize, Deserialize, Default)] -pub enum Service { - Weather, - Stocks, - Dynamic(Vec), - Custom(CustomService), - #[default] - Bench, -} - -impl Objective for Service {} - -impl From<&str> for Service { - fn from(value: &str) -> Self { - match value { - "weather" => Service::Weather, - "stocks" => Service::Stocks, - "bench" => Service::Bench, - s => { - if s.contains(",") { - let x = s.split(","); - Service::Dynamic( - x.map(|y| Service::Custom(y.into())) - .collect::>(), - ) - } else { - Service::Custom(s.into()) - } - } - } - } -} - -#[derive(Serialize, Deserialize, Default)] -pub struct CustomService { - name: String, - registry: HashMap>, -} - -impl Objective for CustomService {} -impl From for Service { - fn from(value: CustomService) -> Self { - Service::Custom(value) - } -} -impl From<&str> for CustomService { - fn from(value: &str) -> Self { - let name = value.to_owned(); - let registry = HashMap::new(); - CustomService { name, registry } - } -} - -#[derive(Serialize, Deserialize, Default)] -pub struct Complex { - data: X, - stack: Vec, - registry: HashMap>, -} - -impl Objective for Complex {} - -pub fn generate_complex() -> Result> { - Ok(Complex::::from_json_str("hi")?) -} diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/service/Cargo.toml --- a/src/crates/service/Cargo.toml Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -[package] -name = "demo_service" -version = "0.1.0" -edition = "2021" -[lib] -path = "lib.rs" -[[bin]] -name = "demo-service" -path = "main.rs" -[[test]] -name = "tests" -path = "tests.rs" - -[dependencies] -obj = { version = "0.1.0", path = "../obj" } -tokio = { version = "1.28.2", features = ["full"] } -sqlx = { version = "0.6.3", features = ["runtime-tokio-rustls", "any", "postgres"] } -axum = { version = "0.6.18" } -tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } -tracing = "0.1.37" - diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/service/lib.rs --- a/src/crates/service/lib.rs Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ - diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/service/main.rs --- a/src/crates/service/main.rs Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ - -use tokio::net::TcpListener; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; - -#[tokio::main] -async fn main() { - tracing_subscriber::registry() - .with( - tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "demo_service=debug".into()), - ) - .with(tracing_subscriber::fmt::layer()) - .init(); - - let listener = TcpListener::bind("127.0.0.1:8888").await.unwrap(); - tracing::debug!("listening on {}", listener.local_addr().unwrap()); -} diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/service/tests.rs --- a/src/crates/service/tests.rs Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ - diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/ui/Cargo.toml --- a/src/crates/ui/Cargo.toml Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -[package] -name = "ui" -version = "0.1.0" -edition = "2021" -build = "build.rs" -[lib] -path = "lib.rs" -crate-type = ["rlib","cdylib"] -[[bin]] -name = "demo-ui" -path = "main.rs" -[build-dependencies] -slint-build = "1.0.2" -[dependencies] -obj = {version = "0.1.0",path = "../obj"} -env_logger = "0.10.0" -log = "0.4.17" -slint = "1.0.2" -[target.'cfg(target_arch = "wasm32")'.dependencies] -wasm-bindgen = { version = "0.2" } -web-sys = { version = "0.3", features=["console"] } -console_error_panic_hook = "0.1.5" diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/ui/build.rs --- a/src/crates/ui/build.rs Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -fn main() { - slint_build::compile("ui.slint").unwrap(); -} diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/ui/config.slint --- a/src/crates/ui/config.slint Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -export global UiConfig { - in property widgets-disabled: false; -} \ No newline at end of file diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/ui/img/ayo.jpeg Binary file src/crates/ui/img/ayo.jpeg has changed diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/ui/img/treez.png Binary file src/crates/ui/img/treez.png has changed diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/ui/index.html --- a/src/crates/ui/index.html Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ - - - >/canvas> - - - diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/ui/lib.rs --- a/src/crates/ui/lib.rs Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -#![deny(unsafe_code)] - -#[cfg(target_arch = "wasm32")] -use wasm_bindgen::prelude::*; - -slint::include_modules!(); - -use std::rc::Rc; - -use slint::{Model, StandardListViewItem, VecModel}; - -#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))] -pub fn run() { - // This provides better error messages in debug mode. - // It's disabled in release mode so it doesn't bloat up the file size. - #[cfg(all(debug_assertions, target_arch = "wasm32"))] - console_error_panic_hook::set_once(); - - let app = App::new().unwrap(); - - let row_data: Rc>> = Rc::new(VecModel::default()); - - for r in 1..101 { - let items = Rc::new(VecModel::default()); - - for c in 1..5 { - items.push(slint::format!("Item {r}.{c}").into()); - } - - row_data.push(items.into()); - } - - app - .global::() - .set_row_data(row_data.clone().into()); - - app.global::().on_sort_ascending({ - let app_weak = app.as_weak(); - let row_data = row_data.clone(); - move |index| { - let row_data = row_data.clone(); - - let sort_model = Rc::new(row_data.sort_by(move |r_a, r_b| { - let c_a = r_a.row_data(index as usize).unwrap(); - let c_b = r_b.row_data(index as usize).unwrap(); - - c_a.text.cmp(&c_b.text) - })); - - app_weak - .unwrap() - .global::() - .set_row_data(sort_model.into()); - } - }); - - app.global::().on_sort_descending({ - let app_weak = app.as_weak(); - move |index| { - let row_data = row_data.clone(); - - let sort_model = Rc::new(row_data.sort_by(move |r_a, r_b| { - let c_a = r_a.row_data(index as usize).unwrap(); - let c_b = r_b.row_data(index as usize).unwrap(); - - c_b.text.cmp(&c_a.text) - })); - - app_weak - .unwrap() - .global::() - .set_row_data(sort_model.into()); - } - }); - - app.run().unwrap(); -} diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/ui/main.rs --- a/src/crates/ui/main.rs Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -use ui::run; -fn main() { - run(); -} diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/ui/pages.slint --- a/src/crates/ui/pages.slint Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -import { AboutPage } from "pages/about.slint"; -import { ControlsPage } from "pages/controls.slint"; -import { ListViewPage } from "pages/list_view.slint"; -import { TableViewPage, TableViewPageAdapter } from "pages/table_view.slint"; -import { TextEditPage } from "pages/text_edit.slint"; - -export { AboutPage, ControlsPage, ListViewPage, TextEditPage, TableViewPage, TableViewPageAdapter } \ No newline at end of file diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/ui/pages/about.slint --- a/src/crates/ui/pages/about.slint Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -import { AboutSlint } from "std-widgets.slint"; -import { UiConfig } from "../config.slint"; -import { Page } from "page.slint"; - -export component AboutPage inherits Page { - title: "About"; - description: "Are you curious now? Check out the docs and gettings start from the Github repository and the website https://slint-ui.com and try it yourself."; - - AboutSlint {} -} \ No newline at end of file diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/ui/pages/controls.slint --- a/src/crates/ui/pages/controls.slint Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,145 +0,0 @@ -import { Button, GroupBox, SpinBox, ComboBox, CheckBox, LineEdit, TabWidget, VerticalBox, HorizontalBox, - Slider, SpinBox } from "std-widgets.slint"; -import { UiConfig } from "../config.slint"; -import { Page } from "page.slint"; - -export component ControlsPage inherits Page { - title: "Controls"; - description: "This page gives an overview of the default widget set provided by Slint. The widgets are available in different styles native, fluent-(dark/light) and material-(dark/light). The widgets can be imported from \"std-widgets.slint\"."; - - GroupBox { - vertical-stretch: 0; - title: "Buttons"; - - HorizontalLayout { - spacing: 8px; - alignment: start; - - Button { - text: "Regular Button"; - enabled: !UiConfig.widgets-disabled; - } - - Button { - text: "Button with Icon"; - icon: @image-url("../img/treez.png"); - enabled: !UiConfig.widgets-disabled; - } - - Button { - checkable: true; - text: self.checked ? "ON" : "OFF"; - enabled: !UiConfig.widgets-disabled; - } - } - } - - GroupBox { - title: "CheckBox - SpinBox - ComboBox"; - vertical-stretch: 0; - - HorizontalBox { - alignment: start; - checkbox := CheckBox { - text: checkbox.checked ? "(checked)" : "(unchecked)"; - checked: true; - enabled: !UiConfig.widgets-disabled; - } - - - SpinBox { - vertical-stretch: 0; - value: 42; - enabled: !UiConfig.widgets-disabled; - } - - ComboBox { - model: ["Select Something", "From this", "Combobox"]; - enabled: !UiConfig.widgets-disabled; - } - } - - - } - - GroupBox { - title: "LineEdit"; - vertical-stretch: 0; - - LineEdit { - placeholder-text: "Enter some text"; - enabled: !UiConfig.widgets-disabled; - } - } - - GroupBox { - title: "Slider"; - vertical-stretch: 0; - - Slider { - min-width: 160px; - minimum: -100; - maximum: 100; - value: 42; - enabled: !UiConfig.widgets-disabled; - } - } - - GroupBox { - title: "TabWidget"; - - TabWidget { - Tab { - title: "Tab 1"; - - VerticalBox { - alignment: start; - - GroupBox { - title: "Content of tab 1"; - - HorizontalBox { - alignment: start; - - Button { - text: "Click me"; - enabled: !UiConfig.widgets-disabled; - } - } - } - } - } - - Tab { - title: "Tab 2"; - - VerticalBox { - alignment: start; - - GroupBox { - title: "Content of tab 2"; - - VerticalBox { - alignment: start; - - CheckBox { - text: "Check me"; - enabled: !UiConfig.widgets-disabled; - } - } - } - } - } - - Tab { - title: "Tab 3"; - - VerticalBox { - Text { - text: "Content of tab 3"; - } - } - } - } - } -} \ No newline at end of file diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/ui/pages/list_view.slint --- a/src/crates/ui/pages/list_view.slint Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -import { HorizontalBox, VerticalBox, ListView, StandardListView, GroupBox } from "std-widgets.slint"; -import { UiConfig } from "../config.slint"; -import { Page } from "page.slint"; - -export component ListViewPage inherits Page { - title: "ListView"; - description: "ListViews can be used to display a list of elements. The StandardListBox is like the default ListView just with a default text based definition of the visual items. Both can be imported from \"std-widgets.slint\""; - - HorizontalBox { - vertical-stretch: 1; - GroupBox { - title: "ListView"; - - ListView { - vertical-stretch: 0; - for i in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] : HorizontalBox { - Image { - width: 24px; - source: @image-url("../img/ayo.jpeg"); - } - Text { - text: "Item " + i; - } - } - } - } - - GroupBox { - title: "StandardListView"; - vertical-stretch: 0; - - StandardListView { - model: [ - {text: "Lorem"}, {text: "ipsum"},{text: "dolor"},{text: "sit"},{text: "amet"},{text: "consetetur"}, - {text: "Lorem"}, {text: "ipsum"},{text: "dolor"},{text: "sit"},{text: "amet"},{text: "consetetur"}, - {text: "Lorem"}, {text: "ipsum"},{text: "dolor"},{text: "sit"},{text: "amet"},{text: "consetetur"}, - {text: "Lorem"}, {text: "ipsum"},{text: "dolor"},{text: "sit"},{text: "amet"},{text: "consetetur"}, - {text: "Lorem"}, {text: "ipsum"},{text: "dolor"},{text: "sit"},{text: "amet"},{text: "consetetur"}, - {text: "Lorem"}, {text: "ipsum"},{text: "dolor"},{text: "sit"},{text: "amet"},{text: "consetetur"}, - {text: "Lorem"}, {text: "ipsum"},{text: "dolor"},{text: "sit"},{text: "amet"},{text: "consetetur"}, - ]; - } - } - } -} \ No newline at end of file diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/ui/pages/page.slint --- a/src/crates/ui/pages/page.slint Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -import { CheckBox, GridBox, ListView, ScrollView, VerticalBox } from "std-widgets.slint"; - -import { UiConfig } from "../config.slint"; - -export component Page inherits VerticalBox { - in property title: "title"; - in property description: "description"; - - HorizontalLayout { - height: 24px; - Text { - font-size: 20px; - text <=> root.title; - } - - // Spacer - Rectangle {} - - CheckBox { - horizontal-stretch: 0; - text: "Disable widgets"; - checked <=> UiConfig.widgets-disabled; - } - } - - @children -} \ No newline at end of file diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/ui/pages/table_view.slint --- a/src/crates/ui/pages/table_view.slint Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -import { HorizontalBox, VerticalBox, StandardTableView, GroupBox} from "std-widgets.slint"; -import { UiConfig } from "../config.slint"; -import { Page } from "page.slint"; - -export global TableViewPageAdapter { - callback sort_ascending(int); - callback sort_descending(int); - in property <[[StandardListViewItem]]> row_data: [ - [ { text: "Item 1.1" }, { text: "Item 1.2" }, { text: "Item 1.3" }, { text: "Item 1.4" }, ], - [ { text: "Item 2.1" }, { text: "Item 2.2" }, { text: "Item 2.3" }, { text: "Item 2.4" }, ], - [ { text: "Item 3.1" }, { text: "Item 3.2" }, { text: "Item 3.3" }, { text: "Item 3.4" }, ], - [ { text: "Item 4.1" }, { text: "Item 4.2" }, { text: "Item 4.3" }, { text: "Item 4.4" }, ], - [ { text: "Item 5.1" }, { text: "Item 5.2" }, { text: "Item 5.3" }, { text: "Item 5.4" }, ], - [ { text: "Item 6.1" }, { text: "Item 6.2" }, { text: "Item 6.3" }, { text: "Item 6.4" }, ], - ]; -} - -export component TableViewPage inherits Page { - title: "TableView"; - description: "StandardTableView can be used to display a list of text elements in columns and rows. It can be imported from \"std-widgets.slint\""; - - HorizontalBox { - vertical-stretch: 1; - - GroupBox { - title: "StandardTableView"; - vertical-stretch: 0; - - StandardTableView { - sort-ascending(index) => { - TableViewPageAdapter.sort_ascending(index); - } - - sort-descending(index) => { - TableViewPageAdapter.sort-descending(index); - } - - columns: [ - { title: "Header 1" }, - { title: "Header 2" }, - { title: "Header 3" }, - { title: "Header 4" }, - ]; - rows: TableViewPageAdapter.row_data; - } - } - } -} \ No newline at end of file diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/ui/pages/text_edit.slint --- a/src/crates/ui/pages/text_edit.slint Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -import { HorizontalBox, GroupBox, TextEdit } from "std-widgets.slint"; -import { UiConfig } from "../config.slint"; -import { Page } from "page.slint"; - -export component TextEditPage inherits Page { - title: "TextEdit"; - description: "Similar to LineEdit, but can be used to enter several lines of text. The widget can be imported from \"std-widgets.slint\"."; - - HorizontalBox { - GroupBox { - vertical-stretch: 0; - title: "Word-Wrap"; - te1 := TextEdit { - min-width: 200px; - text: "This is our TextEdit widget, which allows for editing text that spans over multiple paragraphs.\nFor example this line starts in a new paragraph.\n\nWhen the amount of lines - due to wrapping and number of paragraphs - exceeds the available vertical height, a vertical scrollbar is shown that allows scrolling.\nYou may want to enter a bit of text here then in order to make them visible."; - wrap: word-wrap; - enabled: !UiConfig.widgets-disabled; - } - } - - GroupBox { - title: "No-Wrap"; - vertical-stretch: 0; - te2 := TextEdit { - min-width: 200px; - text <=> te1.text; - wrap: no-wrap; - enabled: !UiConfig.widgets-disabled; - } - } - } -} \ No newline at end of file diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/ui/sidebar.slint --- a/src/crates/ui/sidebar.slint Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,127 +0,0 @@ -import { StyleMetrics } from "std-widgets.slint"; - -component SideBarItem inherits Rectangle { - callback clicked <=> touch.clicked; - in-out property text <=> label.text; - in property selected; - in property has-focus; - - min-height: l.preferred-height; - - state := Rectangle { - opacity: 0; - background: StyleMetrics.window-background; - - animate opacity { duration: 150ms; } - } - - l := HorizontalLayout { - y: (parent.height - self.height) / 2; - padding: StyleMetrics.layout-padding; - spacing: 0px; - - label := Text { - color: StyleMetrics.default-text-color; - vertical-alignment: center; - } - } - - touch := TouchArea { - width: 100%; - height: 100%; - } - - states [ - pressed when touch.pressed : { - state.opacity: 0.8; - } - hover when touch.has-hover : { - state.opacity: 0.6; - } - selected when root.selected : { - state.opacity: 1; - } - focused when root.has-focus : { - state.opacity: 0.8; - } - ] -} - -export component SideBar inherits Rectangle { - in property<[string]> model: []; - out property current-item: 0; - in property title <=> label.text; - out property current-focused: fs.has-focus ? fs.focused-tab : -1; // The currently focused tab - width: 180px; - - forward-focus: fs; - - accessible-role: tab; - accessible-delegate-focus: root.current-focused >= 0 ? root.current-focused : root.current-item; - - Rectangle { - background: StyleMetrics.window-background.darker(0.2); - - fs := FocusScope { - x:0; - width: 0px; // Do not react on clicks - property focused-tab: 0; - - key-pressed(event) => { - if (event.text == "\n") { - root.current-item = root.current-focused; - return accept; - } - if (event.text == Key.UpArrow) { - self.focused-tab = Math.max(self.focused-tab - 1, 0); - return accept; - } - if (event.text == Key.DownArrow) { - self.focused-tab = Math.min(self.focused-tab + 1, root.model.length - 1); - return accept; - } - return reject; - } - - key-released(event) => { - if (event.text == " ") { - root.current-item = root.current-focused; - return accept; - } - return reject; - } - } - } - - VerticalLayout { - padding-top: StyleMetrics.layout-padding; - padding-bottom: StyleMetrics.layout-padding; - spacing: StyleMetrics.layout-spacing; - alignment: start; - - label := Text { - font-size: 16px; - horizontal-alignment: center; - } - - navigation := VerticalLayout { - alignment: start; - vertical-stretch: 0; - for item[index] in root.model : SideBarItem { - has-focus: index == root.current-focused; - text: item; - selected: index == root.current-item; - clicked => { root.current-item = index; } - } - } - - VerticalLayout { - bottom := VerticalLayout { - padding-left: StyleMetrics.layout-padding; - padding-right: StyleMetrics.layout-padding; - - @children - } - } - } -} \ No newline at end of file diff -r 5c58d05abae6 -r cc2204bc6109 src/crates/ui/ui.slint --- a/src/crates/ui/ui.slint Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -import {CheckBox, StandardListView, StyleMetrics} from "std-widgets.slint"; -import {AboutPage, ControlsPage, ListViewPage, TableViewPage, TableViewPageAdapter, TextEditPage} from "pages.slint"; -import {UiConfig} from "config.slint"; -import {SideBar} from "sidebar.slint"; -export {TableViewPageAdapter} -export component App inherits Window { - title: "Demo"; - icon: @image-url("img/treez.png"); - HorizontalLayout { - side-bar := SideBar { - title: "Demo"; - model: ["Controls", "ListView", "TableView", "TextEdit", "About"]; - } - if(side-bar.current-item == 0) : ControlsPage {} - if(side-bar.current-item == 1) : ListViewPage {} - if(side-bar.current-item == 2) : TableViewPage {} - if(side-bar.current-item == 3) : TextEditPage {} - if(side-bar.current-item == 4) : AboutPage {} - } -} \ No newline at end of file diff -r 5c58d05abae6 -r cc2204bc6109 src/db/db.lisp --- a/src/db/db.lisp Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -(in-package :demo-db) diff -r 5c58d05abae6 -r cc2204bc6109 src/package.lisp --- a/src/package.lisp Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -;; demo packages.lisp - -(defpackage :demo-core - (:use :cl)) - -(defpackage :demo-utils - (:use :demo-core) - (:export - #:source-dir - #:random-id - #:scan-dir - #:*cargo-target* - #:*rs-macros* - #:rs-defmacro - #:rs-macroexpand-1 - #:rs-macroexpand)) - -(defpackage :demo-db - (:use :demo-core)) - -(defpackage :demo-ui - (:use :demo-core) - (:export - #:on-new-window - #:start-ui)) - -(defpackage :demo - (:use #:cl #:demo-core #:demo-utils #:demo-db #:demo-ui) - (:local-nicknames - (#:bt #:bordeaux-threads))) - -(defpackage :demo-cli - (:use :demo :clingon)) - -(defpackage :demo-user - (:use :demo)) diff -r 5c58d05abae6 -r cc2204bc6109 src/tests/clients/cli.lisp --- a/src/tests/clients/cli.lisp Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -(in-package #:demo-tests) - -(def-suite* :demo.cli - :in :demo) - -(test cli.args - (is (= 2 2))) diff -r 5c58d05abae6 -r cc2204bc6109 src/tests/clients/web.lisp --- a/src/tests/clients/web.lisp Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -(in-package #:demo-tests) - -(def-suite* :demo.web - :in :demo) - -(test web.index - (is (= 2 2))) diff -r 5c58d05abae6 -r cc2204bc6109 src/tests/package.lisp --- a/src/tests/package.lisp Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -(defpackage #:demo-tests - (:use #:demo #:fiveam) - (:shadowing-import-from #:fiveam #:test) - (:export #:run-tests)) - -(in-package #:demo-tests) - -(def-suite :demo) - -(defun run-tests () - (run! :demo)) diff -r 5c58d05abae6 -r cc2204bc6109 src/tests/services/weather.lisp diff -r 5c58d05abae6 -r cc2204bc6109 src/tests/utils.lisp --- a/src/tests/utils.lisp Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -(in-package #:demo-tests) - -(def-suite* :demo.utils - :in :demo) - -(defun gen-word () - (gen-one-element "lorem" "ipsum")) - -(defun gen-text-element () - (let ((word (gen-word))) - (lambda () - (case (random 10) - (9 #\Newline) - (t (funcall word)))))) - -(defun gen-text (&key (length (gen-integer :min 1 :max 20)) - (element (gen-text-element))) - (let ((elements (gen-list :length length :elements element))) - (lambda () - (with-output-to-string (stream) - (loop for previous = nil then element - for element in (funcall elements) - do (cond ((and previous (not (eql previous #\Newline)) (not (eql element #\Newline))) - (write-char #\Space stream) - (write-string element stream)) - (t ; (and (eql previous #\Newline) (not (eql element #\Newline))) - (princ element stream)))))))) - -(defun gen-offset (&key (integer (gen-integer :min -10 :max 10))) - (lambda () - (case (random 10) - ((8 9 10) nil) - (t (funcall integer))))) - -(defun gen-margin (&key (integer (gen-integer :min 1 :max 10))) - (lambda () - (case (random 10) - ((8 9 10) nil) - (t (funcall integer))))) - -(defun gen-count (&key (integer (gen-integer :min 1 :max 10))) - (lambda () - (case (random 10) - ((8 9 10) nil) - (t (funcall integer))))) - diff -r 5c58d05abae6 -r cc2204bc6109 src/ui/ui.lisp --- a/src/ui/ui.lisp Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -(in-package :demo-ui) - -(defparameter ui-server-port 8080) -(defparameter ui-server-host "0.0.0.0") - -(defclass ui-element (clog-element) () - (:documentation "UI Element Object.")) - -(defgeneric create-ui-element (obj &key hidden class id mode) - (:documentation "Create a new ui-element as a child of OBJ.")) -(defmethod create-ui-element ((obj clog:clog-obj) - &key (class nil) - (hidden nil) - (id nil) - (mode 'auto)) - (let ((new (clog:create-div obj - :class class - :hidden hidden - :id id - :mode mode))) - (clog:set-geometry new :width 200 :height 100) - (change-class new 'ui-element))) - -(defun on-new-window (body) - "Handle new window event." - (clog:debug-mode body) - (let ((elt (clog:create-child body "

foobar

"))) - (clog:set-on-click - elt - (lambda (o) - (setf (clog:color elt) "green"))))) - -(defun start-ui () - "Start the UI." - (clog:initialize #'on-new-window - :extended-routing t - :host ui-server-host - :port ui-server-port) - (clog:open-browser)) - -(defun stop-ui () - "Stop the UI." - (clog:shutdown)) diff -r 5c58d05abae6 -r cc2204bc6109 src/utils/rs.lisp --- a/src/utils/rs.lisp Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -;;; RUST DSL - -;; So basically, this was born out of personal frustration with how -;; cbindgen and Rust macros work (they don't). Rust macros in general -;; are something of a pain in my opinion, so I thought why not just -;; generate Rust code from Lisp instead? - -(in-package :demo-utils) - -(defvar *cargo-target* #p"/Users/ellis/dev/otom8/demo/target/") -(defvar *rs-macros* nil) - -;; TODO gensyms -(defmacro rs-defmacro (name args &body body) - "Define a macro which can be used within the body of a 'with-rs' form." - `(prog1 - (defmacro ,name ,@(mapcar #`(,a1) args) ,@body) - (push ',name *rs-macros*))) - -(defun rs-mod-form (crate &optional mods pub) - "Generate a basic mod form (CRATE . [MODS] [PUB])" - `(,crate ,mods ,pub)) - -(defmacro with-rs-env (imports &body body) - "Generate an environment for use within a Rust generator macro." - `(let ((imports ,(mapcar #'rs-mod-form imports))) - (format nil "~A~&~A" imports ',body))) - -(defun rs-use (crate &optional mods pub) - "Generate a single Rust use statement." - (concatenate - 'string - (if pub "pub " "") - "use " crate "::{" - (cond - ((consp mods) - (reduce - (lambda (x y) (format nil "~A,~A" x y)) - mods)) - (t mods)) - "};")) - -(defun rs-mod (mod &optional pub) - "Generate a single Rust mod statement." - (concatenate - 'string - (if pub "pub " "") - "mod " mod ";")) - -(defun rs-imports (&rest imports) - "Generate a string of Rust 'use' statements." - (cond - ((consp imports) - (mapcar (lambda (x) (apply #'rs-use (apply #'rs-mod-form x))) imports)) - (t imports))) - -(defmacro rs-extern-c-fn (name args &optional pub unsafe no-mangle &body body) - "Generate a Rust extern 'C' fn." - `(concatenate - 'string - ,(when no-mangle (format nil "#[no_mangle]~&")) - ,(when pub "pub ") - ,(when unsafe "unsafe ") - "extern \"C\" fn " ,name "(" - ,(cond - ((consp args) (reduce (lambda (x y) (format nil "~A,~A" x y)) args)) - (t args)) - ")" "{" ,@body "}")) - -(defun rs-obj-impl (obj) - "Implement Objective for give OBJ." - (format nil "impl Objective for ~A {};" obj)) - -;; (defun rs-macroexpand-1 (form &optional env)) - -;; (defun rs-macroexpand (env &rest body) - -;;; diff -r 5c58d05abae6 -r cc2204bc6109 src/utils/utils.lisp --- a/src/utils/utils.lisp Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -(in-package :demo-utils) - -(defun mkstr (&rest args) - (with-output-to-string (s) - (dolist (a args) (princ a s)))) - -(defun symb (&rest args) - (values (intern (apply #'mkstr args)))) - -(defun random-id () - (format NIL "~8,'0x-~8,'0x" (random #xFFFFFFFF) (get-universal-time))) - -(defun scan-dir (dir filename callback) - (dolist (path (directory (merge-pathnames (merge-pathnames filename "**/") dir))) - (funcall callback path))) - -(defun sbq-reader (stream sub-char numarg) - "The anaphoric sharp-backquote reader: #`((,a1))" - (declare (ignore sub-char)) - (unless numarg (setq numarg 1)) - `(lambda ,(loop for i from 1 to numarg - collect (symb 'a i)) - ,(funcall - (get-macro-character #\`) stream nil))) - -(eval-when (:load-toplevel) - (set-dispatch-macro-character - #\# #\` #'sbq-reader)) diff -r 5c58d05abae6 -r cc2204bc6109 system-index.txt --- a/system-index.txt Thu Jun 20 22:31:58 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -demo.asd -examples/examples.asd -examples/db/xdb/xdb.asd