From 9688cb74a1e931edfa625cd28a828e728fcea675 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Tue, 19 Oct 2021 23:57:22 +0900 Subject: Update dependencies to bump crossterm to 0.22.1 Fixes #825 Fixes #690 --- helix-tui/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'helix-tui') diff --git a/helix-tui/Cargo.toml b/helix-tui/Cargo.toml index 80a772a4..2b42d299 100644 --- a/helix-tui/Cargo.toml +++ b/helix-tui/Cargo.toml @@ -19,7 +19,7 @@ default = ["crossterm"] bitflags = "1.3" cassowary = "0.3" unicode-segmentation = "1.8" -crossterm = { version = "0.21", optional = true } +crossterm = { version = "0.22", optional = true } serde = { version = "1", "optional" = true, features = ["derive"]} helix-view = { version = "0.4", path = "../helix-view", features = ["term"] } helix-core = { version = "0.4", path = "../helix-core" } -- cgit v1.2.3-70-g09d2 From 182a59b5528075c0171756bff71275db8a7995f0 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Fri, 22 Oct 2021 12:07:41 +0900 Subject: Update to rust 1.56 + 2021 edition --- flake.lock | 68 ++++++++++++++++++++++++++++++++++----------- flake.nix | 2 ++ helix-core/Cargo.toml | 2 +- helix-lsp/Cargo.toml | 2 +- helix-syntax/Cargo.toml | 2 +- helix-term/Cargo.toml | 2 +- helix-term/src/ui/menu.rs | 32 ++++++++++----------- helix-term/src/ui/picker.rs | 23 +++++---------- helix-tui/Cargo.toml | 2 +- helix-view/Cargo.toml | 2 +- helix-view/src/theme.rs | 1 - 11 files changed, 82 insertions(+), 56 deletions(-) (limited to 'helix-tui') diff --git a/flake.lock b/flake.lock index 21e44c6e..2029d580 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "devshell": { "locked": { - "lastModified": 1630239564, - "narHash": "sha256-lv7atkVE1+dFw0llmzONsbSIo5ao85KpNSRoFk4K8vU=", + "lastModified": 1632436039, + "narHash": "sha256-OtITeVWcKXn1SpVEnImpTGH91FycCskGBPqmlxiykv4=", "owner": "numtide", "repo": "devshell", - "rev": "bd86d3a2bb28ce4d223315e0eca0d59fef8a0a73", + "rev": "7a7a7aa0adebe5488e5abaec688fd9ae0f8ea9c6", "type": "github" }, "original": { @@ -15,6 +15,21 @@ "type": "github" } }, + "flake-utils": { + "locked": { + "lastModified": 1623875721, + "narHash": "sha256-A8BU7bjS5GirpAUv4QA+QnJ4CceLHkcXdRp4xITDB0s=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "f7e004a55b120c02ecb6219596820fcd32ca8772", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "flakeCompat": { "flake": false, "locked": { @@ -37,14 +52,16 @@ "nixpkgs": [ "nixpkgs" ], - "rustOverlay": "rustOverlay" + "rustOverlay": [ + "rust-overlay" + ] }, "locked": { - "lastModified": 1631254163, - "narHash": "sha256-8+nOGLH1fXwWnNMTQq/Igk434BzZF5Vld45xLDLiNDQ=", + "lastModified": 1634796585, + "narHash": "sha256-CW4yx6omk5qCXUIwXHp/sztA7u0SpyLq9NEACPnkiz8=", "owner": "yusdacra", "repo": "nix-cargo-integration", - "rev": "432d8504a32232e8d74710024d5bf5cc31767651", + "rev": "a84a2137a396f303978f1d48341e0390b0e16a8b", "type": "github" }, "original": { @@ -55,11 +72,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1631206977, - "narHash": "sha256-o3Dct9aJ5ht5UaTUBzXrRcK1RZt2eG5/xSlWJuUCVZM=", + "lastModified": 1634782485, + "narHash": "sha256-psfh4OQSokGXG0lpq3zKFbhOo3QfoeudRcaUnwMRkQo=", "owner": "nixos", "repo": "nixpkgs", - "rev": "4f6d8095fd51954120a1d08ea5896fe42dc3923b", + "rev": "34ad3ffe08adfca17fcb4e4a47bb5f3b113687be", "type": "github" }, "original": { @@ -69,21 +86,40 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1628186154, + "narHash": "sha256-r2d0wvywFnL9z4iptztdFMhaUIAaGzrSs7kSok0PgmE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "06552b72346632b6943c8032e57e702ea12413bf", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { "flakeCompat": "flakeCompat", "nixCargoIntegration": "nixCargoIntegration", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" } }, - "rustOverlay": { - "flake": false, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_2" + }, "locked": { - "lastModified": 1631240108, - "narHash": "sha256-ffsTkAGyQLxu4E28nVcqwc8xFL/H1UEwrRw2ITI43Aw=", + "lastModified": 1634869268, + "narHash": "sha256-RVAcEFlFU3877Mm4q/nbXGEYTDg/wQNhzmXGMTV6wBs=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "3a29d5e726b855d9463eb5dfe04f1ec14d413289", + "rev": "c02c2d86354327317546501af001886fbb53d374", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index bcc9383e..c1145268 100644 --- a/flake.nix +++ b/flake.nix @@ -3,9 +3,11 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + rust-overlay.url = "github:oxalica/rust-overlay"; nixCargoIntegration = { url = "github:yusdacra/nix-cargo-integration"; inputs.nixpkgs.follows = "nixpkgs"; + inputs.rustOverlay.follows = "rust-overlay"; }; flakeCompat = { url = "github:edolstra/flake-compat"; diff --git a/helix-core/Cargo.toml b/helix-core/Cargo.toml index 51096453..93ebb133 100644 --- a/helix-core/Cargo.toml +++ b/helix-core/Cargo.toml @@ -2,7 +2,7 @@ name = "helix-core" version = "0.4.1" authors = ["Blaž Hrastnik "] -edition = "2018" +edition = "2021" license = "MPL-2.0" description = "Helix editor core editing primitives" categories = ["editor"] diff --git a/helix-lsp/Cargo.toml b/helix-lsp/Cargo.toml index b4c8c139..455407ad 100644 --- a/helix-lsp/Cargo.toml +++ b/helix-lsp/Cargo.toml @@ -2,7 +2,7 @@ name = "helix-lsp" version = "0.4.1" authors = ["Blaž Hrastnik "] -edition = "2018" +edition = "2021" license = "MPL-2.0" description = "LSP client implementation for Helix project" categories = ["editor"] diff --git a/helix-syntax/Cargo.toml b/helix-syntax/Cargo.toml index 9c2b8275..122fa460 100644 --- a/helix-syntax/Cargo.toml +++ b/helix-syntax/Cargo.toml @@ -2,7 +2,7 @@ name = "helix-syntax" version = "0.4.1" authors = ["Blaž Hrastnik "] -edition = "2018" +edition = "2021" license = "MPL-2.0" description = "Tree-sitter grammars support" categories = ["editor"] diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml index 244d3c13..78afab01 100644 --- a/helix-term/Cargo.toml +++ b/helix-term/Cargo.toml @@ -3,7 +3,7 @@ name = "helix-term" version = "0.4.1" description = "A post-modern text editor." authors = ["Blaž Hrastnik "] -edition = "2018" +edition = "2021" license = "MPL-2.0" categories = ["editor", "command-line-utilities"] repository = "https://github.com/helix-editor/helix" diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs index 055593fd..1130089d 100644 --- a/helix-term/src/ui/menu.rs +++ b/helix-term/src/ui/menu.rs @@ -64,25 +64,23 @@ impl Menu { } pub fn score(&mut self, pattern: &str) { - // need to borrow via pattern match otherwise it complains about simultaneous borrow - let Self { - ref mut matcher, - ref mut matches, - ref options, - .. - } = *self; - // reuse the matches allocation - matches.clear(); - matches.extend(options.iter().enumerate().filter_map(|(index, option)| { - let text = option.filter_text(); - // TODO: using fuzzy_indices could give us the char idx for match highlighting - matcher - .fuzzy_match(text, pattern) - .map(|score| (index, score)) - })); + self.matches.clear(); + self.matches.extend( + self.options + .iter() + .enumerate() + .filter_map(|(index, option)| { + let text = option.filter_text(); + // TODO: using fuzzy_indices could give us the char idx for match highlighting + self.matcher + .fuzzy_match(text, pattern) + .map(|score| (index, score)) + }), + ); // matches.sort_unstable_by_key(|(_, score)| -score); - matches.sort_unstable_by_key(|(index, _score)| options[*index].sort_text()); + self.matches + .sort_unstable_by_key(|(index, _score)| self.options[*index].sort_text()); // reset cursor position self.cursor = None; diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 6f584178..1f08cf13 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -233,37 +233,28 @@ impl Picker { } pub fn score(&mut self) { - // need to borrow via pattern match otherwise it complains about simultaneous borrow - let Self { - ref mut matcher, - ref mut matches, - ref filters, - ref format_fn, - .. - } = *self; - let pattern = &self.prompt.line; // reuse the matches allocation - matches.clear(); - matches.extend( + self.matches.clear(); + self.matches.extend( self.options .iter() .enumerate() .filter_map(|(index, option)| { // filter options first before matching - if !filters.is_empty() { - filters.binary_search(&index).ok()?; + if !self.filters.is_empty() { + self.filters.binary_search(&index).ok()?; } // TODO: maybe using format_fn isn't the best idea here - let text = (format_fn)(option); + let text = (self.format_fn)(option); // TODO: using fuzzy_indices could give us the char idx for match highlighting - matcher + self.matcher .fuzzy_match(&text, pattern) .map(|score| (index, score)) }), ); - matches.sort_unstable_by_key(|(_, score)| -score); + self.matches.sort_unstable_by_key(|(_, score)| -score); // reset cursor position self.cursor = 0; diff --git a/helix-tui/Cargo.toml b/helix-tui/Cargo.toml index 2b42d299..f0c0d7e2 100644 --- a/helix-tui/Cargo.toml +++ b/helix-tui/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Blaž Hrastnik "] description = """ A library to build rich terminal user interfaces or dashboards """ -edition = "2018" +edition = "2021" license = "MPL-2.0" categories = ["editor"] repository = "https://github.com/helix-editor/helix" diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml index fce3fdd1..ef09b964 100644 --- a/helix-view/Cargo.toml +++ b/helix-view/Cargo.toml @@ -2,7 +2,7 @@ name = "helix-view" version = "0.4.1" authors = ["Blaž Hrastnik "] -edition = "2018" +edition = "2021" license = "MPL-2.0" description = "UI abstractions for use in backends" categories = ["editor"] diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index 9c33685b..757316bd 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -1,6 +1,5 @@ use std::{ collections::HashMap, - convert::TryFrom, path::{Path, PathBuf}, }; -- cgit v1.2.3-70-g09d2 From f3c7f20dbce09f516ada77f34f215d64743a34f1 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Thu, 28 Oct 2021 16:39:17 +0900 Subject: Release v0.5.0 --- CHANGELOG.md | 86 +++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.lock | 12 +++---- helix-core/Cargo.toml | 4 +-- helix-lsp/Cargo.toml | 2 +- helix-syntax/Cargo.toml | 2 +- helix-term/Cargo.toml | 8 ++--- helix-tui/Cargo.toml | 6 ++-- helix-view/Cargo.toml | 6 ++-- 8 files changed, 106 insertions(+), 20 deletions(-) (limited to 'helix-tui') diff --git a/CHANGELOG.md b/CHANGELOG.md index 03f57307..e21f3836 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,84 @@ +# 0.5.0 (2021-11-28) + +A big shout out to all the contributors! We had 46 contributors in this release. + +Helix has popped up in [Scoop, FreeBSD Ports and Gentu GURU](https://repology.org/project/helix/versions)! + +The following is a quick rundown of the larger changes, there were many more +(check the git history for more details). + +Breaking changes: + +- A couple of keymaps moved to resolve a few conflicting keybinds. + - Documentation popups were moved from `K` to `space+k` + - `K` is now `keep_selections` which filters selections to only keeps ones matching the regex + - `keep_primary_selection` moved from `space+space` to `,` + - `Alt-,` is now `remove_primary_selection` which keeps all selections except the primary one + - Opening files in a split moved from `C-h` to `C-s` +- Some configuration options moved from a `[terminal]` section to `[editor]`. [Consult the documentation for more information.](https://docs.helix-editor.com/configuration.html). + +Features: + +- LSP compatibility greatly improved for some implementations (Julia, Python, Typescript) +- Autocompletion! Completion now triggers automatically after a set idle timeout +- Completion documentation is now displayed next to the popup (#691) +- Treesitter textobjects (select a function via `mf`, class via `mc`) (#728) +- Global search across entire workspace `space+/` (#651) +- Relative line number support (#485) +- Prompts now store a history (72cf86e) +- `:vsplit` and `:hsplit` commands (#639) +- `C-w h/j/k/l` can now be used to navigate between splits (#860) +- `C-j` and `C-k` are now alternative keybindings to `C-n` and `C-p` in the UI (#876) +- Shell commands (shell-pipe, pipe-to, shell-insert-output, shell-append-output, keep-pipe) (#547) +- Searching now defaults to smart case search (case insensitive unless uppercase is used) (#761) +- The preview pane was improved to highlight and center line ranges +- The user `languages.toml` is now merged into defaults, no longer need to copy the entire file (dc57f8dc) +- Show hidden files in completions (#648) +- Grammar injections are now properly handled (dd0b15e) +- `v` in select mode now switches back to normal mode (#660) +- View mode can now be triggered as a "sticky" mode (#719) +- `f`/`t` and object selection motions can now be repeated via `Alt-.` (#891) +- Statusline now displays total selection count and diagnostics counts for both errors and warnings (#916) + +New grammars: + +- Ledger (#572) +- Protobuf (#614) +- Zig (#631) +- YAML (#667) +- Lua (#665) +- OCaml (#666) +- Svelte (#733) +- Vue (#787) +- Tree-sitter queries (#845) +- Elixir (we switched over to the official grammar) (6c0786e) +- Language server definitions for Nix and Elixir (#725) +- Python now uses `pylsp` instead of `pyls` +- Python now supports indentation + +New themes: + +- Monokai (#628) +- Everforest Dark (#760) +- Nord (#799) +- Base16 Default Dark (#833) +- Rose Pine (#897) + +Fixes: + +- Fix crash on empty rust file (#592) +- Exit select mode after toggle comment (#598) +- Pin popups with no positioning to the initial position (12ea3888) +- xsel copy should not freeze the editor (6dd7dc4) +- `*` now only sets the search register and doesn't jump to the next occurrence (3426285) +- Goto line start/end commands extend when in select mode (#739) +- Fix documentation popups sometimes not getting fully highlighted (066367c) +- Refactor apply_workspace_edit to remove assert (b02d872) +- Wrap around the top of the picker menu when scrolling (c7d6e44) +- Don't allow closing the last split if there's unsaved changes (3ff5b00) +- Indentation used different default on hx vs hx new_file.txt (c913bad) + # 0.4.1 (2021-08-14) A minor release that includes: @@ -7,6 +87,8 @@ A minor release that includes: # 0.4.0 (2021-08-13) +A big shout out to all the contributors! We had 28 contributors in this release. + Two months have passed, so this is another big release. A big thank you to all the contributors and package maintainers! @@ -44,6 +126,8 @@ selections in the future as well as resolves many bugs and edge cases. # 0.3.0 (2021-06-27) +A big shout out to all the contributors! We had 24 contributors in this release. + Another big release. Highlights: @@ -90,6 +174,8 @@ Includes a fix where wq/wqa could exit before file saving completed. # 0.2.0 +A big shout out to all the contributors! We had 18 contributors in this release. + Enough has changed to bump the version. We're skipping 0.1.x because previously the CLI would always report version as 0.1.0, and we'd like to distinguish it in bug reports.. diff --git a/Cargo.lock b/Cargo.lock index 17bc73a9..45a8f5da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -358,7 +358,7 @@ dependencies = [ [[package]] name = "helix-core" -version = "0.4.1" +version = "0.5.0" dependencies = [ "arc-swap", "etcetera", @@ -382,7 +382,7 @@ dependencies = [ [[package]] name = "helix-lsp" -version = "0.4.1" +version = "0.5.0" dependencies = [ "anyhow", "futures-executor", @@ -400,7 +400,7 @@ dependencies = [ [[package]] name = "helix-syntax" -version = "0.4.1" +version = "0.5.0" dependencies = [ "anyhow", "cc", @@ -411,7 +411,7 @@ dependencies = [ [[package]] name = "helix-term" -version = "0.4.1" +version = "0.5.0" dependencies = [ "anyhow", "chrono", @@ -441,7 +441,7 @@ dependencies = [ [[package]] name = "helix-tui" -version = "0.4.1" +version = "0.5.0" dependencies = [ "bitflags", "cassowary", @@ -454,7 +454,7 @@ dependencies = [ [[package]] name = "helix-view" -version = "0.4.1" +version = "0.5.0" dependencies = [ "anyhow", "bitflags", diff --git a/helix-core/Cargo.toml b/helix-core/Cargo.toml index 84d029d2..ea695d34 100644 --- a/helix-core/Cargo.toml +++ b/helix-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "helix-core" -version = "0.4.1" +version = "0.5.0" authors = ["Blaž Hrastnik "] edition = "2021" license = "MPL-2.0" @@ -13,7 +13,7 @@ include = ["src/**/*", "README.md"] [features] [dependencies] -helix-syntax = { version = "0.4", path = "../helix-syntax" } +helix-syntax = { version = "0.5", path = "../helix-syntax" } ropey = "1.3" smallvec = "1.7" diff --git a/helix-lsp/Cargo.toml b/helix-lsp/Cargo.toml index 455407ad..5a284c46 100644 --- a/helix-lsp/Cargo.toml +++ b/helix-lsp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "helix-lsp" -version = "0.4.1" +version = "0.5.0" authors = ["Blaž Hrastnik "] edition = "2021" license = "MPL-2.0" diff --git a/helix-syntax/Cargo.toml b/helix-syntax/Cargo.toml index 122fa460..cceec412 100644 --- a/helix-syntax/Cargo.toml +++ b/helix-syntax/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "helix-syntax" -version = "0.4.1" +version = "0.5.0" authors = ["Blaž Hrastnik "] edition = "2021" license = "MPL-2.0" diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml index cf1f44d5..2414c433 100644 --- a/helix-term/Cargo.toml +++ b/helix-term/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "helix-term" -version = "0.4.1" +version = "0.5.0" description = "A post-modern text editor." authors = ["Blaž Hrastnik "] edition = "2021" @@ -21,9 +21,9 @@ name = "hx" path = "src/main.rs" [dependencies] -helix-core = { version = "0.4", path = "../helix-core" } -helix-view = { version = "0.4", path = "../helix-view" } -helix-lsp = { version = "0.4", path = "../helix-lsp" } +helix-core = { version = "0.5", path = "../helix-core" } +helix-view = { version = "0.5", path = "../helix-view" } +helix-lsp = { version = "0.5", path = "../helix-lsp" } anyhow = "1" once_cell = "1.8" diff --git a/helix-tui/Cargo.toml b/helix-tui/Cargo.toml index f0c0d7e2..6df65d36 100644 --- a/helix-tui/Cargo.toml +++ b/helix-tui/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "helix-tui" -version = "0.4.1" +version = "0.5.0" authors = ["Blaž Hrastnik "] description = """ A library to build rich terminal user interfaces or dashboards @@ -21,5 +21,5 @@ cassowary = "0.3" unicode-segmentation = "1.8" crossterm = { version = "0.22", optional = true } serde = { version = "1", "optional" = true, features = ["derive"]} -helix-view = { version = "0.4", path = "../helix-view", features = ["term"] } -helix-core = { version = "0.4", path = "../helix-core" } +helix-view = { version = "0.5", path = "../helix-view", features = ["term"] } +helix-core = { version = "0.5", path = "../helix-core" } diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml index ef09b964..34f55eb6 100644 --- a/helix-view/Cargo.toml +++ b/helix-view/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "helix-view" -version = "0.4.1" +version = "0.5.0" authors = ["Blaž Hrastnik "] edition = "2021" license = "MPL-2.0" @@ -16,8 +16,8 @@ term = ["crossterm"] [dependencies] bitflags = "1.3" anyhow = "1" -helix-core = { version = "0.4", path = "../helix-core" } -helix-lsp = { version = "0.4", path = "../helix-lsp"} +helix-core = { version = "0.5", path = "../helix-core" } +helix-lsp = { version = "0.5", path = "../helix-lsp"} crossterm = { version = "0.22", optional = true } # Conversion traits -- cgit v1.2.3-70-g09d2 From 5b5d1b9dfff6b522559174f7f8e99aeb82c674a9 Mon Sep 17 00:00:00 2001 From: Omnikar Date: Wed, 3 Nov 2021 23:24:05 -0400 Subject: Truncate the starts of file paths instead of the ends in picker (#951) * Truncate the starts of file paths in picker * Simplify the truncate implementation * Break loop at appropriate point * Fix alignment and ellipsis presence * Remove extraneous usage of `x_offset` Co-authored-by: Blaž Hrastnik --- helix-term/src/ui/picker.rs | 1 + helix-tui/src/buffer.rs | 78 ++++++++++++++++++++++++++++++++------------- 2 files changed, 57 insertions(+), 22 deletions(-) (limited to 'helix-tui') diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 7e257c0b..7fc6af0f 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -483,6 +483,7 @@ impl Component for Picker { text_style }, true, + true, ); } } diff --git a/helix-tui/src/buffer.rs b/helix-tui/src/buffer.rs index 377e3e39..f480bc2f 100644 --- a/helix-tui/src/buffer.rs +++ b/helix-tui/src/buffer.rs @@ -266,12 +266,14 @@ impl Buffer { where S: AsRef, { - self.set_string_truncated(x, y, string, width, style, false) + self.set_string_truncated(x, y, string, width, style, false, false) } /// Print at most the first `width` characters of a string if enough space is available - /// until the end of the line. If `markend` is true appends a `…` at the end of - /// truncated lines. + /// until the end of the line. If `ellipsis` is true appends a `…` at the end of + /// truncated lines. If `truncate_start` is `true`, truncate the beginning of the string + /// instead of the end. + #[allow(clippy::too_many_arguments)] pub fn set_string_truncated( &mut self, x: u16, @@ -280,6 +282,7 @@ impl Buffer { width: usize, style: Style, ellipsis: bool, + truncate_start: bool, ) -> (u16, u16) where S: AsRef, @@ -289,28 +292,59 @@ impl Buffer { let width = if ellipsis { width - 1 } else { width }; let graphemes = UnicodeSegmentation::graphemes(string.as_ref(), true); let max_offset = min(self.area.right() as usize, width.saturating_add(x as usize)); - for s in graphemes { - let width = s.width(); - if width == 0 { - continue; + if !truncate_start { + for s in graphemes { + let width = s.width(); + if width == 0 { + continue; + } + // `x_offset + width > max_offset` could be integer overflow on 32-bit machines if we + // change dimenstions to usize or u32 and someone resizes the terminal to 1x2^32. + if width > max_offset.saturating_sub(x_offset) { + break; + } + + self.content[index].set_symbol(s); + self.content[index].set_style(style); + // Reset following cells if multi-width (they would be hidden by the grapheme), + for i in index + 1..index + width { + self.content[i].reset(); + } + index += width; + x_offset += width; } - // `x_offset + width > max_offset` could be integer overflow on 32-bit machines if we - // change dimenstions to usize or u32 and someone resizes the terminal to 1x2^32. - if width > max_offset.saturating_sub(x_offset) { - break; + if ellipsis && x_offset - (x as usize) < string.as_ref().width() { + self.content[index].set_symbol("…"); } - - self.content[index].set_symbol(s); - self.content[index].set_style(style); - // Reset following cells if multi-width (they would be hidden by the grapheme), - for i in index + 1..index + width { - self.content[i].reset(); + } else { + let mut start_index = self.index_of(x, y); + let mut index = self.index_of(max_offset as u16, y); + + let total_width = string.as_ref().width(); + let truncated = total_width > width; + if ellipsis && truncated { + self.content[start_index].set_symbol("…"); + start_index += 1; + } + if !truncated { + index -= width - total_width; + } + for s in graphemes.rev() { + let width = s.width(); + if width == 0 { + continue; + } + let start = index - width; + if start < start_index { + break; + } + self.content[start].set_symbol(s); + self.content[start].set_style(style); + for i in start + 1..index { + self.content[i].reset(); + } + index -= width; } - index += width; - x_offset += width; - } - if ellipsis && x_offset - (x as usize) < string.as_ref().width() { - self.content[index].set_symbol("…"); } (x_offset as u16, y) } -- cgit v1.2.3-70-g09d2