Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pijul_channel module #4765

Merged
merged 14 commits into from Dec 31, 2022
46 changes: 46 additions & 0 deletions .github/config-schema.json
Expand Up @@ -1213,6 +1213,21 @@
}
]
},
"pijul_channel": {
"default": {
"disabled": true,
"format": "on [$symbol$channel]($style) ",
"style": "bold purple",
"symbol": " ",
"truncation_length": 9223372036854775807,
"truncation_symbol": "…"
},
"allOf": [
{
"$ref": "#/definitions/PijulConfig"
}
]
},
"pulumi": {
"default": {
"disabled": false,
Expand Down Expand Up @@ -4481,6 +4496,37 @@
},
"additionalProperties": false
},
"PijulConfig": {
"type": "object",
"properties": {
"symbol": {
"default": " ",
"type": "string"
},
"style": {
"default": "bold purple",
"type": "string"
},
"format": {
"default": "on [$symbol$channel]($style) ",
"type": "string"
},
"truncation_length": {
"default": 9223372036854775807,
"type": "integer",
"format": "int64"
},
"truncation_symbol": {
"default": "…",
"type": "string"
},
"disabled": {
"default": true,
"type": "boolean"
}
},
"additionalProperties": false
},
"PulumiConfig": {
"type": "object",
"properties": {
Expand Down
3 changes: 3 additions & 0 deletions docs/.vuepress/public/presets/toml/bracketed-segments.toml
Expand Up @@ -130,6 +130,9 @@ format = '\[[$symbol($version)]($style)\]'
[php]
format = '\[[$symbol($version)]($style)\]'

[pijul_channel]
format = '\[[$symbol$channel]($style)\]'

[pulumi]
format = '\[[$symbol$stack]($style)\]'

Expand Down
3 changes: 3 additions & 0 deletions docs/.vuepress/public/presets/toml/nerd-font-symbols.toml
Expand Up @@ -108,6 +108,9 @@ Windows = " "
[package]
symbol = ""

[pijul_channel]
symbol = "🪺 "

[python]
symbol = ""

Expand Down
3 changes: 3 additions & 0 deletions docs/.vuepress/public/presets/toml/plain-text-symbols.toml
Expand Up @@ -156,6 +156,9 @@ symbol = "pl "
[php]
symbol = "php "

[pijul_channel]
symbol = "pijul "

[pulumi]
symbol = "pulumi "

Expand Down
16 changes: 16 additions & 0 deletions docs/config/README.md
Expand Up @@ -271,6 +271,7 @@ $git_state\
$git_metrics\
$git_status\
$hg_branch\
$pijul_channel\
$docker_context\
$package\
$c\
Expand Down Expand Up @@ -3162,6 +3163,21 @@ By default the module will be shown if any of the following conditions are met:
format = 'via [🔹 $version](147 bold) '
```

## Pijul Channel

The `pijul_channel` module shows the active channel of the repo in your current directory.

### Options

| Option | Default | Description |
| ------------------- | --------------------------------- | ------------------------------------------------------------------------------------ |
| `symbol` | `' '` | The symbol used before the pijul channel name of the repo in your current directory. |
| `style` | `'bold purple'` | The style for the module. |
| `format` | `'on [$symbol$channel]($style) '` | The format for the module. |
| `truncation_length` | `2^63 - 1` | Truncates the pijul channel name to `N` graphemes |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more compatible with 32-bit systems:

Suggested change
| `truncation_length` | `2^63 - 1` | Truncates the pijul channel name to `N` graphemes |
| `truncation_length` | `2^32 - 1` | Truncates the pijul channel name to `N` graphemes |

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both git_branch and hg_branch take i64 for truncation_length. While I agree that this is an easy change for 32-bit compatibility, I think consistency is more important. All of the modules that use truncation need to be using usize instead of i64.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way, I feel like an unsigned integer type should be preferred and meson also uses u32.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but let's do a follow-up change to handle all of the affected modules, instead of just polishing this one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've avoided doing this, because it could be a breaking change. If for instance they are switched to u32 the former default would be outside the accepted value range, and negative values would lead to errors instead of warnings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the risk of causing XKCD 1172, I doubt anything would actually break. Defaults shouldn't be stored in any TOML files, and anyone who actually sets truncation_length for any module is most likely to set it less than 200. As for handling negative values, I wonder if there's a way to adjust the deserializer to emit warnings with defaults instead of hard errors. Possibly we could make the default 0 instead of INT_MAX, as at these sizes, there's no practical difference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some people will have based their config-file on starship print-config --default, it was even recommended in the docs for a few weeks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof. That does make a mess of things then.

| `truncation_symbol` | `'…'` | The symbol used to indicate a branch name was truncated. |
| `disabled` | `true` | Disables the `pijul` module. |

## Pulumi

The `pulumi` module shows the current username, selected [Pulumi Stack](https://www.pulumi.com/docs/intro/concepts/stack/), and version.
Expand Down
3 changes: 3 additions & 0 deletions src/configs/mod.rs
Expand Up @@ -61,6 +61,7 @@ pub mod os;
pub mod package;
pub mod perl;
pub mod php;
pub mod pijul_channel;
pub mod pulumi;
pub mod purescript;
pub mod python;
Expand Down Expand Up @@ -221,6 +222,8 @@ pub struct FullConfig<'a> {
#[serde(borrow)]
php: php::PhpConfig<'a>,
#[serde(borrow)]
pijul_channel: pijul_channel::PijulConfig<'a>,
#[serde(borrow)]
pulumi: pulumi::PulumiConfig<'a>,
#[serde(borrow)]
purescript: purescript::PureScriptConfig<'a>,
Expand Down
30 changes: 30 additions & 0 deletions src/configs/pijul_channel.rs
@@ -0,0 +1,30 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(default)]
pub struct PijulConfig<'a> {
pub symbol: &'a str,
pub style: &'a str,
pub format: &'a str,
pub truncation_length: i64,
pub truncation_symbol: &'a str,
pub disabled: bool,
}

impl<'a> Default for PijulConfig<'a> {
fn default() -> Self {
PijulConfig {
symbol: " ",
style: "bold purple",
format: "on [$symbol$channel]($style) ",
truncation_length: std::i64::MAX,
truncation_symbol: "…",
disabled: true,
}
}
}
1 change: 1 addition & 0 deletions src/configs/starship_root.rs
Expand Up @@ -42,6 +42,7 @@ pub const PROMPT_ORDER: &[&str] = &[
"git_metrics",
"git_status",
"hg_branch",
"pijul_channel",
"docker_context",
"package",
// ↓ Toolchain version modules ↓
Expand Down
1 change: 1 addition & 0 deletions src/module.rs
Expand Up @@ -69,6 +69,7 @@ pub const ALL_MODULES: &[&str] = &[
"package",
"perl",
"php",
"pijul_channel",
"pulumi",
"purescript",
"python",
Expand Down
3 changes: 3 additions & 0 deletions src/modules/mod.rs
Expand Up @@ -58,6 +58,7 @@ mod os;
mod package;
mod perl;
mod php;
mod pijul_channel;
mod pulumi;
mod purescript;
mod python;
Expand Down Expand Up @@ -159,6 +160,7 @@ pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> {
"package" => package::module(context),
"perl" => perl::module(context),
"php" => php::module(context),
"pijul_channel" => pijul_channel::module(context),
"pulumi" => pulumi::module(context),
"purescript" => purescript::module(context),
"python" => python::module(context),
Expand Down Expand Up @@ -273,6 +275,7 @@ pub fn description(module: &str) -> &'static str {
"package" => "The package version of the current directory's project",
"perl" => "The currently installed version of Perl",
"php" => "The currently installed version of PHP",
"pijul_channel" => "The current channel of the repo in the current directory",
"pulumi" => "The current username, stack, and installed version of Pulumi",
"purescript" => "The currently installed version of PureScript",
"python" => "The currently installed version of Python",
Expand Down