Skip to content

Commit

Permalink
fix: re-add add_newline to root config (starship#1598)
Browse files Browse the repository at this point in the history
  • Loading branch information
matchai authored Aug 18, 2020
1 parent 8c48e0f commit 09672ee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
19 changes: 6 additions & 13 deletions docs/config/README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
# 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`.

```sh
mkdir -p ~/.config && touch ~/.config/starship.toml
```

All configuration for starship is done in this [TOML](https://github.com/toml-lang/toml) file:

```toml
# Don't print a new line at the start of the prompt
format = "$all"
add_newline = false

# Replace the "❯" symbol in the prompt with "➜"
[character] # The name of the module we are configuring is "character"
Expand Down Expand Up @@ -147,15 +139,13 @@ This is the list of prompt-wide configuration options.
| -------------- | ------------------------------ | ----------------------------------------------------- |
| `format` | [link](#default-prompt-format) | Configure the format of the prompt. |
| `scan_timeout` | `30` | Timeout for starship to scan files (in milliseconds). |
| `add_newline` | `true` | Add a new line before the start of the prompt. |

### Example

```toml
# ~/.config/starship.toml

# Disable the newline at the start of the prompt
format = "$all"

# Use custom format
format = """
[┌───────────────────>](bold green)
Expand All @@ -164,14 +154,17 @@ format = """

# Wait 10 milliseconds for starship to check files under the current directory.
scan_timeout = 10

# Disable the newline at the start of the prompt
add_newline = false
```

### Default Prompt Format

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
format = "\n$all"
format = "$all"

# Which is equivalent to
format = """
Expand Down
4 changes: 3 additions & 1 deletion src/configs/starship_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use starship_module_config_derive::ModuleConfig;
pub struct StarshipRootConfig<'a> {
pub format: &'a str,
pub scan_timeout: u64,
pub add_newline: bool,
}

// List of default prompt order
Expand Down Expand Up @@ -70,8 +71,9 @@ pub const PROMPT_ORDER: &[&str] = &[
impl<'a> RootModuleConfig<'a> for StarshipRootConfig<'a> {
fn new() -> Self {
StarshipRootConfig {
format: "\n$all",
format: "$all",
scan_timeout: 30,
add_newline: true,
}
}
}
3 changes: 3 additions & 0 deletions src/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ pub fn get_prompt(context: Context) -> String {
);

let module_strings = root_module.ansi_strings_for_shell(context.shell);
if config.add_newline {
writeln!(buf).unwrap();
}
write!(buf, "{}", ANSIStrings(&module_strings)).unwrap();

buf
Expand Down

0 comments on commit 09672ee

Please sign in to comment.