Files
starship/src/modules/character.rs
T
Matan Kushner 8239fbd12b Refactor integration tests (#71)
- Create subcommands to be able to print modules independently
	- `starship prompt` will print the full prompt
	- `starship module <MODULE_NAME>` will print a specific module
		e.g. `starship module python`
	- Added `--path` flag to print the prompt or modules without being in a specific directory
	- Added `--status` flag to provide the status of the last command, instead of requiring it as an argument
- Refactored integration tests to be end-to-end tests, since there was no way in integration tests to set the environment variables for a specific command, which was required for the `username` module
- Moved e2e tests to `tests/testsuite` to allow for a single binary to be built
	- Tests will build/run faster
	- No more false positives for unused functions
- Added tests for `username`
- Removed codecov + tarpaulin 😢
2019-06-06 13:18:00 +01:00

31 lines
1004 B
Rust

use super::{Context, Module};
use ansi_term::Color;
/// Creates a segment for the prompt character
///
/// The char segment prints an arrow character in a color dependant on the exit-
/// code of the last executed command:
/// - If the exit-code was "0", the arrow will be formatted with `COLOR_SUCCESS`
/// (green by default)
/// - If the exit-code was anything else, the arrow will be formatted with
/// `COLOR_FAILURE` (red by default)
pub fn segment(context: &Context) -> Option<Module> {
const PROMPT_CHAR: &str = "";
let color_success = Color::Green.bold();
let color_failure = Color::Red.bold();
let mut module = Module::new("char");
module.get_prefix().set_value("");
let symbol = module.new_segment("symbol", PROMPT_CHAR);
let arguments = &context.arguments;
if arguments.value_of("status_code").unwrap_or("0") == "0" {
symbol.set_style(color_success.bold());
} else {
symbol.set_style(color_failure.bold());
};
Some(module)
}