pub struct Context { /* private fields */ }Expand description
The configuration bundle every command operates against.
Context::new performs no filesystem access. Ambient configuration
discovery is opt-in through Context::discover, so a caller that already
knows its configuration — an editor holding an unsaved buffer, say — never
has the user’s ~/.config read behind its back.
Implementations§
Source§impl Context
impl Context
Sourcepub fn new(base_path: Utf8PathBuf) -> Self
pub fn new(base_path: Utf8PathBuf) -> Self
A context with no aisle or pantry configuration. Touches nothing.
Sourcepub fn discover(base_path: Utf8PathBuf) -> Self
pub fn discover(base_path: Utf8PathBuf) -> Self
A context with aisle and pantry resolved using CookCLI’s search order:
<base>/config/<name> first, then the global configuration directory
(global_config_path — $COOK_CONFIG_DIR when set, otherwise
~/.config/cook/<name> on Linux and the platform equivalent
elsewhere).
This is the only constructor that reads ambient state, and it is explicitly opted into.
Two things to know before relying on it:
- It reports no errors. A configuration directory that cannot be
resolved at all — no home directory, or a non-UTF-8 path — is treated
as one fewer place to look, exactly as the CLI treats it. An unset
ConfigSourcetherefore does not distinguish “the user has no config file” from “this machine has no home directory”. Callglobal_config_pathdirectly if you need to tell those apart. - It stats, it does not read. Discovery only checks that each
candidate is a file; the contents are read later by
ConfigSource::read. AContextheld across an editing session can therefore name a file that has since been deleted, which surfaces as aCoreError::Iofrom whichever command reads it rather than from here. Re-rundiscoverif the configuration may have changed.
Sourcepub fn with_aisle(self, source: ConfigSource) -> Self
pub fn with_aisle(self, source: ConfigSource) -> Self
Replace the aisle configuration, whatever discovery found.
Sourcepub fn with_pantry(self, source: ConfigSource) -> Self
pub fn with_pantry(self, source: ConfigSource) -> Self
Replace the pantry configuration, whatever discovery found.
Sourcepub fn base_path(&self) -> &Utf8Path
pub fn base_path(&self) -> &Utf8Path
The directory recipe paths and searches are resolved against.
Returned exactly as it was supplied. Unlike the CLI, which canonicalises
it and rejects a non-directory before building a Context, core neither
resolves nor validates it — so a relative path is interpreted against
the process working directory, which for an in-process editor
integration is the editor’s, not the project’s. Pass an absolute path
unless you mean that.
Sourcepub fn aisle(&self) -> &ConfigSource
pub fn aisle(&self) -> &ConfigSource
The aisle configuration to categorise shopping list ingredients with.
Sourcepub fn pantry(&self) -> &ConfigSource
pub fn pantry(&self) -> &ConfigSource
The pantry configuration to filter already-stocked ingredients with.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
impl UnwindSafe for Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);