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(flutter): Add flutter module #4605

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
80 changes: 80 additions & 0 deletions .github/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,31 @@
}
]
},
"flutter": {
"default": {
"detect_extensions": [],
"detect_files": [
"pubspec.yaml",
"pubspec.yml",
"pubspec.lock"
],
"detect_folders": [
".dart_tool",
"android",
"ios"
],
"disabled": false,
"format": "via [$symbol($version )]($style)",
"style": "bold blue",
"symbol": "🇫 ",
"version_format": "v${raw}"
},
"allOf": [
{
"$ref": "#/definitions/FlutterConfig"
}
]
},
"gcloud": {
"default": {
"disabled": false,
Expand Down Expand Up @@ -2827,6 +2852,61 @@
},
"additionalProperties": false
},
"FlutterConfig": {
"type": "object",
"properties": {
"format": {
"default": "via [$symbol($version )]($style)",
"type": "string"
},
"version_format": {
"default": "v${raw}",
"type": "string"
},
"symbol": {
"default": "🇫 ",
"type": "string"
},
"style": {
"default": "bold blue",
"type": "string"
},
"disabled": {
"default": false,
"type": "boolean"
},
"detect_extensions": {
"default": [],
"type": "array",
"items": {
"type": "string"
}
},
"detect_files": {
"default": [
"pubspec.yaml",
"pubspec.yml",
"pubspec.lock"
],
"type": "array",
"items": {
"type": "string"
}
},
"detect_folders": {
"default": [
".dart_tool",
"android",
"ios"
],
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": false
},
"GcloudConfig": {
"type": "object",
"properties": {
Expand Down
3 changes: 3 additions & 0 deletions docs/.vuepress/public/presets/toml/bracketed-segments.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ format = '\[[$symbol($version)]($style)\]'
[erlang]
format = '\[[$symbol($version)]($style)\]'

[flutter]
format = '\[[$symbol($version)]($style)\]'

[gcloud]
format = '\[[$symbol$account(@$domain)(\($region\))]($style)\]'

Expand Down
3 changes: 3 additions & 0 deletions docs/.vuepress/public/presets/toml/nerd-font-symbols.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ symbol = " "
[elm]
symbol = " "

[flutter]
symbol = "F "

[git_branch]
symbol = " "

Expand Down
3 changes: 3 additions & 0 deletions docs/.vuepress/public/presets/toml/no-empty-icons.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ format = '(via [$symbol($version )]($style))'
[erlang]
format = '(via [$symbol($version )]($style))'

[flutter]
format = '(via [$symbol($version )]($style))'

[golang]
format = '(via [$symbol($version )]($style))'

Expand Down
3 changes: 3 additions & 0 deletions docs/.vuepress/public/presets/toml/no-runtime-versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ format = 'via [$symbol]($style)'
[erlang]
format = 'via [$symbol]($style)'

[flutter]
format = "via [$symbol]($style)"

[golang]
format = 'via [$symbol]($style)'

Expand Down
3 changes: 3 additions & 0 deletions docs/.vuepress/public/presets/toml/plain-text-symbols.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ symbol = "exs "
[elm]
symbol = "elm "

[flutter]
symbol = "flutter "

[git_branch]
symbol = "git "

Expand Down
40 changes: 40 additions & 0 deletions docs/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ $dotnet\
$elixir\
$elm\
$erlang\
$flutter\
$golang\
$guix_shell\
$haskell\
Expand Down Expand Up @@ -1489,6 +1490,45 @@ Produces a prompt that looks like:
AA -------------------------------------------- BB -------------------------------------------- CC
```

## Flutter

The `flutter` module shows the flutter version of the current project from .dart_tool/version.
By default the module will be shown if any of the following conditions are met:

- The current directory contains a `.dart_tool`, `ios` and `android` directory
- The current directory contains a `pubspec.yaml`, `pubspec.yml` or `pubspec.lock` file

### Options

| Option | Default | Description |
| ---------------- | ------------------------------------------------- | ------------------------------------------------------------------------- |
| `format` | `'via [$symbol($version )]($style)'` | The format for the module. |
| `version_format` | `'v${raw}'` | The version format. Available vars are `raw`, `major`, `minor`, & `patch` |
| `symbol` | `'🇫 '` | A format string representing the symbol of Dart |
| `detect_files` | `['pubspec.yaml', 'pubspec.yml', 'pubspec.lock']` | Which filenames should trigger this module. |
| `detect_folders` | `['.dart_tool', 'ios', 'android']` | Which folders should trigger this module (all must exist). |
| `style` | `'bold blue'` | The style for the module. |
| `disabled` | `false` | Disables the `dart` module. |

### Variables

| Variable | Example | Description |
| -------- | -------- | ------------------------------------ |
| version | `v3.3.8` | The version of `flutter` |
| symbol | | Mirrors the value of option `symbol` |
| style\* | | Mirrors the value of option `style` |

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

### Example

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

[flutter]
format = 'via [🔰 $version](bold red) '
```

## Google Cloud (`gcloud`)

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

#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(default)]
pub struct FlutterConfig<'a> {
pub format: &'a str,
pub version_format: &'a str,
pub symbol: &'a str,
pub style: &'a str,
pub disabled: bool,
pub detect_extensions: Vec<&'a str>,
pub detect_files: Vec<&'a str>,
pub detect_folders: Vec<&'a str>,
}

impl<'a> Default for FlutterConfig<'a> {
fn default() -> Self {
FlutterConfig {
format: "via [$symbol($version )]($style)",
version_format: "v${raw}",
symbol: "🇫 ",
style: "bold blue",
disabled: false,
detect_extensions: vec![],
detect_files: vec!["pubspec.yaml", "pubspec.yml", "pubspec.lock"],
detect_folders: vec![".dart_tool", "android", "ios"],
}
}
}
3 changes: 3 additions & 0 deletions src/configs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub mod elm;
pub mod env_var;
pub mod erlang;
pub mod fill;
pub mod flutter;
pub mod gcloud;
pub mod git_branch;
pub mod git_commit;
Expand Down Expand Up @@ -149,6 +150,8 @@ pub struct FullConfig<'a> {
#[serde(borrow)]
fill: fill::FillConfig<'a>,
#[serde(borrow)]
flutter: flutter::FlutterConfig<'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 @@ -57,6 +57,7 @@ pub const PROMPT_ORDER: &[&str] = &[
"elixir",
"elm",
"erlang",
"flutter",
"golang",
"haskell",
"helm",
Expand Down
6 changes: 6 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,12 @@ impl DirContents {
.any(|path| !path.starts_with('!') && self.has_folder(path))
}

pub fn has_all_positive_folder(&self, paths: &[&str]) -> bool {
paths
.iter()
.all(|path| !path.starts_with('!') && self.has_folder(path))
}

pub fn has_any_positive_extension(&self, exts: &[&str]) -> bool {
exts.iter()
.any(|ext| !ext.starts_with('!') && self.has_extension(ext))
Expand Down
1 change: 1 addition & 0 deletions src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub const ALL_MODULES: &[&str] = &[
"env_var",
"erlang",
"fill",
"flutter",
"gcloud",
"git_branch",
"git_commit",
Expand Down