summaryrefslogtreecommitdiffstats
path: root/src/modules/python.rs
diff options
context:
space:
mode:
authorMatan Kushner <hello@matchai.me>2019-05-01 16:34:24 -0400
committerGitHub <noreply@github.com>2019-05-01 16:34:24 -0400
commitc6ee5c6ac16d360ab1a44d097c91fe9f98f20f85 (patch)
treee06814175f34e508fbae4de66571e3d0042786e7 /src/modules/python.rs
parentd945b03093cf130bdc702056650f7e8e8869753b (diff)
Refactor segments into modules (#40)
Diffstat (limited to 'src/modules/python.rs')
-rw-r--r--src/modules/python.rs19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/modules/python.rs b/src/modules/python.rs
index afd62690a..70625a47c 100644
--- a/src/modules/python.rs
+++ b/src/modules/python.rs
@@ -1,9 +1,9 @@
-use super::Segment;
-use crate::context::Context;
use ansi_term::Color;
use std::path::PathBuf;
use std::process::Command;
+use super::{Context, Module};
+
/// Creates a segment with the current Python version
///
/// Will display the Python version if any of the following criteria are met:
@@ -11,7 +11,7 @@ use std::process::Command;
/// - Current directory contains a `.python-version` file
/// - Current directory contains a `requirements.txt` file
/// - Current directory contains a `pyproject.toml` file
-pub fn segment(context: &Context) -> Option<Segment> {
+pub fn segment(context: &Context) -> Option<Module> {
let is_py_project = context.dir_files.iter().any(has_py_files);
if !is_py_project {
return None;
@@ -19,16 +19,17 @@ pub fn segment(context: &Context) -> Option<Segment> {
match get_python_version() {
Some(python_version) => {
- const PYTHON_CHAR: &str = "🐍";
- const SEGMENT_COLOR: Color = Color::Yellow;
+ const PYTHON_CHAR: &str = "🐍 ";
+ let module_color = Color::Yellow.bold();
- let mut segment = Segment::new("python");
- segment.set_style(SEGMENT_COLOR.bold());
+ let mut module = Module::new("python");
+ module.set_style(module_color);
let formatted_version = format_python_version(python_version);
- segment.set_value(format!("{} {}", PYTHON_CHAR, formatted_version));
+ module.new_segment("symbol", PYTHON_CHAR);
+ module.new_segment("version", formatted_version);
- Some(segment)
+ Some(module)
}
None => None,
}