From 1661e4b5e1d8ebfef28f798fcb86ba2656373ba0 Mon Sep 17 00:00:00 2001 From: Dimitar Gyurov Date: Fri, 10 Mar 2023 23:42:42 +0100 Subject: [PATCH] Add a version-control statusline element (#5682) --- Cargo.lock | 1 + book/src/configuration.md | 1 + helix-term/src/ui/statusline.rs | 14 ++++++++++++++ helix-vcs/Cargo.toml | 1 + helix-vcs/src/git.rs | 17 +++++++++++++++++ helix-vcs/src/lib.rs | 14 +++++++++++++- helix-view/src/document.rs | 16 ++++++++++++++++ helix-view/src/editor.rs | 4 ++++ 8 files changed, 67 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index a1a9eae4d..de985bca1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1212,6 +1212,7 @@ dependencies = [ name = "helix-vcs" version = "0.6.0" dependencies = [ + "arc-swap", "gix", "helix-core", "imara-diff", diff --git a/book/src/configuration.md b/book/src/configuration.md index 4b62ca521..e698646bc 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -111,6 +111,7 @@ The following statusline elements can be configured: | `position-percentage` | The cursor position as a percentage of the total number of lines | | `separator` | The string defined in `editor.statusline.separator` (defaults to `"│"`) | | `spacer` | Inserts a space between elements (multiple/contiguous spacers may be specified) | +| `version-control` | The current branch name or detached commit hash of the opened workspace | ### `[editor.lsp]` Section diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs index 3e7065b82..887863519 100644 --- a/helix-term/src/ui/statusline.rs +++ b/helix-term/src/ui/statusline.rs @@ -159,6 +159,7 @@ where helix_view::editor::StatusLineElement::TotalLineNumbers => render_total_line_numbers, helix_view::editor::StatusLineElement::Separator => render_separator, helix_view::editor::StatusLineElement::Spacer => render_spacer, + helix_view::editor::StatusLineElement::VersionControl => render_version_control, } } @@ -476,3 +477,16 @@ where { write(context, String::from(" "), None); } + +fn render_version_control(context: &mut RenderContext, write: F) +where + F: Fn(&mut RenderContext, String, Option