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(fossil_metrics): add fossil_metrics module #4874

Merged
merged 15 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,20 @@
}
]
},
"fossil_metrics": {
"default": {
"added_style": "bold green",
"deleted_style": "bold red",
"disabled": true,
"format": "([+$added]($added_style) )([-$deleted]($deleted_style) )",
"only_nonzero_diffs": true
},
"allOf": [
{
"$ref": "#/definitions/FossilMetricsConfig"
}
]
},
"gcloud": {
"default": {
"disabled": false,
Expand Down Expand Up @@ -3027,6 +3041,32 @@
},
"additionalProperties": false
},
"FossilMetricsConfig": {
"type": "object",
"properties": {
"format": {
"default": "([+$added]($added_style) )([-$deleted]($deleted_style) )",
"type": "string"
},
"added_style": {
"default": "bold green",
"type": "string"
},
"deleted_style": {
"default": "bold red",
"type": "string"
},
"only_nonzero_diffs": {
"default": true,
"type": "boolean"
},
"disabled": {
"default": true,
"type": "boolean"
}
},
"additionalProperties": false
},
"GcloudConfig": {
"type": "object",
"properties": {
Expand Down
36 changes: 36 additions & 0 deletions docs/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ $kubernetes\
$directory\
$vcsh\
$fossil_branch\
$fossil_metrics\
$git_branch\
$git_commit\
$git_state\
Expand Down Expand Up @@ -1593,6 +1594,41 @@ truncation_length = 4
truncation_symbol = ''
```

## Fossil Metrics

The `fossil_metrics` module will show the number of added and deleted lines in the check-out in your current directory.

### Options

| Option | Default | Description |
| -------------------- | ------------------------------------------------------------ | ------------------------------------- |
| `format` | `'([+$added]($added_style) )([-$deleted]($deleted_style) )'` | The format for the module. |
| `added_style` | `'bold green'` | The style for the added count. |
| `deleted_style` | `'bold red'` | The style for the deleted count. |
| `only_nonzero_diffs` | `true` | Render status only for changed items. |
| `disabled` | `true` | Disables the `fossil_metrics` module. |

### Variables

| Variable | Example | Description |
| --------------- | ------- | ------------------------------------------- |
| added | `1` | The current number of added lines |
| deleted | `2` | The current number of deleted lines |
| added_style\* | | Mirrors the value of option `added_style` |
| deleted_style\* | | Mirrors the value of option `deleted_style` |

*: This variable can only be used as a part of a style string

### Example

```toml
# ~/.config/starship.toml

[fossil_metrics]
added_style = 'bold blue'
format = '[+$added]($added_style)/[-$deleted]($deleted_style) '
```

## Google Cloud (`gcloud`)

The `gcloud` module shows the current configuration for [`gcloud`](https://cloud.google.com/sdk/gcloud) CLI.
Expand Down
28 changes: 28 additions & 0 deletions src/configs/fossil_metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(default)]
pub struct FossilMetricsConfig<'a> {
pub format: &'a str,
pub added_style: &'a str,
pub deleted_style: &'a str,
pub only_nonzero_diffs: bool,
pub disabled: bool,
}

impl<'a> Default for FossilMetricsConfig<'a> {
fn default() -> Self {
FossilMetricsConfig {
format: "([+$added]($added_style) )([-$deleted]($deleted_style) )",
added_style: "bold green",
deleted_style: "bold red",
only_nonzero_diffs: true,
disabled: true,
}
}
}
3 changes: 3 additions & 0 deletions src/configs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub mod erlang;
pub mod fennel;
pub mod fill;
pub mod fossil_branch;
pub mod fossil_metrics;
pub mod gcloud;
pub mod git_branch;
pub mod git_commit;
Expand Down Expand Up @@ -158,6 +159,8 @@ pub struct FullConfig<'a> {
#[serde(borrow)]
fossil_branch: fossil_branch::FossilBranchConfig<'a>,
#[serde(borrow)]
fossil_metrics: fossil_metrics::FossilMetricsConfig<'a>,
#[serde(borrow)]
gcloud: gcloud::GcloudConfig<'a>,
#[serde(borrow)]
git_branch: git_branch::GitBranchConfig<'a>,
Expand Down
1 change: 1 addition & 0 deletions src/configs/starship_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub const PROMPT_ORDER: &[&str] = &[
"directory",
"vcsh",
"fossil_branch",
"fossil_metrics",
"git_branch",
"git_commit",
"git_state",
Expand Down
1 change: 1 addition & 0 deletions src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub const ALL_MODULES: &[&str] = &[
"fennel",
"fill",
"fossil_branch",
"fossil_metrics",
"gcloud",
"git_branch",
"git_commit",
Expand Down