aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
authorMr. E2022-07-18 00:57:01 +0000
committerGitHub2022-07-18 00:57:01 +0000
commitdbf68e0370981dc4ad0fa74596b57347f7048fab (patch)
treef0b04c445708158827b611ce602235bb5ff72142 /helix-view/src
parent43761d426cb0c508bfcea93c4bf1d08949e6c7c1 (diff)
Customizable/configurable status line (#2434)
* feat(statusline): add the file type (language id) to the status line * refactor(statusline): move the statusline implementation into an own struct * refactor(statusline): split the statusline implementation into different functions * refactor(statusline): Append elements using a consistent API This is a preparation for the configurability which is about to be implemented. * refactor(statusline): implement render_diagnostics() This avoid cluttering the render() function and will simplify configurability. * feat(statusline): make the status line configurable * refactor(statusline): make clippy happy * refactor(statusline): avoid intermediate StatusLineObject Use a more functional approach to obtain render functions and write to the buffers, and avoid an intermediate StatusLineElement object. * fix(statusline): avoid rendering the left elements twice * refactor(statusline): make clippy happy again * refactor(statusline): rename `buffer` into `parts` * refactor(statusline): ensure the match is exhaustive * fix(statusline): avoid an overflow when calculating the maximal center width * chore(statusline): Describe the statusline configurability in the book * chore(statusline): Correct and add documentation * refactor(statusline): refactor some code following the code review Avoid very small helper functions for the diagnositcs and inline them instead. Rename the config field `status_line` to `statusline` to remain consistent with `bufferline`. * chore(statusline): adjust documentation following the config field refactoring * revert(statusline): revert regression introduced by c0a1870 * chore(statusline): slight adjustment in the configuration documentation * feat(statusline): integrate changes from #2676 after rebasing * refactor(statusline): remove the StatusLine struct Because none of the functions need `Self` and all of them are in an own file, there is no explicit need for the struct. * fix(statusline): restore the configurability of color modes The configuration was ignored after reintegrating the changes of #2676 in 8d28f95. * fix(statusline): remove the spinner padding * refactor(statusline): remove unnecessary format!()
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/editor.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index a2943af9..51c0eee0 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -147,6 +147,8 @@ pub struct Config {
/// Whether to display infoboxes. Defaults to true.
pub auto_info: bool,
pub file_picker: FilePickerConfig,
+ /// Configuration of the statusline elements
+ pub statusline: StatusLineConfig,
/// Shape for cursor in each mode
pub cursor_shape: CursorShapeConfig,
/// Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative. Defaults to `false`.
@@ -180,6 +182,54 @@ pub struct SearchConfig {
pub wrap_around: bool,
}
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
+pub struct StatusLineConfig {
+ pub left: Vec<StatusLineElement>,
+ pub center: Vec<StatusLineElement>,
+ pub right: Vec<StatusLineElement>,
+}
+
+impl Default for StatusLineConfig {
+ fn default() -> Self {
+ use StatusLineElement as E;
+
+ Self {
+ left: vec![E::Mode, E::Spinner, E::FileName],
+ center: vec![],
+ right: vec![E::Diagnostics, E::Selections, E::Position, E::FileEncoding],
+ }
+ }
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case")]
+pub enum StatusLineElement {
+ /// The editor mode (Normal, Insert, Visual/Selection)
+ Mode,
+
+ /// The LSP activity spinner
+ Spinner,
+
+ /// The file nane/path, including a dirty flag if it's unsaved
+ FileName,
+
+ /// The file encoding
+ FileEncoding,
+
+ /// The file type (language ID or "text")
+ FileType,
+
+ /// A summary of the number of errors and warnings
+ Diagnostics,
+
+ /// The number of selections (cursors)
+ Selections,
+
+ /// The cursor position
+ Position,
+}
+
// Cursor shape is read and used on every rendered frame and so needs
// to be fast. Therefore we avoid a hashmap and use an enum indexed array.
#[derive(Debug, Clone, PartialEq)]
@@ -409,6 +459,7 @@ impl Default for Config {
completion_trigger_len: 2,
auto_info: true,
file_picker: FilePickerConfig::default(),
+ statusline: StatusLineConfig::default(),
cursor_shape: CursorShapeConfig::default(),
true_color: false,
search: SearchConfig::default(),