netget-tool 0.3.4

Network protocol stubbing toolkit: ~280 protocol servers and clients whose responses come from an LLM, a script, a static rule or a person.
Documentation
//! Core types for the display module

use serde::{Deserialize, Serialize};

/// RGBA color with 8-bit channels
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct Color {
    pub r: u8,
    pub g: u8,
    pub b: u8,
    pub a: u8,
}

impl Color {
    /// Create RGB color with full opacity
    pub const fn rgb(r: u8, g: u8, b: u8) -> Self {
        Self { r, g, b, a: 255 }
    }

    /// Create RGBA color with alpha channel
    pub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self {
        Self { r, g, b, a }
    }

    /// Black color
    pub const BLACK: Color = Color::rgb(0, 0, 0);

    /// White color
    pub const WHITE: Color = Color::rgb(255, 255, 255);

    /// Red color
    pub const RED: Color = Color::rgb(255, 0, 0);

    /// Green color
    pub const GREEN: Color = Color::rgb(0, 255, 0);

    /// Blue color
    pub const BLUE: Color = Color::rgb(0, 0, 255);

    /// Gray color
    pub const GRAY: Color = Color::rgb(128, 128, 128);

    /// Light gray color
    pub const LIGHT_GRAY: Color = Color::rgb(192, 192, 192);

    /// Dark gray color
    pub const DARK_GRAY: Color = Color::rgb(64, 64, 64);
}

/// 2D point
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct Point {
    pub x: u32,
    pub y: u32,
}

impl Point {
    pub const fn new(x: u32, y: u32) -> Self {
        Self { x, y }
    }
}

/// Rectangle defined by position and size
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct Rect {
    pub x: u32,
    pub y: u32,
    pub width: u32,
    pub height: u32,
}

impl Rect {
    pub const fn new(x: u32, y: u32, width: u32, height: u32) -> Self {
        Self {
            x,
            y,
            width,
            height,
        }
    }
}

/// Drawing commands that can be generated by LLM and rendered by the canvas
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DisplayCommand {
    /// Render ASCII art as monospace text
    RenderAsciiArt {
        text: String,
        font_size: u32,
        fg_color: Color,
        bg_color: Color,
    },

    /// Draw a filled or outlined rectangle
    DrawRectangle {
        x: u32,
        y: u32,
        width: u32,
        height: u32,
        color: Color,
        filled: bool,
    },

    /// Draw text at a position
    DrawText {
        x: u32,
        y: u32,
        text: String,
        font_size: u32,
        color: Color,
    },

    /// Draw a line between two points
    DrawLine {
        x1: u32,
        y1: u32,
        x2: u32,
        y2: u32,
        color: Color,
        width: u32,
    },

    /// Draw a filled or outlined circle
    DrawCircle {
        x: u32,
        y: u32,
        radius: u32,
        color: Color,
        filled: bool,
    },

    /// Draw a window with title and content
    DrawWindow {
        x: u32,
        y: u32,
        width: u32,
        height: u32,
        title: String,
        content: Vec<DisplayCommand>,
    },

    /// Draw a button
    DrawButton {
        x: u32,
        y: u32,
        width: u32,
        height: u32,
        label: String,
    },

    /// Draw a text input box
    DrawTextBox {
        x: u32,
        y: u32,
        width: u32,
        height: u32,
        text: String,
        placeholder: Option<String>,
    },

    /// Set background color
    SetBackground { color: Color },

    /// Clear the canvas
    Clear,
}