pub struct FastApiTheme {Show 23 fields
pub primary: Color,
pub secondary: Color,
pub accent: Color,
pub success: Color,
pub warning: Color,
pub error: Color,
pub info: Color,
pub http_get: Color,
pub http_post: Color,
pub http_put: Color,
pub http_delete: Color,
pub http_patch: Color,
pub http_options: Color,
pub http_head: Color,
pub status_1xx: Color,
pub status_2xx: Color,
pub status_3xx: Color,
pub status_4xx: Color,
pub status_5xx: Color,
pub border: Color,
pub header: Color,
pub muted: Color,
pub highlight_bg: Color,
}Expand description
FastAPI-inspired color theme for console output.
Contains colors for:
- Brand identity (primary, secondary, accent)
- Semantic meaning (success, warning, error, info)
- HTTP methods (GET, POST, PUT, DELETE, etc.)
- Status codes (1xx, 2xx, 3xx, 4xx, 5xx)
- Structural elements (border, header, muted, highlight)
Fields§
§primary: ColorPrimary brand color (teal, inspired by FastAPI docs).
secondary: ColorSecondary brand color.
accent: ColorAccent color for highlights.
success: ColorSuccess indicator color (green).
warning: ColorWarning indicator color (orange/yellow).
error: ColorError indicator color (red).
info: ColorInfo indicator color (blue).
http_get: ColorGET method color (blue).
http_post: ColorPOST method color (green).
http_put: ColorPUT method color (orange).
http_delete: ColorDELETE method color (red).
http_patch: ColorPATCH method color (cyan).
http_options: ColorOPTIONS method color (gray).
http_head: ColorHEAD method color (purple).
status_1xx: Color1xx informational (gray).
status_2xx: Color2xx success (green).
status_3xx: Color3xx redirect (cyan).
status_4xx: Color4xx client error (yellow/orange).
status_5xx: Color5xx server error (red).
border: ColorBorder color for boxes/panels.
header: ColorHeader text color.
muted: ColorMuted/secondary text color.
highlight_bg: ColorBackground highlight color.
Implementations§
Source§impl FastApiTheme
impl FastApiTheme
Sourcepub fn from_preset(preset: ThemePreset) -> Self
pub fn from_preset(preset: ThemePreset) -> Self
Create a theme from a preset.
Sourcepub fn fastapi() -> Self
pub fn fastapi() -> Self
Create the default FastAPI-inspired theme.
Colors chosen to match FastAPI documentation styling and Swagger UI conventions for familiarity.
Sourcepub fn light() -> Self
pub fn light() -> Self
Create a theme optimized for light terminal backgrounds.
Uses darker, more saturated colors that maintain good contrast against white or light-colored terminal backgrounds.
Sourcepub fn accessible() -> Self
pub fn accessible() -> Self
Create a high-contrast accessible theme.
Designed to meet WCAG 2.1 Level AA contrast requirements (4.5:1 minimum). Uses bright, saturated colors for maximum visibility.
§Color Choices
- All colors have >4.5:1 contrast ratio against dark backgrounds
- Uses pure, saturated terminal colors for maximum compatibility
- Semantic colors follow universal conventions (red=error, green=success)
- Avoids colors that may be difficult for colorblind users
Sourcepub fn http_method_color(&self, method: &str) -> Color
pub fn http_method_color(&self, method: &str) -> Color
Get the color for an HTTP method.
§Example
use fastapi_output::themes::FastApiTheme;
let theme = FastApiTheme::default();
let get_color = theme.http_method_color("GET");
let post_color = theme.http_method_color("post"); // case-insensitiveSourcepub fn status_code_color(&self, code: u16) -> Color
pub fn status_code_color(&self, code: u16) -> Color
Get the color for an HTTP status code.
§Example
use fastapi_output::themes::FastApiTheme;
let theme = FastApiTheme::default();
let success_color = theme.status_code_color(200);
let error_color = theme.status_code_color(500);Sourcepub fn primary_hex(&self) -> String
pub fn primary_hex(&self) -> String
Get primary color as hex string.
Sourcepub fn success_hex(&self) -> String
pub fn success_hex(&self) -> String
Get success color as hex string.
Sourcepub fn warning_hex(&self) -> String
pub fn warning_hex(&self) -> String
Get warning color as hex string.
Sourcepub fn accent_hex(&self) -> String
pub fn accent_hex(&self) -> String
Get accent color as hex string.
Sourcepub fn http_method_hex(&self, method: &str) -> String
pub fn http_method_hex(&self, method: &str) -> String
Get color for HTTP method as hex string.
Sourcepub fn status_code_hex(&self, code: u16) -> String
pub fn status_code_hex(&self, code: u16) -> String
Get color for status code as hex string.
Trait Implementations§
Source§impl Clone for FastApiTheme
impl Clone for FastApiTheme
Source§fn clone(&self) -> FastApiTheme
fn clone(&self) -> FastApiTheme
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more