Skip to content

Commit

Permalink
feat(fossil_metrics): add fossil_metrics module (#4874)
Browse files Browse the repository at this point in the history
* feat(fossil_metrics): add fossil_metrics module

* Return early if not in a Fossil check-out

* Add more tests for fossil_metrics

* Move is in Fossil checkout check after module enabled check

* Update type for new toml version

* Update the config file schema

* Rework parsing of fossil diff output

* Fix Fossil check-out detection in subdirectories

* Use regex to only match expected fossil diff output

* Use shared ancestor scanning and fix detection on Windows

* Add note on minimum Fossil version
  • Loading branch information
VegardSkui committed Sep 2, 2023
1 parent 91d9053 commit e867cda
Show file tree
Hide file tree
Showing 9 changed files with 415 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/config-schema.json
Expand Up @@ -520,6 +520,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": {
"detect_env_vars": [],
Expand Down Expand Up @@ -3068,6 +3082,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
Expand Up @@ -266,6 +266,7 @@ $kubernetes\
$directory\
$vcsh\
$fossil_branch\
$fossil_metrics\
$git_branch\
$git_commit\
$git_state\
Expand Down Expand Up @@ -1604,6 +1605,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. At least v2.14 (2021-01-20) of Fossil is required.

### 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
@@ -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
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 @@ -159,6 +160,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
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
Expand Up @@ -35,6 +35,7 @@ pub const ALL_MODULES: &[&str] = &[
"fennel",
"fill",
"fossil_branch",
"fossil_metrics",
"gcloud",
"git_branch",
"git_commit",
Expand Down

0 comments on commit e867cda

Please sign in to comment.