Open-Source Wikis

/

Starship

/

Reference

/

Data models

starship/starship

Data models

The key Rust types you'll encounter when reading or modifying Starship's source. All types listed here are defined in src/.

Context

src/context.rs — the per-prompt request state.

pub struct Context<'a> {
    pub config: StarshipConfig,        // parsed starship.toml
    pub properties: Properties,        // CLI flags from the shell
    pub current_dir: PathBuf,
    pub logical_dir: PathBuf,
    pub dir_contents: OnceCell<DirContents>,
    pub repo: OnceLock<Result<Repo, Box<gix::discover::Error>>>,
    pub shell: Shell,
    pub target: Target,
    pub width: usize,
    pub root_config: StarshipRootConfig,
    pub env: Env<'a>,                  // env-var view (mockable)
    pub exec_cmd: ExecCmd<'a>,         // command-runner (mockable)
    pub cmd_timeout: Duration,
    pub claude_code_data: Option<ClaudeCodeData>,
    pub root_dir: tempfile::TempDir,   // only in #[cfg(test)]
    /* shared module-state slots */
}

Helpers: try_begin_scan(), get_repo(), exec_cmd(...), get_env(...), is_module_disabled_in_config(...). See Context subsystem.

Properties

src/context.rs — parsed by clap from CLI flags:

pub struct Properties {
    pub status_code: Option<String>,
    pub pipestatus: Option<Vec<String>>,
    pub terminal_width: Option<usize>,
    pub path: Option<PathBuf>,
    pub logical_path: Option<PathBuf>,
    pub cmd_duration: Option<u128>,
    pub keymap: String,
    pub jobs: i64,
    pub shell: Option<String>,
    pub config: Option<PathBuf>,
}

Shell

pub enum Shell {
    Bash, Cmd, Elvish, Fish, Ion, Nu, PowerShell,
    Tcsh, Unknown, Xonsh, Zsh,
}

Selected from $STARSHIP_SHELL. Unknown is the fallback (and what statusline mode uses, since there's no shell wrapping the output).

Target

pub enum Target {
    Main,
    Right,
    Continuation,
    Profile(String),
}

Selected by the prompt, prompt --right, prompt --continuation, and prompt --profile <name> / statusline claude-code invocations.

Module

src/module.rs — the rendering output of a single module.

pub struct Module<'a> {
    config: Option<&'a Value>,         // raw TOML for this module
    description: String,
    pub config_name: String,           // e.g. "rust", "custom.foo"
    pub segments: Vec<Segment>,        // rendered output
    pub duration: Duration,             // how long it took to render
}

Helpers:

  • set_segments(Vec<Segment>) — set output.
  • is_empty() — true if every segment is empty/value.
  • ansi_strings_for_width(width: Option<usize>) -> Vec<AnsiString>
  • get_segments() -> &Vec<Segment>

The synthetic root "module" returned by print::handle_module is stitched together from per-module results.

Segment

src/segment.rs:

pub enum Segment {
    LineTerm,
    Fill(FillSegment),                // padding to column N
    Text(TextSegment),                 // styled string
}

pub struct TextSegment {
    pub style: Option<Style>,
    pub value: String,
}

Segment::value() returns the unstyled string. Segment::ansi_string() returns the AnsiString with style applied.

Style and palettes

src/config.rsparse_style_string produces a nu_ansi_term::Style from a string like "bold red bg:#ff0". Palettes are looked up via Style::resolve_palette against the active palette = "...".

StringFormatter

src/formatter/string_formatter.rs:

pub struct StringFormatter<'a> { /* ... */ }

impl<'a> StringFormatter<'a> {
    pub fn new(format: &'a str) -> Result<Self, StringFormatterError>;
    pub fn map<T, M>(self, mapper: M) -> Self where M: Fn(&str) -> Option<Result<T, StringFormatterError>>, T: Into<String>;
    pub fn map_meta(self, mapper: impl Fn(&str, &Context) -> Option<&str>) -> Self;
    pub fn map_style(self, mapper: impl Fn(&str) -> Option<Result<String, StringFormatterError>>) -> Self;
    pub fn parse(self, default_style: Option<Style>, context: Option<&Context>) -> Result<Vec<Segment>, StringFormatterError>;
}

pub enum StringFormatterError {
    Custom(String),
    Pest(pest::error::Error<Rule>),
}

The trait VariableHolder<T> exposes get_variables() -> BTreeSet<T>, used by print::handle to learn which variables a format string references before running modules.

ClaudeCodeData

src/utils/statusline.rs — full schema in Claude Code statusline. Three modules (claude_model, claude_context, claude_cost) read this off Context.

Cli and Commands

src/main.rsclap::Parser derive types. The interesting variants:

  • Init { shell, print_full_init }
  • Prompt(Properties) (also prompt --right, prompt --continuation, prompt --profile)
  • Module { name, ... }
  • Configure { name? }
  • PrintConfig { default, name? }
  • Toggle { module, key? }
  • Preset { name?, output?, list }
  • Statusline { provider }
  • BugReport
  • Explain(Properties) and Timings(Properties)
  • Completions { shell }
  • Session { shell }
  • ConfigSchema (gated on config-schema feature)
  • TimeMachine { time }

See also

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Data models – Starship wiki | Factory