mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-12-26 11:37:32 +00:00
parent
73e6c69637
commit
1cd4f12bb4
@ -1,5 +1,12 @@
|
|||||||
# Configuration
|
# Configuration
|
||||||
|
|
||||||
|
::: tip
|
||||||
|
|
||||||
|
🔥 Configuration is currently being worked on.
|
||||||
|
Many new configuration options will be available in coming releases.
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
To get started configuring starship, create the following file: `~/.config/starship.toml`.
|
To get started configuring starship, create the following file: `~/.config/starship.toml`.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@ -7,9 +14,10 @@ mkdir -p ~/.config && touch ~/.config/starship.toml
|
|||||||
```
|
```
|
||||||
|
|
||||||
All configuration for starship is done in this [TOML](https://github.com/toml-lang/toml) file:
|
All configuration for starship is done in this [TOML](https://github.com/toml-lang/toml) file:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
# Don't print a new line at the start of the prompt
|
# Don't print a new line at the start of the prompt
|
||||||
add_newline = false
|
format = "$all"
|
||||||
|
|
||||||
# Replace the "❯" symbol in the prompt with "➜"
|
# Replace the "❯" symbol in the prompt with "➜"
|
||||||
[character] # The name of the module we are configuring is "character"
|
[character] # The name of the module we are configuring is "character"
|
||||||
@ -137,7 +145,6 @@ This is the list of prompt-wide configuration options.
|
|||||||
|
|
||||||
| Option | Default | Description |
|
| Option | Default | Description |
|
||||||
| -------------- | ------------------------------ | ----------------------------------------------------- |
|
| -------------- | ------------------------------ | ----------------------------------------------------- |
|
||||||
| `add_newline` | `true` | Add a new line before the start of the prompt. |
|
|
||||||
| `format` | [link](#default-prompt-format) | Configure the format of the prompt. |
|
| `format` | [link](#default-prompt-format) | Configure the format of the prompt. |
|
||||||
| `scan_timeout` | `30` | Timeout for starship to scan files (in milliseconds). |
|
| `scan_timeout` | `30` | Timeout for starship to scan files (in milliseconds). |
|
||||||
|
|
||||||
@ -147,7 +154,7 @@ This is the list of prompt-wide configuration options.
|
|||||||
# ~/.config/starship.toml
|
# ~/.config/starship.toml
|
||||||
|
|
||||||
# Disable the newline at the start of the prompt
|
# Disable the newline at the start of the prompt
|
||||||
add_newline = false
|
format = "$all"
|
||||||
|
|
||||||
# Use custom format
|
# Use custom format
|
||||||
format = """
|
format = """
|
||||||
@ -164,7 +171,7 @@ scan_timeout = 10
|
|||||||
The default `format` is used to define the format of the prompt, if empty or no `format` is provided. The default is as shown:
|
The default `format` is used to define the format of the prompt, if empty or no `format` is provided. The default is as shown:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
format = "$all"
|
format = "\n$all"
|
||||||
|
|
||||||
# Which is equivalent to
|
# Which is equivalent to
|
||||||
format = """
|
format = """
|
||||||
|
@ -6,7 +6,6 @@ use starship_module_config_derive::ModuleConfig;
|
|||||||
pub struct StarshipRootConfig<'a> {
|
pub struct StarshipRootConfig<'a> {
|
||||||
pub format: &'a str,
|
pub format: &'a str,
|
||||||
pub scan_timeout: u64,
|
pub scan_timeout: u64,
|
||||||
pub add_newline: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// List of default prompt order
|
// List of default prompt order
|
||||||
@ -71,9 +70,8 @@ pub const PROMPT_ORDER: &[&str] = &[
|
|||||||
impl<'a> RootModuleConfig<'a> for StarshipRootConfig<'a> {
|
impl<'a> RootModuleConfig<'a> for StarshipRootConfig<'a> {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
StarshipRootConfig {
|
StarshipRootConfig {
|
||||||
format: "$all",
|
format: "\n$all",
|
||||||
scan_timeout: 30,
|
scan_timeout: 30,
|
||||||
add_newline: true,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,36 +5,9 @@ use crate::segment::Segment;
|
|||||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
const LINE_ENDING: &str = "\n";
|
const LINE_ENDING: &str = "\n";
|
||||||
|
|
||||||
let show_newline = context.config.get_root_config().add_newline;
|
|
||||||
if !show_newline {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut module = context.new_module("line_break");
|
let mut module = context.new_module("line_break");
|
||||||
|
|
||||||
module.set_segments(vec![Segment::new(None, LINE_ENDING)]);
|
module.set_segments(vec![Segment::new(None, LINE_ENDING)]);
|
||||||
|
|
||||||
Some(module)
|
Some(module)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use crate::test::ModuleRenderer;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn add_newline_by_default() {
|
|
||||||
let expected = Some(String::from("\n"));
|
|
||||||
let actual = ModuleRenderer::new("line_break").collect();
|
|
||||||
assert_eq!(expected, actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn dont_add_newline_when_disabled() {
|
|
||||||
let expected = None;
|
|
||||||
let config = toml::toml! {
|
|
||||||
add_newline = false
|
|
||||||
};
|
|
||||||
let actual = ModuleRenderer::new("line_break").config(config).collect();
|
|
||||||
assert_eq!(expected, actual);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user