mirror of
https://github.com/starship/starship.git
synced 2025-01-11 17:08:16 +01:00
Add stringify_segment rustdoc
This commit is contained in:
parent
472b66894d
commit
c79cbe63b1
@ -4,9 +4,9 @@ extern crate test;
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use clap::{App, Arg};
|
||||||
use starship::{modules, print};
|
use starship::{modules, print};
|
||||||
use test::Bencher;
|
use test::Bencher;
|
||||||
use clap::{App, Arg};
|
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn full_prompt_bench(b: &mut Bencher) {
|
fn full_prompt_bench(b: &mut Bencher) {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use super::Segment;
|
use super::Segment;
|
||||||
use dirs;
|
|
||||||
use std::env;
|
|
||||||
use ansi_term::{Color, Style};
|
use ansi_term::{Color, Style};
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
|
use dirs;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
/// Creates a segment with the current directory
|
/// Creates a segment with the current directory
|
||||||
pub fn segment(_: &ArgMatches) -> Segment {
|
pub fn segment(_: &ArgMatches) -> Segment {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
mod char;
|
mod character;
|
||||||
mod directory;
|
mod directory;
|
||||||
mod line_break;
|
mod line_break;
|
||||||
|
|
||||||
use clap::ArgMatches;
|
|
||||||
use ansi_term::Style;
|
use ansi_term::Style;
|
||||||
|
use clap::ArgMatches;
|
||||||
|
|
||||||
pub struct Segment {
|
pub struct Segment {
|
||||||
pub style: Style,
|
pub style: Style,
|
||||||
@ -18,21 +18,21 @@ impl Default for Segment {
|
|||||||
style: Style::default(),
|
style: Style::default(),
|
||||||
value: String::from(" "),
|
value: String::from(" "),
|
||||||
prefix: None,
|
prefix: None,
|
||||||
suffix: None
|
suffix: None,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Segment {
|
Segment {
|
||||||
style: Style::default(),
|
style: Style::default(),
|
||||||
value: String::from(""),
|
value: String::from(""),
|
||||||
prefix: None,
|
prefix: None,
|
||||||
suffix: default_suffix
|
suffix: default_suffix,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle(module: &str, args: &ArgMatches) -> Segment {
|
pub fn handle(module: &str, args: &ArgMatches) -> Segment {
|
||||||
match module {
|
match module {
|
||||||
"char" | "character" => char::segment(&args),
|
"char" | "character" => character::segment(&args),
|
||||||
"dir" | "directory" => directory::segment(&args),
|
"dir" | "directory" => directory::segment(&args),
|
||||||
"line_break" => line_break::segment(&args),
|
"line_break" => line_break::segment(&args),
|
||||||
|
|
||||||
|
20
src/print.rs
20
src/print.rs
@ -5,12 +5,30 @@ use clap::ArgMatches;
|
|||||||
pub fn prompt(args: ArgMatches) {
|
pub fn prompt(args: ArgMatches) {
|
||||||
let default_prompt = vec!["directory", "line_break", "character"];
|
let default_prompt = vec!["directory", "line_break", "character"];
|
||||||
|
|
||||||
default_prompt.into_iter()
|
default_prompt
|
||||||
|
.into_iter()
|
||||||
.map(|module| modules::handle(module, &args))
|
.map(|module| modules::handle(module, &args))
|
||||||
.map(|segment| stringify_segment(segment))
|
.map(|segment| stringify_segment(segment))
|
||||||
.for_each(|segment_string| print!("{}", segment_string));
|
.for_each(|segment_string| print!("{}", segment_string));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a string with the formatted contents of a segment
|
||||||
|
///
|
||||||
|
/// Will recursively also format the prefix and suffix of the segment being
|
||||||
|
/// stringified.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
/// ```
|
||||||
|
/// use starship::modules::Segment;
|
||||||
|
///
|
||||||
|
/// let segment = Segment {
|
||||||
|
/// value: String::from("->"),
|
||||||
|
/// ..Default::default()
|
||||||
|
/// };
|
||||||
|
///
|
||||||
|
/// let result = starship::print::stringify_segment(segment);
|
||||||
|
/// assert_eq!(result, "-> ");
|
||||||
|
/// ```
|
||||||
pub fn stringify_segment(segment: Segment) -> String {
|
pub fn stringify_segment(segment: Segment) -> String {
|
||||||
let Segment {
|
let Segment {
|
||||||
prefix,
|
prefix,
|
||||||
|
Loading…
Reference in New Issue
Block a user