mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-28 15:56:28 +00:00
refactor: Refactor Go module to the new module config (#525)
This commit is contained in:
parent
8f6b0e8710
commit
cc68dec795
23
src/configs/go.rs
Normal file
23
src/configs/go.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig};
|
||||||
|
|
||||||
|
use ansi_term::{Color, Style};
|
||||||
|
use starship_module_config_derive::ModuleConfig;
|
||||||
|
|
||||||
|
#[derive(Clone, ModuleConfig)]
|
||||||
|
pub struct GoConfig<'a> {
|
||||||
|
pub symbol: SegmentConfig<'a>,
|
||||||
|
pub version: SegmentConfig<'a>,
|
||||||
|
pub style: Style,
|
||||||
|
pub disabled: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> RootModuleConfig<'a> for GoConfig<'a> {
|
||||||
|
fn new() -> Self {
|
||||||
|
GoConfig {
|
||||||
|
symbol: SegmentConfig::new("🐹 "),
|
||||||
|
version: SegmentConfig::default(),
|
||||||
|
style: Color::Cyan.bold(),
|
||||||
|
disabled: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ pub mod battery;
|
|||||||
pub mod character;
|
pub mod character;
|
||||||
pub mod conda;
|
pub mod conda;
|
||||||
pub mod dotnet;
|
pub mod dotnet;
|
||||||
|
pub mod go;
|
||||||
pub mod hostname;
|
pub mod hostname;
|
||||||
pub mod jobs;
|
pub mod jobs;
|
||||||
pub mod kubernetes;
|
pub mod kubernetes;
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
use ansi_term::Color;
|
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
use super::{Context, Module};
|
use super::{Context, Module, RootModuleConfig};
|
||||||
|
|
||||||
|
use crate::configs::go::GoConfig;
|
||||||
|
|
||||||
/// Creates a module with the current Go version
|
/// Creates a module with the current Go version
|
||||||
///
|
///
|
||||||
@ -27,17 +28,14 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
|
|
||||||
match get_go_version() {
|
match get_go_version() {
|
||||||
Some(go_version) => {
|
Some(go_version) => {
|
||||||
const GO_CHAR: &str = "🐹 ";
|
|
||||||
|
|
||||||
let mut module = context.new_module("golang");
|
let mut module = context.new_module("golang");
|
||||||
let module_style = module
|
let config: GoConfig = GoConfig::try_load(module.config);
|
||||||
.config_value_style("style")
|
|
||||||
.unwrap_or_else(|| Color::Cyan.bold());
|
module.set_style(config.style);
|
||||||
module.set_style(module_style);
|
module.create_segment("symbol", &config.symbol);
|
||||||
|
|
||||||
let formatted_version = format_go_version(&go_version)?;
|
let formatted_version = format_go_version(&go_version)?;
|
||||||
module.new_segment("symbol", GO_CHAR);
|
module.create_segment("version", &config.version.with_value(&formatted_version));
|
||||||
module.new_segment("version", &formatted_version);
|
|
||||||
|
|
||||||
Some(module)
|
Some(module)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user