Skip to content

Commit

Permalink
Add tests and docs for add_newline
Browse files Browse the repository at this point in the history
  • Loading branch information
matchai committed Jul 25, 2019
1 parent 367024c commit cc774d2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
21 changes: 21 additions & 0 deletions docs/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ $ 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
add_newline = false

# Replace the "➜" symbol in the prompt with "❯"
[character] # The name of the module we are confguring is "character"
symbol = "" # The "symbol" segment is being set to "❯"
Expand All @@ -37,6 +40,24 @@ are segments within it. Every module also has a prefix and suffix that are the d
"via " "⬢" "v10.4.1" ""
```

## Prompt

This is the list of prompt-wide configuration options.

### Options

| Variable | Default | Description|
| `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
add_newline = false
```

## Battery

The `battery` module shows how charged the device's battery is and its current charging status.
Expand Down
2 changes: 1 addition & 1 deletion src/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use clap::ArgMatches;
use rayon::prelude::*;
use std::io::{self, Write};

use crate::config::Config;
use crate::context::Context;
use crate::module::Module;
use crate::modules;
use crate::config::Config;

const PROMPT_ORDER: &[&str] = &[
"battery",
Expand Down
5 changes: 3 additions & 2 deletions tests/testsuite/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ lazy_static! {
static ref EMPTY_CONFIG: PathBuf = MANIFEST_DIR.join("empty_config.toml");
}

/// Run an instance of starship
fn run_starship() -> process::Command {
/// Render the full starship prompt
pub fn render_prompt() -> process::Command {
let mut command = process::Command::new("./target/debug/starship");

command
Expand All @@ -22,6 +22,7 @@ fn run_starship() -> process::Command {
command
}

/// Render a specific starship module by name
pub fn render_module(module_name: &str) -> process::Command {
let mut command = process::Command::new("./target/debug/starship");

Expand Down
21 changes: 21 additions & 0 deletions tests/testsuite/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,24 @@ fn disabled_module() -> io::Result<()> {

Ok(())
}

#[test]
fn add_newline_configuration() -> io::Result<()> {
// Start prompt with newline
let default_output = common::render_prompt().output()?;
let actual = String::from_utf8(default_output.stdout).unwrap();
let expected = actual.trim_start();
assert_ne!(actual, expected);

// Start prompt without newline
let output = common::render_prompt()
.use_config(toml::toml! {
add_newline = false
})
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = actual.trim_start();
assert_eq!(expected, actual);

Ok(())
}

0 comments on commit cc774d2

Please sign in to comment.