mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07:00
Use "context" to contain run details (#14)
* Create "context" to contain run details * Use context in tests and benchmarks
This commit is contained in:
@@ -1,21 +1,22 @@
|
||||
use super::Segment;
|
||||
use ansi_term::Color;
|
||||
use clap::ArgMatches;
|
||||
use std::fs::{self, DirEntry};
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
use super::Segment;
|
||||
use crate::context::Context;
|
||||
|
||||
/// Creates a segment with the current Node.js version
|
||||
///
|
||||
/// Will display the Node.js version if any of the following criteria are met:
|
||||
/// - Current directory contains a `.js` file
|
||||
/// - Current directory contains a `node_modules` directory
|
||||
/// - Current directory contains a `package.json` file
|
||||
pub fn segment(current_dir: &Path, _args: &ArgMatches) -> Option<Segment> {
|
||||
pub fn segment(context: &Context) -> Option<Segment> {
|
||||
const NODE_CHAR: &str = "⬢";
|
||||
const SECTION_COLOR: Color = Color::Green;
|
||||
|
||||
let mut segment = Segment::new("node");
|
||||
let current_dir = &context.current_dir;
|
||||
let files = fs::read_dir(current_dir).unwrap();
|
||||
|
||||
// Early return if there are no JS project files
|
||||
|
||||
Reference in New Issue
Block a user