mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07:00
Refactor segments into modules (#40)
This commit is contained in:
@@ -2,8 +2,7 @@ use ansi_term::Color;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
use super::Segment;
|
||||
use crate::context::Context;
|
||||
use super::{Context, Module};
|
||||
|
||||
/// Creates a segment with the current Node.js version
|
||||
///
|
||||
@@ -11,7 +10,7 @@ use crate::context::Context;
|
||||
/// - Current directory contains a `.js` file
|
||||
/// - Current directory contains a `package.json` file
|
||||
/// - Current directory contains a `node_modules` directory
|
||||
pub fn segment(context: &Context) -> Option<Segment> {
|
||||
pub fn segment(context: &Context) -> Option<Module> {
|
||||
let is_js_project = context.dir_files.iter().any(has_js_files);
|
||||
if !is_js_project {
|
||||
return None;
|
||||
@@ -19,16 +18,17 @@ pub fn segment(context: &Context) -> Option<Segment> {
|
||||
|
||||
match get_node_version() {
|
||||
Some(node_version) => {
|
||||
const NODE_CHAR: &str = "⬢";
|
||||
const SEGMENT_COLOR: Color = Color::Green;
|
||||
const NODE_CHAR: &str = "⬢ ";
|
||||
let module_color = Color::Green.bold();
|
||||
|
||||
let mut segment = Segment::new("node");
|
||||
segment.set_style(SEGMENT_COLOR.bold());
|
||||
let mut module = Module::new("node");
|
||||
module.set_style(module_color);
|
||||
|
||||
let formatted_version = node_version.trim();
|
||||
segment.set_value(format!("{} {}", NODE_CHAR, formatted_version));
|
||||
module.new_segment("symbol", NODE_CHAR);
|
||||
module.new_segment("version", formatted_version);
|
||||
|
||||
Some(segment)
|
||||
Some(module)
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user