Skip to main content

FastApiTheme

Struct FastApiTheme 

Source
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: Color

Primary brand color (teal, inspired by FastAPI docs).

§secondary: Color

Secondary brand color.

§accent: Color

Accent color for highlights.

§success: Color

Success indicator color (green).

§warning: Color

Warning indicator color (orange/yellow).

§error: Color

Error indicator color (red).

§info: Color

Info indicator color (blue).

§http_get: Color

GET method color (blue).

§http_post: Color

POST method color (green).

§http_put: Color

PUT method color (orange).

§http_delete: Color

DELETE method color (red).

§http_patch: Color

PATCH method color (cyan).

§http_options: Color

OPTIONS method color (gray).

§http_head: Color

HEAD method color (purple).

§status_1xx: Color

1xx informational (gray).

§status_2xx: Color

2xx success (green).

§status_3xx: Color

3xx redirect (cyan).

§status_4xx: Color

4xx client error (yellow/orange).

§status_5xx: Color

5xx server error (red).

§border: Color

Border color for boxes/panels.

§header: Color

Header text color.

§muted: Color

Muted/secondary text color.

§highlight_bg: Color

Background highlight color.

Implementations§

Source§

impl FastApiTheme

Source

pub fn from_preset(preset: ThemePreset) -> Self

Create a theme from a preset.

Source

pub fn fastapi() -> Self

Create the default FastAPI-inspired theme.

Colors chosen to match FastAPI documentation styling and Swagger UI conventions for familiarity.

Source

pub fn neon() -> Self

Create a neon/cyberpunk theme with high contrast.

Source

pub fn minimal() -> Self

Create a minimal grayscale theme with accent colors.

Source

pub fn monokai() -> Self

Create a Monokai-inspired dark theme.

Source

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.

Source

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
Source

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-insensitive
Source

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);
Source

pub fn primary_hex(&self) -> String

Get primary color as hex string.

Source

pub fn success_hex(&self) -> String

Get success color as hex string.

Source

pub fn error_hex(&self) -> String

Get error color as hex string.

Source

pub fn warning_hex(&self) -> String

Get warning color as hex string.

Source

pub fn info_hex(&self) -> String

Get info color as hex string.

Source

pub fn accent_hex(&self) -> String

Get accent color as hex string.

Source

pub fn http_method_hex(&self, method: &str) -> String

Get color for HTTP method as hex string.

Source

pub fn status_code_hex(&self, code: u16) -> String

Get color for status code as hex string.

Trait Implementations§

Source§

impl Clone for FastApiTheme

Source§

fn clone(&self) -> FastApiTheme

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FastApiTheme

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FastApiTheme

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for FastApiTheme

Source§

fn eq(&self, other: &FastApiTheme) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for FastApiTheme

Source§

impl StructuralPartialEq for FastApiTheme

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.