├── .editorconfig ├── .gitattributes ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ └── config.yml ├── dependabot.yml └── workflows │ ├── lint.yml │ └── linux.yml ├── .gitignore ├── .vscode └── settings.json ├── CHANGELOG.md ├── Cargo.lock ├── Cargo.toml ├── README.md ├── rust-toolchain.toml ├── scm-diff-editor ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── src │ ├── lib.rs │ ├── main.rs │ ├── render.rs │ └── testing.rs └── tests │ └── test_scm_diff_editor.rs └── scm-record ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── benches └── benches.rs ├── examples ├── load_json.rs └── static_contents.rs ├── proptest-regressions └── ui.txt ├── src ├── consts.rs ├── helpers.rs ├── lib.rs ├── render.rs ├── types.rs ├── ui.rs └── util.rs └── tests ├── example_contents.json └── test_scm_record.rs /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | trim_trailing_whitespace = true 6 | 7 | [*.{rs,lalrpop}] 8 | indent_style = space 9 | indent_size = 4 10 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | Cargo.lock linguist-generated=true merge=binary 2 | CHANGELOG.md merge=union 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [arxanas] 4 | # patreon: arxanas 5 | 6 | # open_collective: # Replace with a single Open Collective username 7 | # ko_fi: # Replace with a single Ko-fi username 8 | # tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 9 | # community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 10 | # liberapay: # Replace with a single Liberapay username 11 | # issuehunt: # Replace with a single IssueHunt username 12 | # otechie: # Replace with a single Otechie username 13 | # lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 14 | # custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: File a bug report 2 | description: | 3 | This form is for bugs with concrete resolutions. If you don't have a specific resolution in mind, then start a Discussion instead. 4 | labels: 5 | - bug 6 | 7 | body: 8 | - type: markdown 9 | attributes: 10 | value: | 11 | Thanks for reporting a bug! This form is for bugs which have concrete resolutions. To ask a question or to brainstorm solutions to a problem, start a [Discussion](https://github.com/arxanas/git-branchless/discussions) instead. 12 | 13 | - type: textarea 14 | id: description 15 | attributes: 16 | label: Description of the bug 17 | description: Include a description of the bug and steps to reproduce the issue. 18 | validations: 19 | required: true 20 | 21 | - type: textarea 22 | id: expected-behavior 23 | attributes: 24 | label: Expected behavior 25 | description: What did you expect to happen? 26 | 27 | - type: textarea 28 | id: actual-behavior 29 | attributes: 30 | label: Actual behavior 31 | description: What actually happened? 32 | 33 | - type: input 34 | id: rustc-version 35 | attributes: 36 | label: Version of `rustc` 37 | description: If this is a build issue, paste the output of `rustc --version` here. 38 | placeholder: "Example: rustc 1.55.0 (c8dfcfe04 2021-09-06)" 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | contact_links: 2 | - name: Start a Discussion 3 | url: https://github.com/arxanas/git-branchless/discussions 4 | about: Ask questions, suggest features, brainstorm solutions, and so on. Open-ended topics belong here. 5 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | updates: 4 | - package-ecosystem: "cargo" 5 | directory: "/" 6 | schedule: 7 | interval: "weekly" 8 | commit-message: 9 | prefix: "build:" 10 | allow: 11 | - dependency-type: "direct" 12 | ignore: 13 | - dependency-name: "*" 14 | update-types: ["version-update:semver-patch"] 15 | 16 | - package-ecosystem: "github-actions" 17 | directory: "/" 18 | schedule: 19 | interval: "weekly" 20 | commit-message: 21 | prefix: "build:" 22 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | pull_request: 9 | 10 | env: 11 | CARGO_INCREMENTAL: 0 12 | RUST_BACKTRACE: short 13 | 14 | jobs: 15 | static-analysis: 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | - uses: actions/checkout@v4 20 | 21 | - name: Forbid nocommit string 22 | run: | 23 | if results=$(git grep --column --line-number --only-matching '@''nocommit'); then 24 | echo "$results" 25 | awk <<<"$results" -F ':' '{ print "::error file=" $1 ",line=" $2 ",col=" $3 "::Illegal string: " $4 }' 26 | exit 1 27 | fi 28 | 29 | - name: Set up Rust 30 | uses: actions-rs/toolchain@v1 31 | with: 32 | profile: minimal 33 | toolchain: stable 34 | components: rustfmt, clippy 35 | override: true 36 | 37 | - name: Cache dependencies 38 | uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 39 | 40 | - name: Run `cargo fmt` 41 | uses: actions-rs/cargo@v1 42 | with: 43 | command: fmt 44 | args: --all -- --check 45 | 46 | - name: Run `cargo clippy` 47 | uses: actions-rs/cargo@v1 48 | with: 49 | command: clippy 50 | args: --workspace --all-features --all-targets -- --deny warnings 51 | 52 | - name: Run `cargo doc` 53 | uses: actions-rs/cargo@v1 54 | env: 55 | RUSTDOCFLAGS: "--deny warnings" 56 | with: 57 | command: clippy 58 | args: --workspace --all-features --all-targets -- --deny warnings 59 | -------------------------------------------------------------------------------- /.github/workflows/linux.yml: -------------------------------------------------------------------------------- 1 | name: Linux 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | 9 | env: 10 | CARGO_INCREMENTAL: 0 11 | RUST_BACKTRACE: short 12 | 13 | jobs: 14 | run-tests: 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v4 19 | 20 | - name: Set up Rust 21 | uses: actions-rs/toolchain@v1 22 | with: 23 | profile: minimal 24 | toolchain: 1.74 25 | override: true 26 | 27 | - name: Cache dependencies 28 | uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 29 | 30 | - name: Compile (all features) 31 | run: cargo build --all-features --all-targets --workspace 32 | 33 | # Don't test benches. 34 | - name: Run Rust tests (all features) 35 | timeout-minutes: 30 36 | run: cargo test --all-features --examples --tests --workspace 37 | 38 | # Note that `--doc` can't be combined with other tests. 39 | - name: Run Rust doc-tests (all features) 40 | timeout-minutes: 30 41 | run: cargo test --all-features --doc --workspace 42 | 43 | - name: Compile (no features) 44 | run: cargo build --no-default-features --all-targets --workspace 45 | 46 | # Don't test benches. 47 | - name: Run Rust tests (no features) 48 | timeout-minutes: 30 49 | run: cargo test --no-default-features --examples --tests --workspace 50 | 51 | # Note that `--doc` can't be combined with other tests. 52 | - name: Run Rust doc-tests (no features) 53 | timeout-minutes: 30 54 | run: cargo test --no-default-features --doc --workspace 55 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | *.so 3 | *.pending-snap 4 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true, 3 | "editor.formatOnType": true, 4 | "files.insertFinalNewline": true 5 | } 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | 9 | 10 | ## [Unreleased] - ReleaseDate 11 | 12 | ## [0.8.0] - 2025-03-15 13 | 14 | ### Changed 15 | 16 | - BREAKING (#93): File mode changes (including file creation and file deletion) should now always be represented as `Section::FileMode`. 17 | - (#95) Some selections/deselections are now performed automatically to prevent impossible combinations (like trying to delete a file but leave lines in it) 18 | 19 | ## [0.7.0] - 2025-03-15 20 | 21 | (Erroneously skipped; see https://github.com/crate-ci/cargo-release/issues/872) 22 | 23 | ## [0.6.0] - 2025-03-15 24 | 25 | (Erroneously skipped; see https://github.com/crate-ci/cargo-release/issues/872) 26 | 27 | ## [0.5.0] - 2025-01-10 28 | 29 | ### Changed 30 | 31 | - BREAKING (#39): Pressing the "left" or "h" keys now folds the current section if it is unfolded instead of moving to the outer item. You can still move to the outer item directly without automatic folding by pressing shift-left or shift-h. 32 | 33 | ## [0.4.0] - 2024-10-09 34 | 35 | ### Added 36 | 37 | - (#45): ctrl-up and ctrl-down added as keyboard shortcuts to scroll by individual lines. 38 | - (#45): ctrl-page-up and ctrl-page-down added as keyboard shortcuts to scroll by pages. 39 | - (#58): Pressing question mark '?' pops up a help dialog. 40 | 41 | ### Changed 42 | 43 | - BREAKING (#45): page-up and page-down now jump to the next section of the same type. The old behavior can be accessed with ctrl-page-up and ctrl-page-down. 44 | - BREAKING (#52): Minimum supported Rust version (MSRV) is now 1.74. 45 | - BREAKING (#53): `scm-diff-editor` has been extracted to its own crate and can be installed as its own stand-alone binary. 46 | - (#46): Checkmarks changed to Unicode symobls. 47 | - (#61): Control characters are replaced with Unicode symbols for rendering. 48 | 49 | ### Fixed 50 | 51 | - (#37): Fixed redraw issues when rendering tabs and other non-printing characters. 52 | 53 | ## [0.3.0] - 2024-05-26 54 | 55 | ### Added 56 | 57 | - (#41) When collapsing editable sections, the uneditable context lines between those collapsed editable sections is now also hidden. 58 | 59 | ### Fixed 60 | 61 | - (#31) Console mode settings are now undone in LIFO order, improving Powershell integration. 62 | - (#47) The alternate screen is now cleared before starting, improving Mosh integration. 63 | 64 | ## [v0.2.0] - 2023-12-25 65 | 66 | ### Added 67 | 68 | - Support invoking a commit editor while selecting changes. 69 | 70 | ### Changed 71 | 72 | - The maximum file view width is now 120 columns. 73 | - (#11) Render a message when there are no changes to view. 74 | 75 | ### Fixed 76 | 77 | - Fixed typo in "next item" menu item. 78 | - Fixed build without `serde` feature. 79 | 80 | ## [v0.1.0] - 2023-03-01 81 | 82 | Initial release as part of git-branchless v0.7.0. 83 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "aho-corasick" 7 | version = "1.1.3" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" 10 | dependencies = [ 11 | "memchr", 12 | ] 13 | 14 | [[package]] 15 | name = "allocator-api2" 16 | version = "0.2.21" 17 | source = "registry+https://github.com/rust-lang/crates.io-index" 18 | checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" 19 | 20 | [[package]] 21 | name = "anes" 22 | version = "0.1.6" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" 25 | 26 | [[package]] 27 | name = "anstream" 28 | version = "0.6.18" 29 | source = "registry+https://github.com/rust-lang/crates.io-index" 30 | checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" 31 | dependencies = [ 32 | "anstyle", 33 | "anstyle-parse", 34 | "anstyle-query", 35 | "anstyle-wincon", 36 | "colorchoice", 37 | "is_terminal_polyfill", 38 | "utf8parse", 39 | ] 40 | 41 | [[package]] 42 | name = "anstyle" 43 | version = "1.0.10" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" 46 | 47 | [[package]] 48 | name = "anstyle-parse" 49 | version = "0.2.6" 50 | source = "registry+https://github.com/rust-lang/crates.io-index" 51 | checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" 52 | dependencies = [ 53 | "utf8parse", 54 | ] 55 | 56 | [[package]] 57 | name = "anstyle-query" 58 | version = "1.1.2" 59 | source = "registry+https://github.com/rust-lang/crates.io-index" 60 | checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" 61 | dependencies = [ 62 | "windows-sys 0.59.0", 63 | ] 64 | 65 | [[package]] 66 | name = "anstyle-wincon" 67 | version = "3.0.6" 68 | source = "registry+https://github.com/rust-lang/crates.io-index" 69 | checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" 70 | dependencies = [ 71 | "anstyle", 72 | "windows-sys 0.59.0", 73 | ] 74 | 75 | [[package]] 76 | name = "assert_matches" 77 | version = "1.5.0" 78 | source = "registry+https://github.com/rust-lang/crates.io-index" 79 | checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" 80 | 81 | [[package]] 82 | name = "autocfg" 83 | version = "1.4.0" 84 | source = "registry+https://github.com/rust-lang/crates.io-index" 85 | checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" 86 | 87 | [[package]] 88 | name = "bit-set" 89 | version = "0.8.0" 90 | source = "registry+https://github.com/rust-lang/crates.io-index" 91 | checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3" 92 | dependencies = [ 93 | "bit-vec", 94 | ] 95 | 96 | [[package]] 97 | name = "bit-vec" 98 | version = "0.8.0" 99 | source = "registry+https://github.com/rust-lang/crates.io-index" 100 | checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" 101 | 102 | [[package]] 103 | name = "bitflags" 104 | version = "2.6.0" 105 | source = "registry+https://github.com/rust-lang/crates.io-index" 106 | checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" 107 | 108 | [[package]] 109 | name = "block-buffer" 110 | version = "0.10.4" 111 | source = "registry+https://github.com/rust-lang/crates.io-index" 112 | checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" 113 | dependencies = [ 114 | "generic-array", 115 | ] 116 | 117 | [[package]] 118 | name = "bumpalo" 119 | version = "3.16.0" 120 | source = "registry+https://github.com/rust-lang/crates.io-index" 121 | checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" 122 | 123 | [[package]] 124 | name = "byteorder" 125 | version = "1.5.0" 126 | source = "registry+https://github.com/rust-lang/crates.io-index" 127 | checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" 128 | 129 | [[package]] 130 | name = "cassowary" 131 | version = "0.3.0" 132 | source = "registry+https://github.com/rust-lang/crates.io-index" 133 | checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" 134 | 135 | [[package]] 136 | name = "cast" 137 | version = "0.3.0" 138 | source = "registry+https://github.com/rust-lang/crates.io-index" 139 | checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" 140 | 141 | [[package]] 142 | name = "castaway" 143 | version = "0.2.3" 144 | source = "registry+https://github.com/rust-lang/crates.io-index" 145 | checksum = "0abae9be0aaf9ea96a3b1b8b1b55c602ca751eba1b1500220cea4ecbafe7c0d5" 146 | dependencies = [ 147 | "rustversion", 148 | ] 149 | 150 | [[package]] 151 | name = "cfg-if" 152 | version = "1.0.0" 153 | source = "registry+https://github.com/rust-lang/crates.io-index" 154 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 155 | 156 | [[package]] 157 | name = "ciborium" 158 | version = "0.2.2" 159 | source = "registry+https://github.com/rust-lang/crates.io-index" 160 | checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" 161 | dependencies = [ 162 | "ciborium-io", 163 | "ciborium-ll", 164 | "serde", 165 | ] 166 | 167 | [[package]] 168 | name = "ciborium-io" 169 | version = "0.2.2" 170 | source = "registry+https://github.com/rust-lang/crates.io-index" 171 | checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" 172 | 173 | [[package]] 174 | name = "ciborium-ll" 175 | version = "0.2.2" 176 | source = "registry+https://github.com/rust-lang/crates.io-index" 177 | checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" 178 | dependencies = [ 179 | "ciborium-io", 180 | "half", 181 | ] 182 | 183 | [[package]] 184 | name = "clap" 185 | version = "4.5.26" 186 | source = "registry+https://github.com/rust-lang/crates.io-index" 187 | checksum = "a8eb5e908ef3a6efbe1ed62520fb7287959888c88485abe072543190ecc66783" 188 | dependencies = [ 189 | "clap_builder", 190 | "clap_derive", 191 | ] 192 | 193 | [[package]] 194 | name = "clap_builder" 195 | version = "4.5.26" 196 | source = "registry+https://github.com/rust-lang/crates.io-index" 197 | checksum = "96b01801b5fc6a0a232407abc821660c9c6d25a1cafc0d4f85f29fb8d9afc121" 198 | dependencies = [ 199 | "anstream", 200 | "anstyle", 201 | "clap_lex", 202 | "strsim", 203 | ] 204 | 205 | [[package]] 206 | name = "clap_derive" 207 | version = "4.5.24" 208 | source = "registry+https://github.com/rust-lang/crates.io-index" 209 | checksum = "54b755194d6389280185988721fffba69495eed5ee9feeee9a599b53db80318c" 210 | dependencies = [ 211 | "heck", 212 | "proc-macro2", 213 | "quote", 214 | "syn", 215 | ] 216 | 217 | [[package]] 218 | name = "clap_lex" 219 | version = "0.7.4" 220 | source = "registry+https://github.com/rust-lang/crates.io-index" 221 | checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" 222 | 223 | [[package]] 224 | name = "colorchoice" 225 | version = "1.0.3" 226 | source = "registry+https://github.com/rust-lang/crates.io-index" 227 | checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" 228 | 229 | [[package]] 230 | name = "compact_str" 231 | version = "0.8.1" 232 | source = "registry+https://github.com/rust-lang/crates.io-index" 233 | checksum = "3b79c4069c6cad78e2e0cdfcbd26275770669fb39fd308a752dc110e83b9af32" 234 | dependencies = [ 235 | "castaway", 236 | "cfg-if", 237 | "itoa", 238 | "rustversion", 239 | "ryu", 240 | "static_assertions", 241 | ] 242 | 243 | [[package]] 244 | name = "console" 245 | version = "0.15.10" 246 | source = "registry+https://github.com/rust-lang/crates.io-index" 247 | checksum = "ea3c6ecd8059b57859df5c69830340ed3c41d30e3da0c1cbed90a96ac853041b" 248 | dependencies = [ 249 | "encode_unicode", 250 | "libc", 251 | "once_cell", 252 | "windows-sys 0.59.0", 253 | ] 254 | 255 | [[package]] 256 | name = "cpufeatures" 257 | version = "0.2.16" 258 | source = "registry+https://github.com/rust-lang/crates.io-index" 259 | checksum = "16b80225097f2e5ae4e7179dd2266824648f3e2f49d9134d584b76389d31c4c3" 260 | dependencies = [ 261 | "libc", 262 | ] 263 | 264 | [[package]] 265 | name = "criterion" 266 | version = "0.5.1" 267 | source = "registry+https://github.com/rust-lang/crates.io-index" 268 | checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" 269 | dependencies = [ 270 | "anes", 271 | "cast", 272 | "ciborium", 273 | "clap", 274 | "criterion-plot", 275 | "is-terminal", 276 | "itertools 0.10.5", 277 | "num-traits", 278 | "once_cell", 279 | "oorandom", 280 | "plotters", 281 | "rayon", 282 | "regex", 283 | "serde", 284 | "serde_derive", 285 | "serde_json", 286 | "tinytemplate", 287 | "walkdir", 288 | ] 289 | 290 | [[package]] 291 | name = "criterion-plot" 292 | version = "0.5.0" 293 | source = "registry+https://github.com/rust-lang/crates.io-index" 294 | checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" 295 | dependencies = [ 296 | "cast", 297 | "itertools 0.10.5", 298 | ] 299 | 300 | [[package]] 301 | name = "crossbeam-deque" 302 | version = "0.8.6" 303 | source = "registry+https://github.com/rust-lang/crates.io-index" 304 | checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" 305 | dependencies = [ 306 | "crossbeam-epoch", 307 | "crossbeam-utils", 308 | ] 309 | 310 | [[package]] 311 | name = "crossbeam-epoch" 312 | version = "0.9.18" 313 | source = "registry+https://github.com/rust-lang/crates.io-index" 314 | checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" 315 | dependencies = [ 316 | "crossbeam-utils", 317 | ] 318 | 319 | [[package]] 320 | name = "crossbeam-utils" 321 | version = "0.8.21" 322 | source = "registry+https://github.com/rust-lang/crates.io-index" 323 | checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" 324 | 325 | [[package]] 326 | name = "crossterm" 327 | version = "0.28.1" 328 | source = "registry+https://github.com/rust-lang/crates.io-index" 329 | checksum = "829d955a0bb380ef178a640b91779e3987da38c9aea133b20614cfed8cdea9c6" 330 | dependencies = [ 331 | "bitflags", 332 | "crossterm_winapi", 333 | "mio", 334 | "parking_lot", 335 | "rustix", 336 | "signal-hook", 337 | "signal-hook-mio", 338 | "winapi", 339 | ] 340 | 341 | [[package]] 342 | name = "crossterm_winapi" 343 | version = "0.9.1" 344 | source = "registry+https://github.com/rust-lang/crates.io-index" 345 | checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" 346 | dependencies = [ 347 | "winapi", 348 | ] 349 | 350 | [[package]] 351 | name = "crunchy" 352 | version = "0.2.2" 353 | source = "registry+https://github.com/rust-lang/crates.io-index" 354 | checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" 355 | 356 | [[package]] 357 | name = "crypto-common" 358 | version = "0.1.6" 359 | source = "registry+https://github.com/rust-lang/crates.io-index" 360 | checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" 361 | dependencies = [ 362 | "generic-array", 363 | "typenum", 364 | ] 365 | 366 | [[package]] 367 | name = "darling" 368 | version = "0.20.10" 369 | source = "registry+https://github.com/rust-lang/crates.io-index" 370 | checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" 371 | dependencies = [ 372 | "darling_core", 373 | "darling_macro", 374 | ] 375 | 376 | [[package]] 377 | name = "darling_core" 378 | version = "0.20.10" 379 | source = "registry+https://github.com/rust-lang/crates.io-index" 380 | checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" 381 | dependencies = [ 382 | "fnv", 383 | "ident_case", 384 | "proc-macro2", 385 | "quote", 386 | "strsim", 387 | "syn", 388 | ] 389 | 390 | [[package]] 391 | name = "darling_macro" 392 | version = "0.20.10" 393 | source = "registry+https://github.com/rust-lang/crates.io-index" 394 | checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" 395 | dependencies = [ 396 | "darling_core", 397 | "quote", 398 | "syn", 399 | ] 400 | 401 | [[package]] 402 | name = "diffy" 403 | version = "0.4.0" 404 | source = "registry+https://github.com/rust-lang/crates.io-index" 405 | checksum = "5d3041965b7a63e70447ec818a46b1e5297f7fcae3058356d226c02750c4e6cb" 406 | dependencies = [ 407 | "nu-ansi-term", 408 | ] 409 | 410 | [[package]] 411 | name = "digest" 412 | version = "0.10.7" 413 | source = "registry+https://github.com/rust-lang/crates.io-index" 414 | checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" 415 | dependencies = [ 416 | "block-buffer", 417 | "crypto-common", 418 | ] 419 | 420 | [[package]] 421 | name = "either" 422 | version = "1.13.0" 423 | source = "registry+https://github.com/rust-lang/crates.io-index" 424 | checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" 425 | 426 | [[package]] 427 | name = "encode_unicode" 428 | version = "1.0.0" 429 | source = "registry+https://github.com/rust-lang/crates.io-index" 430 | checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" 431 | 432 | [[package]] 433 | name = "equivalent" 434 | version = "1.0.1" 435 | source = "registry+https://github.com/rust-lang/crates.io-index" 436 | checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" 437 | 438 | [[package]] 439 | name = "errno" 440 | version = "0.3.10" 441 | source = "registry+https://github.com/rust-lang/crates.io-index" 442 | checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" 443 | dependencies = [ 444 | "libc", 445 | "windows-sys 0.59.0", 446 | ] 447 | 448 | [[package]] 449 | name = "fastrand" 450 | version = "2.3.0" 451 | source = "registry+https://github.com/rust-lang/crates.io-index" 452 | checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" 453 | 454 | [[package]] 455 | name = "fnv" 456 | version = "1.0.7" 457 | source = "registry+https://github.com/rust-lang/crates.io-index" 458 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 459 | 460 | [[package]] 461 | name = "foldhash" 462 | version = "0.1.4" 463 | source = "registry+https://github.com/rust-lang/crates.io-index" 464 | checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f" 465 | 466 | [[package]] 467 | name = "generic-array" 468 | version = "0.14.7" 469 | source = "registry+https://github.com/rust-lang/crates.io-index" 470 | checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" 471 | dependencies = [ 472 | "typenum", 473 | "version_check", 474 | ] 475 | 476 | [[package]] 477 | name = "getrandom" 478 | version = "0.2.15" 479 | source = "registry+https://github.com/rust-lang/crates.io-index" 480 | checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" 481 | dependencies = [ 482 | "cfg-if", 483 | "libc", 484 | "wasi", 485 | ] 486 | 487 | [[package]] 488 | name = "half" 489 | version = "2.4.1" 490 | source = "registry+https://github.com/rust-lang/crates.io-index" 491 | checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" 492 | dependencies = [ 493 | "cfg-if", 494 | "crunchy", 495 | ] 496 | 497 | [[package]] 498 | name = "hashbrown" 499 | version = "0.15.2" 500 | source = "registry+https://github.com/rust-lang/crates.io-index" 501 | checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" 502 | dependencies = [ 503 | "allocator-api2", 504 | "equivalent", 505 | "foldhash", 506 | ] 507 | 508 | [[package]] 509 | name = "heck" 510 | version = "0.5.0" 511 | source = "registry+https://github.com/rust-lang/crates.io-index" 512 | checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" 513 | 514 | [[package]] 515 | name = "hermit-abi" 516 | version = "0.4.0" 517 | source = "registry+https://github.com/rust-lang/crates.io-index" 518 | checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" 519 | 520 | [[package]] 521 | name = "ident_case" 522 | version = "1.0.1" 523 | source = "registry+https://github.com/rust-lang/crates.io-index" 524 | checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" 525 | 526 | [[package]] 527 | name = "indoc" 528 | version = "2.0.5" 529 | source = "registry+https://github.com/rust-lang/crates.io-index" 530 | checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" 531 | 532 | [[package]] 533 | name = "insta" 534 | version = "1.43.1" 535 | source = "registry+https://github.com/rust-lang/crates.io-index" 536 | checksum = "154934ea70c58054b556dd430b99a98c2a7ff5309ac9891597e339b5c28f4371" 537 | dependencies = [ 538 | "console", 539 | "once_cell", 540 | "similar", 541 | ] 542 | 543 | [[package]] 544 | name = "instability" 545 | version = "0.3.6" 546 | source = "registry+https://github.com/rust-lang/crates.io-index" 547 | checksum = "894813a444908c0c8c0e221b041771d107c4a21de1d317dc49bcc66e3c9e5b3f" 548 | dependencies = [ 549 | "darling", 550 | "indoc", 551 | "proc-macro2", 552 | "quote", 553 | "syn", 554 | ] 555 | 556 | [[package]] 557 | name = "is-terminal" 558 | version = "0.4.13" 559 | source = "registry+https://github.com/rust-lang/crates.io-index" 560 | checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" 561 | dependencies = [ 562 | "hermit-abi", 563 | "libc", 564 | "windows-sys 0.52.0", 565 | ] 566 | 567 | [[package]] 568 | name = "is_terminal_polyfill" 569 | version = "1.70.1" 570 | source = "registry+https://github.com/rust-lang/crates.io-index" 571 | checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" 572 | 573 | [[package]] 574 | name = "itertools" 575 | version = "0.10.5" 576 | source = "registry+https://github.com/rust-lang/crates.io-index" 577 | checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" 578 | dependencies = [ 579 | "either", 580 | ] 581 | 582 | [[package]] 583 | name = "itertools" 584 | version = "0.13.0" 585 | source = "registry+https://github.com/rust-lang/crates.io-index" 586 | checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" 587 | dependencies = [ 588 | "either", 589 | ] 590 | 591 | [[package]] 592 | name = "itoa" 593 | version = "1.0.14" 594 | source = "registry+https://github.com/rust-lang/crates.io-index" 595 | checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" 596 | 597 | [[package]] 598 | name = "js-sys" 599 | version = "0.3.76" 600 | source = "registry+https://github.com/rust-lang/crates.io-index" 601 | checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" 602 | dependencies = [ 603 | "once_cell", 604 | "wasm-bindgen", 605 | ] 606 | 607 | [[package]] 608 | name = "lazy_static" 609 | version = "1.5.0" 610 | source = "registry+https://github.com/rust-lang/crates.io-index" 611 | checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" 612 | 613 | [[package]] 614 | name = "libc" 615 | version = "0.2.169" 616 | source = "registry+https://github.com/rust-lang/crates.io-index" 617 | checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" 618 | 619 | [[package]] 620 | name = "linux-raw-sys" 621 | version = "0.4.15" 622 | source = "registry+https://github.com/rust-lang/crates.io-index" 623 | checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" 624 | 625 | [[package]] 626 | name = "lock_api" 627 | version = "0.4.12" 628 | source = "registry+https://github.com/rust-lang/crates.io-index" 629 | checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" 630 | dependencies = [ 631 | "autocfg", 632 | "scopeguard", 633 | ] 634 | 635 | [[package]] 636 | name = "log" 637 | version = "0.4.22" 638 | source = "registry+https://github.com/rust-lang/crates.io-index" 639 | checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" 640 | 641 | [[package]] 642 | name = "lru" 643 | version = "0.12.5" 644 | source = "registry+https://github.com/rust-lang/crates.io-index" 645 | checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" 646 | dependencies = [ 647 | "hashbrown", 648 | ] 649 | 650 | [[package]] 651 | name = "maplit" 652 | version = "1.0.2" 653 | source = "registry+https://github.com/rust-lang/crates.io-index" 654 | checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" 655 | 656 | [[package]] 657 | name = "memchr" 658 | version = "2.7.4" 659 | source = "registry+https://github.com/rust-lang/crates.io-index" 660 | checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" 661 | 662 | [[package]] 663 | name = "mio" 664 | version = "1.0.3" 665 | source = "registry+https://github.com/rust-lang/crates.io-index" 666 | checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" 667 | dependencies = [ 668 | "libc", 669 | "log", 670 | "wasi", 671 | "windows-sys 0.52.0", 672 | ] 673 | 674 | [[package]] 675 | name = "nu-ansi-term" 676 | version = "0.50.1" 677 | source = "registry+https://github.com/rust-lang/crates.io-index" 678 | checksum = "d4a28e057d01f97e61255210fcff094d74ed0466038633e95017f5beb68e4399" 679 | dependencies = [ 680 | "windows-sys 0.52.0", 681 | ] 682 | 683 | [[package]] 684 | name = "num-traits" 685 | version = "0.2.19" 686 | source = "registry+https://github.com/rust-lang/crates.io-index" 687 | checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" 688 | dependencies = [ 689 | "autocfg", 690 | ] 691 | 692 | [[package]] 693 | name = "once_cell" 694 | version = "1.20.2" 695 | source = "registry+https://github.com/rust-lang/crates.io-index" 696 | checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" 697 | 698 | [[package]] 699 | name = "oorandom" 700 | version = "11.1.4" 701 | source = "registry+https://github.com/rust-lang/crates.io-index" 702 | checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" 703 | 704 | [[package]] 705 | name = "parking_lot" 706 | version = "0.12.3" 707 | source = "registry+https://github.com/rust-lang/crates.io-index" 708 | checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" 709 | dependencies = [ 710 | "lock_api", 711 | "parking_lot_core", 712 | ] 713 | 714 | [[package]] 715 | name = "parking_lot_core" 716 | version = "0.9.10" 717 | source = "registry+https://github.com/rust-lang/crates.io-index" 718 | checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" 719 | dependencies = [ 720 | "cfg-if", 721 | "libc", 722 | "redox_syscall", 723 | "smallvec", 724 | "windows-targets", 725 | ] 726 | 727 | [[package]] 728 | name = "paste" 729 | version = "1.0.15" 730 | source = "registry+https://github.com/rust-lang/crates.io-index" 731 | checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" 732 | 733 | [[package]] 734 | name = "pin-project-lite" 735 | version = "0.2.16" 736 | source = "registry+https://github.com/rust-lang/crates.io-index" 737 | checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" 738 | 739 | [[package]] 740 | name = "plotters" 741 | version = "0.3.7" 742 | source = "registry+https://github.com/rust-lang/crates.io-index" 743 | checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" 744 | dependencies = [ 745 | "num-traits", 746 | "plotters-backend", 747 | "plotters-svg", 748 | "wasm-bindgen", 749 | "web-sys", 750 | ] 751 | 752 | [[package]] 753 | name = "plotters-backend" 754 | version = "0.3.7" 755 | source = "registry+https://github.com/rust-lang/crates.io-index" 756 | checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" 757 | 758 | [[package]] 759 | name = "plotters-svg" 760 | version = "0.3.7" 761 | source = "registry+https://github.com/rust-lang/crates.io-index" 762 | checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" 763 | dependencies = [ 764 | "plotters-backend", 765 | ] 766 | 767 | [[package]] 768 | name = "ppv-lite86" 769 | version = "0.2.20" 770 | source = "registry+https://github.com/rust-lang/crates.io-index" 771 | checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" 772 | dependencies = [ 773 | "zerocopy", 774 | ] 775 | 776 | [[package]] 777 | name = "proc-macro2" 778 | version = "1.0.92" 779 | source = "registry+https://github.com/rust-lang/crates.io-index" 780 | checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" 781 | dependencies = [ 782 | "unicode-ident", 783 | ] 784 | 785 | [[package]] 786 | name = "proptest" 787 | version = "1.6.0" 788 | source = "registry+https://github.com/rust-lang/crates.io-index" 789 | checksum = "14cae93065090804185d3b75f0bf93b8eeda30c7a9b4a33d3bdb3988d6229e50" 790 | dependencies = [ 791 | "bit-set", 792 | "bit-vec", 793 | "bitflags", 794 | "lazy_static", 795 | "num-traits", 796 | "rand", 797 | "rand_chacha", 798 | "rand_xorshift", 799 | "regex-syntax", 800 | "rusty-fork", 801 | "tempfile", 802 | "unarray", 803 | ] 804 | 805 | [[package]] 806 | name = "quick-error" 807 | version = "1.2.3" 808 | source = "registry+https://github.com/rust-lang/crates.io-index" 809 | checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" 810 | 811 | [[package]] 812 | name = "quote" 813 | version = "1.0.38" 814 | source = "registry+https://github.com/rust-lang/crates.io-index" 815 | checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" 816 | dependencies = [ 817 | "proc-macro2", 818 | ] 819 | 820 | [[package]] 821 | name = "rand" 822 | version = "0.8.5" 823 | source = "registry+https://github.com/rust-lang/crates.io-index" 824 | checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" 825 | dependencies = [ 826 | "libc", 827 | "rand_chacha", 828 | "rand_core", 829 | ] 830 | 831 | [[package]] 832 | name = "rand_chacha" 833 | version = "0.3.1" 834 | source = "registry+https://github.com/rust-lang/crates.io-index" 835 | checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" 836 | dependencies = [ 837 | "ppv-lite86", 838 | "rand_core", 839 | ] 840 | 841 | [[package]] 842 | name = "rand_core" 843 | version = "0.6.4" 844 | source = "registry+https://github.com/rust-lang/crates.io-index" 845 | checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" 846 | dependencies = [ 847 | "getrandom", 848 | ] 849 | 850 | [[package]] 851 | name = "rand_xorshift" 852 | version = "0.3.0" 853 | source = "registry+https://github.com/rust-lang/crates.io-index" 854 | checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" 855 | dependencies = [ 856 | "rand_core", 857 | ] 858 | 859 | [[package]] 860 | name = "ratatui" 861 | version = "0.29.0" 862 | source = "registry+https://github.com/rust-lang/crates.io-index" 863 | checksum = "eabd94c2f37801c20583fc49dd5cd6b0ba68c716787c2dd6ed18571e1e63117b" 864 | dependencies = [ 865 | "bitflags", 866 | "cassowary", 867 | "compact_str", 868 | "crossterm", 869 | "indoc", 870 | "instability", 871 | "itertools 0.13.0", 872 | "lru", 873 | "paste", 874 | "strum", 875 | "unicode-segmentation", 876 | "unicode-truncate", 877 | "unicode-width 0.2.0", 878 | ] 879 | 880 | [[package]] 881 | name = "rayon" 882 | version = "1.10.0" 883 | source = "registry+https://github.com/rust-lang/crates.io-index" 884 | checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" 885 | dependencies = [ 886 | "either", 887 | "rayon-core", 888 | ] 889 | 890 | [[package]] 891 | name = "rayon-core" 892 | version = "1.12.1" 893 | source = "registry+https://github.com/rust-lang/crates.io-index" 894 | checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" 895 | dependencies = [ 896 | "crossbeam-deque", 897 | "crossbeam-utils", 898 | ] 899 | 900 | [[package]] 901 | name = "redox_syscall" 902 | version = "0.5.8" 903 | source = "registry+https://github.com/rust-lang/crates.io-index" 904 | checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" 905 | dependencies = [ 906 | "bitflags", 907 | ] 908 | 909 | [[package]] 910 | name = "regex" 911 | version = "1.11.1" 912 | source = "registry+https://github.com/rust-lang/crates.io-index" 913 | checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" 914 | dependencies = [ 915 | "aho-corasick", 916 | "memchr", 917 | "regex-automata", 918 | "regex-syntax", 919 | ] 920 | 921 | [[package]] 922 | name = "regex-automata" 923 | version = "0.4.9" 924 | source = "registry+https://github.com/rust-lang/crates.io-index" 925 | checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" 926 | dependencies = [ 927 | "aho-corasick", 928 | "memchr", 929 | "regex-syntax", 930 | ] 931 | 932 | [[package]] 933 | name = "regex-syntax" 934 | version = "0.8.5" 935 | source = "registry+https://github.com/rust-lang/crates.io-index" 936 | checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" 937 | 938 | [[package]] 939 | name = "rustix" 940 | version = "0.38.43" 941 | source = "registry+https://github.com/rust-lang/crates.io-index" 942 | checksum = "a78891ee6bf2340288408954ac787aa063d8e8817e9f53abb37c695c6d834ef6" 943 | dependencies = [ 944 | "bitflags", 945 | "errno", 946 | "libc", 947 | "linux-raw-sys", 948 | "windows-sys 0.59.0", 949 | ] 950 | 951 | [[package]] 952 | name = "rustversion" 953 | version = "1.0.19" 954 | source = "registry+https://github.com/rust-lang/crates.io-index" 955 | checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" 956 | 957 | [[package]] 958 | name = "rusty-fork" 959 | version = "0.3.0" 960 | source = "registry+https://github.com/rust-lang/crates.io-index" 961 | checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" 962 | dependencies = [ 963 | "fnv", 964 | "quick-error", 965 | "tempfile", 966 | "wait-timeout", 967 | ] 968 | 969 | [[package]] 970 | name = "ryu" 971 | version = "1.0.18" 972 | source = "registry+https://github.com/rust-lang/crates.io-index" 973 | checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" 974 | 975 | [[package]] 976 | name = "same-file" 977 | version = "1.0.6" 978 | source = "registry+https://github.com/rust-lang/crates.io-index" 979 | checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" 980 | dependencies = [ 981 | "winapi-util", 982 | ] 983 | 984 | [[package]] 985 | name = "scm-diff-editor" 986 | version = "0.8.0" 987 | dependencies = [ 988 | "clap", 989 | "diffy", 990 | "insta", 991 | "maplit", 992 | "scm-record", 993 | "sha1", 994 | "thiserror", 995 | "tracing", 996 | "walkdir", 997 | ] 998 | 999 | [[package]] 1000 | name = "scm-record" 1001 | version = "0.8.0" 1002 | dependencies = [ 1003 | "assert_matches", 1004 | "cassowary", 1005 | "criterion", 1006 | "crossterm", 1007 | "insta", 1008 | "num-traits", 1009 | "proptest", 1010 | "ratatui", 1011 | "serde", 1012 | "serde_json", 1013 | "thiserror", 1014 | "tracing", 1015 | "unicode-width 0.2.0", 1016 | ] 1017 | 1018 | [[package]] 1019 | name = "scopeguard" 1020 | version = "1.2.0" 1021 | source = "registry+https://github.com/rust-lang/crates.io-index" 1022 | checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" 1023 | 1024 | [[package]] 1025 | name = "serde" 1026 | version = "1.0.217" 1027 | source = "registry+https://github.com/rust-lang/crates.io-index" 1028 | checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" 1029 | dependencies = [ 1030 | "serde_derive", 1031 | ] 1032 | 1033 | [[package]] 1034 | name = "serde_derive" 1035 | version = "1.0.217" 1036 | source = "registry+https://github.com/rust-lang/crates.io-index" 1037 | checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" 1038 | dependencies = [ 1039 | "proc-macro2", 1040 | "quote", 1041 | "syn", 1042 | ] 1043 | 1044 | [[package]] 1045 | name = "serde_json" 1046 | version = "1.0.135" 1047 | source = "registry+https://github.com/rust-lang/crates.io-index" 1048 | checksum = "2b0d7ba2887406110130a978386c4e1befb98c674b4fba677954e4db976630d9" 1049 | dependencies = [ 1050 | "itoa", 1051 | "memchr", 1052 | "ryu", 1053 | "serde", 1054 | ] 1055 | 1056 | [[package]] 1057 | name = "sha1" 1058 | version = "0.10.6" 1059 | source = "registry+https://github.com/rust-lang/crates.io-index" 1060 | checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" 1061 | dependencies = [ 1062 | "cfg-if", 1063 | "cpufeatures", 1064 | "digest", 1065 | ] 1066 | 1067 | [[package]] 1068 | name = "signal-hook" 1069 | version = "0.3.17" 1070 | source = "registry+https://github.com/rust-lang/crates.io-index" 1071 | checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" 1072 | dependencies = [ 1073 | "libc", 1074 | "signal-hook-registry", 1075 | ] 1076 | 1077 | [[package]] 1078 | name = "signal-hook-mio" 1079 | version = "0.2.4" 1080 | source = "registry+https://github.com/rust-lang/crates.io-index" 1081 | checksum = "34db1a06d485c9142248b7a054f034b349b212551f3dfd19c94d45a754a217cd" 1082 | dependencies = [ 1083 | "libc", 1084 | "mio", 1085 | "signal-hook", 1086 | ] 1087 | 1088 | [[package]] 1089 | name = "signal-hook-registry" 1090 | version = "1.4.2" 1091 | source = "registry+https://github.com/rust-lang/crates.io-index" 1092 | checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" 1093 | dependencies = [ 1094 | "libc", 1095 | ] 1096 | 1097 | [[package]] 1098 | name = "similar" 1099 | version = "2.6.0" 1100 | source = "registry+https://github.com/rust-lang/crates.io-index" 1101 | checksum = "1de1d4f81173b03af4c0cbed3c898f6bff5b870e4a7f5d6f4057d62a7a4b686e" 1102 | 1103 | [[package]] 1104 | name = "smallvec" 1105 | version = "1.13.2" 1106 | source = "registry+https://github.com/rust-lang/crates.io-index" 1107 | checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" 1108 | 1109 | [[package]] 1110 | name = "static_assertions" 1111 | version = "1.1.0" 1112 | source = "registry+https://github.com/rust-lang/crates.io-index" 1113 | checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" 1114 | 1115 | [[package]] 1116 | name = "strsim" 1117 | version = "0.11.1" 1118 | source = "registry+https://github.com/rust-lang/crates.io-index" 1119 | checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" 1120 | 1121 | [[package]] 1122 | name = "strum" 1123 | version = "0.26.3" 1124 | source = "registry+https://github.com/rust-lang/crates.io-index" 1125 | checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" 1126 | dependencies = [ 1127 | "strum_macros", 1128 | ] 1129 | 1130 | [[package]] 1131 | name = "strum_macros" 1132 | version = "0.26.4" 1133 | source = "registry+https://github.com/rust-lang/crates.io-index" 1134 | checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" 1135 | dependencies = [ 1136 | "heck", 1137 | "proc-macro2", 1138 | "quote", 1139 | "rustversion", 1140 | "syn", 1141 | ] 1142 | 1143 | [[package]] 1144 | name = "syn" 1145 | version = "2.0.95" 1146 | source = "registry+https://github.com/rust-lang/crates.io-index" 1147 | checksum = "46f71c0377baf4ef1cc3e3402ded576dccc315800fbc62dfc7fe04b009773b4a" 1148 | dependencies = [ 1149 | "proc-macro2", 1150 | "quote", 1151 | "unicode-ident", 1152 | ] 1153 | 1154 | [[package]] 1155 | name = "tempfile" 1156 | version = "3.15.0" 1157 | source = "registry+https://github.com/rust-lang/crates.io-index" 1158 | checksum = "9a8a559c81686f576e8cd0290cd2a24a2a9ad80c98b3478856500fcbd7acd704" 1159 | dependencies = [ 1160 | "cfg-if", 1161 | "fastrand", 1162 | "getrandom", 1163 | "once_cell", 1164 | "rustix", 1165 | "windows-sys 0.59.0", 1166 | ] 1167 | 1168 | [[package]] 1169 | name = "thiserror" 1170 | version = "2.0.10" 1171 | source = "registry+https://github.com/rust-lang/crates.io-index" 1172 | checksum = "a3ac7f54ca534db81081ef1c1e7f6ea8a3ef428d2fc069097c079443d24124d3" 1173 | dependencies = [ 1174 | "thiserror-impl", 1175 | ] 1176 | 1177 | [[package]] 1178 | name = "thiserror-impl" 1179 | version = "2.0.10" 1180 | source = "registry+https://github.com/rust-lang/crates.io-index" 1181 | checksum = "9e9465d30713b56a37ede7185763c3492a91be2f5fa68d958c44e41ab9248beb" 1182 | dependencies = [ 1183 | "proc-macro2", 1184 | "quote", 1185 | "syn", 1186 | ] 1187 | 1188 | [[package]] 1189 | name = "tinytemplate" 1190 | version = "1.2.1" 1191 | source = "registry+https://github.com/rust-lang/crates.io-index" 1192 | checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" 1193 | dependencies = [ 1194 | "serde", 1195 | "serde_json", 1196 | ] 1197 | 1198 | [[package]] 1199 | name = "tracing" 1200 | version = "0.1.41" 1201 | source = "registry+https://github.com/rust-lang/crates.io-index" 1202 | checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" 1203 | dependencies = [ 1204 | "pin-project-lite", 1205 | "tracing-attributes", 1206 | "tracing-core", 1207 | ] 1208 | 1209 | [[package]] 1210 | name = "tracing-attributes" 1211 | version = "0.1.28" 1212 | source = "registry+https://github.com/rust-lang/crates.io-index" 1213 | checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" 1214 | dependencies = [ 1215 | "proc-macro2", 1216 | "quote", 1217 | "syn", 1218 | ] 1219 | 1220 | [[package]] 1221 | name = "tracing-core" 1222 | version = "0.1.33" 1223 | source = "registry+https://github.com/rust-lang/crates.io-index" 1224 | checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" 1225 | dependencies = [ 1226 | "once_cell", 1227 | ] 1228 | 1229 | [[package]] 1230 | name = "typenum" 1231 | version = "1.17.0" 1232 | source = "registry+https://github.com/rust-lang/crates.io-index" 1233 | checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" 1234 | 1235 | [[package]] 1236 | name = "unarray" 1237 | version = "0.1.4" 1238 | source = "registry+https://github.com/rust-lang/crates.io-index" 1239 | checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" 1240 | 1241 | [[package]] 1242 | name = "unicode-ident" 1243 | version = "1.0.14" 1244 | source = "registry+https://github.com/rust-lang/crates.io-index" 1245 | checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" 1246 | 1247 | [[package]] 1248 | name = "unicode-segmentation" 1249 | version = "1.12.0" 1250 | source = "registry+https://github.com/rust-lang/crates.io-index" 1251 | checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" 1252 | 1253 | [[package]] 1254 | name = "unicode-truncate" 1255 | version = "1.1.0" 1256 | source = "registry+https://github.com/rust-lang/crates.io-index" 1257 | checksum = "b3644627a5af5fa321c95b9b235a72fd24cd29c648c2c379431e6628655627bf" 1258 | dependencies = [ 1259 | "itertools 0.13.0", 1260 | "unicode-segmentation", 1261 | "unicode-width 0.1.14", 1262 | ] 1263 | 1264 | [[package]] 1265 | name = "unicode-width" 1266 | version = "0.1.14" 1267 | source = "registry+https://github.com/rust-lang/crates.io-index" 1268 | checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" 1269 | 1270 | [[package]] 1271 | name = "unicode-width" 1272 | version = "0.2.0" 1273 | source = "registry+https://github.com/rust-lang/crates.io-index" 1274 | checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" 1275 | 1276 | [[package]] 1277 | name = "utf8parse" 1278 | version = "0.2.2" 1279 | source = "registry+https://github.com/rust-lang/crates.io-index" 1280 | checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" 1281 | 1282 | [[package]] 1283 | name = "version_check" 1284 | version = "0.9.5" 1285 | source = "registry+https://github.com/rust-lang/crates.io-index" 1286 | checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" 1287 | 1288 | [[package]] 1289 | name = "wait-timeout" 1290 | version = "0.2.0" 1291 | source = "registry+https://github.com/rust-lang/crates.io-index" 1292 | checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" 1293 | dependencies = [ 1294 | "libc", 1295 | ] 1296 | 1297 | [[package]] 1298 | name = "walkdir" 1299 | version = "2.5.0" 1300 | source = "registry+https://github.com/rust-lang/crates.io-index" 1301 | checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" 1302 | dependencies = [ 1303 | "same-file", 1304 | "winapi-util", 1305 | ] 1306 | 1307 | [[package]] 1308 | name = "wasi" 1309 | version = "0.11.0+wasi-snapshot-preview1" 1310 | source = "registry+https://github.com/rust-lang/crates.io-index" 1311 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 1312 | 1313 | [[package]] 1314 | name = "wasm-bindgen" 1315 | version = "0.2.99" 1316 | source = "registry+https://github.com/rust-lang/crates.io-index" 1317 | checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" 1318 | dependencies = [ 1319 | "cfg-if", 1320 | "once_cell", 1321 | "wasm-bindgen-macro", 1322 | ] 1323 | 1324 | [[package]] 1325 | name = "wasm-bindgen-backend" 1326 | version = "0.2.99" 1327 | source = "registry+https://github.com/rust-lang/crates.io-index" 1328 | checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" 1329 | dependencies = [ 1330 | "bumpalo", 1331 | "log", 1332 | "proc-macro2", 1333 | "quote", 1334 | "syn", 1335 | "wasm-bindgen-shared", 1336 | ] 1337 | 1338 | [[package]] 1339 | name = "wasm-bindgen-macro" 1340 | version = "0.2.99" 1341 | source = "registry+https://github.com/rust-lang/crates.io-index" 1342 | checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" 1343 | dependencies = [ 1344 | "quote", 1345 | "wasm-bindgen-macro-support", 1346 | ] 1347 | 1348 | [[package]] 1349 | name = "wasm-bindgen-macro-support" 1350 | version = "0.2.99" 1351 | source = "registry+https://github.com/rust-lang/crates.io-index" 1352 | checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" 1353 | dependencies = [ 1354 | "proc-macro2", 1355 | "quote", 1356 | "syn", 1357 | "wasm-bindgen-backend", 1358 | "wasm-bindgen-shared", 1359 | ] 1360 | 1361 | [[package]] 1362 | name = "wasm-bindgen-shared" 1363 | version = "0.2.99" 1364 | source = "registry+https://github.com/rust-lang/crates.io-index" 1365 | checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" 1366 | 1367 | [[package]] 1368 | name = "web-sys" 1369 | version = "0.3.76" 1370 | source = "registry+https://github.com/rust-lang/crates.io-index" 1371 | checksum = "04dd7223427d52553d3702c004d3b2fe07c148165faa56313cb00211e31c12bc" 1372 | dependencies = [ 1373 | "js-sys", 1374 | "wasm-bindgen", 1375 | ] 1376 | 1377 | [[package]] 1378 | name = "winapi" 1379 | version = "0.3.9" 1380 | source = "registry+https://github.com/rust-lang/crates.io-index" 1381 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 1382 | dependencies = [ 1383 | "winapi-i686-pc-windows-gnu", 1384 | "winapi-x86_64-pc-windows-gnu", 1385 | ] 1386 | 1387 | [[package]] 1388 | name = "winapi-i686-pc-windows-gnu" 1389 | version = "0.4.0" 1390 | source = "registry+https://github.com/rust-lang/crates.io-index" 1391 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 1392 | 1393 | [[package]] 1394 | name = "winapi-util" 1395 | version = "0.1.9" 1396 | source = "registry+https://github.com/rust-lang/crates.io-index" 1397 | checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" 1398 | dependencies = [ 1399 | "windows-sys 0.59.0", 1400 | ] 1401 | 1402 | [[package]] 1403 | name = "winapi-x86_64-pc-windows-gnu" 1404 | version = "0.4.0" 1405 | source = "registry+https://github.com/rust-lang/crates.io-index" 1406 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 1407 | 1408 | [[package]] 1409 | name = "windows-sys" 1410 | version = "0.52.0" 1411 | source = "registry+https://github.com/rust-lang/crates.io-index" 1412 | checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" 1413 | dependencies = [ 1414 | "windows-targets", 1415 | ] 1416 | 1417 | [[package]] 1418 | name = "windows-sys" 1419 | version = "0.59.0" 1420 | source = "registry+https://github.com/rust-lang/crates.io-index" 1421 | checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" 1422 | dependencies = [ 1423 | "windows-targets", 1424 | ] 1425 | 1426 | [[package]] 1427 | name = "windows-targets" 1428 | version = "0.52.6" 1429 | source = "registry+https://github.com/rust-lang/crates.io-index" 1430 | checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" 1431 | dependencies = [ 1432 | "windows_aarch64_gnullvm", 1433 | "windows_aarch64_msvc", 1434 | "windows_i686_gnu", 1435 | "windows_i686_gnullvm", 1436 | "windows_i686_msvc", 1437 | "windows_x86_64_gnu", 1438 | "windows_x86_64_gnullvm", 1439 | "windows_x86_64_msvc", 1440 | ] 1441 | 1442 | [[package]] 1443 | name = "windows_aarch64_gnullvm" 1444 | version = "0.52.6" 1445 | source = "registry+https://github.com/rust-lang/crates.io-index" 1446 | checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" 1447 | 1448 | [[package]] 1449 | name = "windows_aarch64_msvc" 1450 | version = "0.52.6" 1451 | source = "registry+https://github.com/rust-lang/crates.io-index" 1452 | checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" 1453 | 1454 | [[package]] 1455 | name = "windows_i686_gnu" 1456 | version = "0.52.6" 1457 | source = "registry+https://github.com/rust-lang/crates.io-index" 1458 | checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" 1459 | 1460 | [[package]] 1461 | name = "windows_i686_gnullvm" 1462 | version = "0.52.6" 1463 | source = "registry+https://github.com/rust-lang/crates.io-index" 1464 | checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" 1465 | 1466 | [[package]] 1467 | name = "windows_i686_msvc" 1468 | version = "0.52.6" 1469 | source = "registry+https://github.com/rust-lang/crates.io-index" 1470 | checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" 1471 | 1472 | [[package]] 1473 | name = "windows_x86_64_gnu" 1474 | version = "0.52.6" 1475 | source = "registry+https://github.com/rust-lang/crates.io-index" 1476 | checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" 1477 | 1478 | [[package]] 1479 | name = "windows_x86_64_gnullvm" 1480 | version = "0.52.6" 1481 | source = "registry+https://github.com/rust-lang/crates.io-index" 1482 | checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" 1483 | 1484 | [[package]] 1485 | name = "windows_x86_64_msvc" 1486 | version = "0.52.6" 1487 | source = "registry+https://github.com/rust-lang/crates.io-index" 1488 | checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" 1489 | 1490 | [[package]] 1491 | name = "zerocopy" 1492 | version = "0.7.35" 1493 | source = "registry+https://github.com/rust-lang/crates.io-index" 1494 | checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" 1495 | dependencies = [ 1496 | "byteorder", 1497 | "zerocopy-derive", 1498 | ] 1499 | 1500 | [[package]] 1501 | name = "zerocopy-derive" 1502 | version = "0.7.35" 1503 | source = "registry+https://github.com/rust-lang/crates.io-index" 1504 | checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" 1505 | dependencies = [ 1506 | "proc-macro2", 1507 | "quote", 1508 | "syn", 1509 | ] 1510 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | resolver = "2" 3 | members = ["scm-diff-editor", "scm-record"] 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | [Build status]: https://img.shields.io/github/actions/workflow/status/arxanas/scm-record/.github%2Fworkflows%2Flinux.yml 4 | [link-build-status]: https://github.com/arxanas/scm-record/actions?branch=main 5 | [Latest version]: https://img.shields.io/crates/v/scm-record.svg 6 | [link-latest-version]: https://crates.io/crates/scm-record 7 | [Docs]: https://img.shields.io/docsrs/scm-record 8 | [link-docs]: https://docs.rs/scm-record/latest/scm_record/ 9 | [License]: https://img.shields.io/crates/l/scm-record 10 | [link-license]: https://github.com/arxanas/scm-record/tree/main/scm-record 11 | 12 | [![Build status]][link-build-status] [![Latest version]][link-latest-version] [![Docs]][link-docs] [![License]][link-license] 13 | 14 | `scm-record` is a Rust library for a UI component to interactively select changes to include in a commit. It's meant to be embedded in source control tooling. 15 | 16 | You can think of this as an interactive replacement for `git add -p`, or a reimplementation of `hg crecord`/`hg commit -i`. Given a set of changes made by the user, this component presents them to the user and lets them select which of those changes should be staged for commit. 17 | 18 | The `scm-record` library is directly integrated into these projects: 19 | 20 | - [git-branchless](https://github.com/arxanas/git-branchless): the `git record -i` command lets you interactively select and commit changes. 21 | - [Jujutsu](https://github.com/martinvonz/jj): as the built-in diff editor; see the [`ui.diff-editor`](https://martinvonz.github.io/jj/latest/config/#editing-diffs) configuration option. 22 | 23 | ## Standalone executable 24 | 25 | `scm-diff-editor` is a standalone executable that uses `scm-record` as the front-end. It can be installed via `cargo`: 26 | 27 | ```sh 28 | $ cargo install --locked scm-diff-editor 29 | ``` 30 | 31 | The `scm-diff-editor` executable can be used with these tools: 32 | 33 | - [Git](https://git-scm.org): as a [difftool](https://git-scm.com/docs/git-difftool). 34 | - [Mercurial](https://www.mercurial-scm.org/): via [the `extdiff` extension](https://wiki.mercurial-scm.org/ExtdiffExtension). 35 | - Likely other source control systems as well. 36 | 37 | # Future work 38 | 39 | ## Feature wishlist 40 | 41 | Here are some features in the UI which are not yet implemented: 42 | 43 | - [ ] Make the keybindings easier to discover (https://github.com/arxanas/scm-record/issues/25). 44 | - [ ] Support accessing the menu with the keyboard (https://github.com/arxanas/scm-record/issues/44). 45 | - [ ] Edit one side of the diff in an editor (https://github.com/arxanas/scm-record/issues/83). 46 | - [ ] Multi-way split UI to split a commit into more than 2 commits (https://github.com/arxanas/scm-record/issues/73). 47 | - [ ] Support for use as a mergetool. 48 | - [ ] Commands to select ours/theirs for diffs representing merge conflicts. 49 | 50 | ## Integration with other projects 51 | 52 | Here's some projects that don't use `scm-record`, but could benefit from integration with it (with your contribution): 53 | 54 | - [Sapling](https://sapling-scm.com/) 55 | - [Stacked Git](https://stacked-git.github.io/) 56 | - [Pijul](https://pijul.org/) 57 | - [gitoxide/ein](https://github.com/Byron/gitoxide) 58 | - [gitui](https://github.com/extrawurst/gitui) 59 | - [Game of Trees](https://gameoftrees.org/) 60 | -------------------------------------------------------------------------------- /rust-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "1.74" # or later 3 | profile = "default" 4 | -------------------------------------------------------------------------------- /scm-diff-editor/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["Waleed Khan "] 3 | description = "UI component to interactively select changes to include in a commit." 4 | edition = "2021" 5 | license = "MIT OR Apache-2.0" 6 | name = "scm-diff-editor" 7 | repository = "https://github.com/arxanas/scm-record" 8 | version = "0.8.0" 9 | 10 | # Keep in sync with `scm-record/Cargo.toml`. 11 | rust-version = "1.74" 12 | 13 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 14 | 15 | [dependencies] 16 | clap = { version = "4.5", features = ["derive"] } 17 | diffy = "0.4" 18 | scm-record = { version = "0.8", path = "../scm-record" } 19 | sha1 = "0.10" 20 | thiserror = "2.0.3" 21 | tracing = "0.1.40" 22 | walkdir = "2.5" 23 | 24 | [dev-dependencies] 25 | insta = "1.43" 26 | maplit = "1.0" 27 | -------------------------------------------------------------------------------- /scm-diff-editor/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /scm-diff-editor/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Individual contributors 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /scm-diff-editor/src/main.rs: -------------------------------------------------------------------------------- 1 | use clap::Parser; 2 | use scm_diff_editor::{run, Opts, Result}; 3 | 4 | pub fn main() -> Result<()> { 5 | let opts = Opts::parse(); 6 | run(opts)?; 7 | Ok(()) 8 | } 9 | -------------------------------------------------------------------------------- /scm-diff-editor/src/render.rs: -------------------------------------------------------------------------------- 1 | use std::borrow::Cow; 2 | use std::path::PathBuf; 3 | 4 | use scm_record::helpers::make_binary_description; 5 | use scm_record::{ChangeType, File, Section, SectionChangedLine}; 6 | use tracing::warn; 7 | 8 | use super::{Error, FileContents, FileInfo, Filesystem}; 9 | 10 | fn make_section_changed_lines( 11 | contents: &str, 12 | change_type: ChangeType, 13 | ) -> Vec> { 14 | contents 15 | .split_inclusive('\n') 16 | .map(|line| SectionChangedLine { 17 | is_checked: false, 18 | change_type, 19 | line: Cow::Owned(line.to_owned()), 20 | }) 21 | .collect() 22 | } 23 | 24 | pub fn create_file( 25 | filesystem: &dyn Filesystem, 26 | left_path: PathBuf, 27 | left_display_path: PathBuf, 28 | right_path: PathBuf, 29 | right_display_path: PathBuf, 30 | ) -> Result, Error> { 31 | let FileInfo { 32 | file_mode: left_file_mode, 33 | contents: left_contents, 34 | } = filesystem.read_file_info(&left_path)?; 35 | let FileInfo { 36 | file_mode: right_file_mode, 37 | contents: right_contents, 38 | } = filesystem.read_file_info(&right_path)?; 39 | let mut sections = Vec::new(); 40 | 41 | if left_file_mode != right_file_mode { 42 | sections.push(Section::FileMode { 43 | is_checked: false, 44 | mode: right_file_mode, 45 | }); 46 | } 47 | 48 | match (left_contents, right_contents) { 49 | (FileContents::Absent, FileContents::Absent) => {} 50 | ( 51 | FileContents::Absent, 52 | FileContents::Text { 53 | contents, 54 | hash: _, 55 | num_bytes: _, 56 | }, 57 | ) => sections.push(Section::Changed { 58 | lines: make_section_changed_lines(&contents, ChangeType::Added), 59 | }), 60 | 61 | (FileContents::Absent, FileContents::Binary { hash, num_bytes }) => { 62 | sections.push(Section::Binary { 63 | is_checked: false, 64 | old_description: None, 65 | new_description: Some(Cow::Owned(make_binary_description(&hash, num_bytes))), 66 | }) 67 | } 68 | 69 | ( 70 | FileContents::Text { 71 | contents, 72 | hash: _, 73 | num_bytes: _, 74 | }, 75 | FileContents::Absent, 76 | ) => sections.push(Section::Changed { 77 | lines: make_section_changed_lines(&contents, ChangeType::Removed), 78 | }), 79 | 80 | ( 81 | FileContents::Text { 82 | contents: old_contents, 83 | hash: _, 84 | num_bytes: _, 85 | }, 86 | FileContents::Text { 87 | contents: new_contents, 88 | hash: _, 89 | num_bytes: _, 90 | }, 91 | ) => { 92 | sections.extend(create_diff(&old_contents, &new_contents)); 93 | } 94 | 95 | ( 96 | FileContents::Text { 97 | contents: _, 98 | hash: old_hash, 99 | num_bytes: old_num_bytes, 100 | } 101 | | FileContents::Binary { 102 | hash: old_hash, 103 | num_bytes: old_num_bytes, 104 | }, 105 | FileContents::Text { 106 | contents: _, 107 | hash: new_hash, 108 | num_bytes: new_num_bytes, 109 | } 110 | | FileContents::Binary { 111 | hash: new_hash, 112 | num_bytes: new_num_bytes, 113 | }, 114 | ) => sections.push(Section::Binary { 115 | is_checked: false, 116 | old_description: Some(Cow::Owned(make_binary_description( 117 | &old_hash, 118 | old_num_bytes, 119 | ))), 120 | new_description: Some(Cow::Owned(make_binary_description( 121 | &new_hash, 122 | new_num_bytes, 123 | ))), 124 | }), 125 | 126 | (FileContents::Binary { hash, num_bytes }, FileContents::Absent) => { 127 | sections.push(Section::Binary { 128 | is_checked: false, 129 | old_description: Some(Cow::Owned(make_binary_description(&hash, num_bytes))), 130 | new_description: None, 131 | }) 132 | } 133 | } 134 | 135 | Ok(File { 136 | old_path: if left_display_path != right_display_path { 137 | Some(Cow::Owned(left_display_path)) 138 | } else { 139 | None 140 | }, 141 | path: Cow::Owned(right_display_path), 142 | file_mode: left_file_mode, 143 | sections, 144 | }) 145 | } 146 | 147 | pub fn create_merge_file( 148 | filesystem: &dyn Filesystem, 149 | base_path: PathBuf, 150 | left_path: PathBuf, 151 | right_path: PathBuf, 152 | output_path: PathBuf, 153 | ) -> Result, Error> { 154 | let FileInfo { 155 | file_mode: left_file_mode, 156 | contents: left_contents, 157 | } = filesystem.read_file_info(&left_path)?; 158 | let FileInfo { 159 | file_mode: _, 160 | contents: right_contents, 161 | } = filesystem.read_file_info(&right_path)?; 162 | let FileInfo { 163 | file_mode: _, 164 | contents: base_contents, 165 | } = filesystem.read_file_info(&base_path)?; 166 | 167 | let (base_contents, left_contents, right_contents) = 168 | match (base_contents, left_contents, right_contents) { 169 | (FileContents::Absent, _, _) => { 170 | return Err(Error::MissingMergeFile { path: base_path }) 171 | } 172 | (_, FileContents::Absent, _) => { 173 | return Err(Error::MissingMergeFile { path: left_path }) 174 | } 175 | (_, _, FileContents::Absent) => { 176 | return Err(Error::MissingMergeFile { path: right_path }) 177 | } 178 | (FileContents::Binary { .. }, _, _) => { 179 | return Err(Error::BinaryMergeFile { path: base_path }) 180 | } 181 | (_, FileContents::Binary { .. }, _) => { 182 | return Err(Error::BinaryMergeFile { path: left_path }) 183 | } 184 | (_, _, FileContents::Binary { .. }) => { 185 | return Err(Error::BinaryMergeFile { path: right_path }) 186 | } 187 | ( 188 | FileContents::Text { 189 | contents: base_contents, 190 | hash: _, 191 | num_bytes: _, 192 | }, 193 | FileContents::Text { 194 | contents: left_contents, 195 | hash: _, 196 | num_bytes: _, 197 | }, 198 | FileContents::Text { 199 | contents: right_contents, 200 | hash: _, 201 | num_bytes: _, 202 | }, 203 | ) => (base_contents, left_contents, right_contents), 204 | }; 205 | 206 | let sections = create_merge(&base_contents, &left_contents, &right_contents); 207 | Ok(File { 208 | old_path: Some(Cow::Owned(base_path)), 209 | path: Cow::Owned(output_path), 210 | file_mode: left_file_mode, 211 | sections, 212 | }) 213 | } 214 | 215 | fn create_diff(old_contents: &str, new_contents: &str) -> Vec> { 216 | let patch = { 217 | // Set the context length to the maximum number of lines in either file, 218 | // because we will handle abbreviating context ourselves. 219 | let max_lines = old_contents 220 | .lines() 221 | .count() 222 | .max(new_contents.lines().count()); 223 | let mut diff_options = diffy::DiffOptions::new(); 224 | diff_options.set_context_len(max_lines); 225 | diff_options.create_patch(old_contents, new_contents) 226 | }; 227 | 228 | let mut sections = Vec::new(); 229 | for hunk in patch.hunks() { 230 | sections.extend(hunk.lines().iter().fold(Vec::new(), |mut acc, line| { 231 | match line { 232 | diffy::Line::Context(line) => match acc.last_mut() { 233 | Some(Section::Unchanged { lines }) => { 234 | lines.push(Cow::Owned((*line).to_owned())); 235 | } 236 | _ => { 237 | acc.push(Section::Unchanged { 238 | lines: vec![Cow::Owned((*line).to_owned())], 239 | }); 240 | } 241 | }, 242 | diffy::Line::Delete(line) => { 243 | let line = SectionChangedLine { 244 | is_checked: false, 245 | change_type: ChangeType::Removed, 246 | line: Cow::Owned((*line).to_owned()), 247 | }; 248 | match acc.last_mut() { 249 | Some(Section::Changed { lines }) => { 250 | lines.push(line); 251 | } 252 | _ => { 253 | acc.push(Section::Changed { lines: vec![line] }); 254 | } 255 | } 256 | } 257 | diffy::Line::Insert(line) => { 258 | let line = SectionChangedLine { 259 | is_checked: false, 260 | change_type: ChangeType::Added, 261 | line: Cow::Owned((*line).to_owned()), 262 | }; 263 | match acc.last_mut() { 264 | Some(Section::Changed { lines }) => { 265 | lines.push(line); 266 | } 267 | _ => { 268 | acc.push(Section::Changed { lines: vec![line] }); 269 | } 270 | } 271 | } 272 | } 273 | acc 274 | })); 275 | } 276 | sections 277 | } 278 | 279 | fn make_conflict_markers(base: &str, left: &str, right: &str) -> (String, String, String, String) { 280 | let all = [base, left, right].concat(); 281 | let left_char = "<"; 282 | let base_start_char = "|"; 283 | let base_end_char = "="; 284 | let right_char = ">"; 285 | let mut len = 7; 286 | loop { 287 | let left_marker = left_char.repeat(len); 288 | let base_start_marker = base_start_char.repeat(len); 289 | let base_end_marker = base_end_char.repeat(len); 290 | let right_marker = right_char.repeat(len); 291 | if !all.contains(&left_marker) 292 | && !all.contains(&base_start_marker) 293 | && !all.contains(&base_end_marker) 294 | && !all.contains(&right_marker) 295 | { 296 | return ( 297 | left_marker, 298 | base_start_marker, 299 | base_end_marker, 300 | right_marker, 301 | ); 302 | } 303 | len += 1; 304 | } 305 | } 306 | 307 | fn create_merge( 308 | base_contents: &str, 309 | left_contents: &str, 310 | right_contents: &str, 311 | ) -> Vec> { 312 | let (left_marker, base_start_marker, base_end_marker, right_marker) = 313 | make_conflict_markers(base_contents, left_contents, right_contents); 314 | 315 | let mut merge_options = diffy::MergeOptions::new(); 316 | merge_options.set_conflict_marker_length(right_marker.len()); 317 | merge_options.set_conflict_style(diffy::ConflictStyle::Diff3); 318 | let merge = merge_options.merge(base_contents, left_contents, right_contents); 319 | let conflicted_text = match merge { 320 | Ok(_) => return Default::default(), 321 | Err(conflicted_text) => conflicted_text, 322 | }; 323 | 324 | enum MarkerType { 325 | Left, 326 | BaseStart, 327 | BaseEnd, 328 | Right, 329 | } 330 | #[derive(Debug)] 331 | enum State<'a> { 332 | Empty, 333 | Unchanged { 334 | lines: Vec>, 335 | }, 336 | Left { 337 | left_lines: Vec>, 338 | }, 339 | Base { 340 | left_lines: Vec>, 341 | base_lines: Vec>, 342 | }, 343 | Right { 344 | left_lines: Vec>, 345 | base_lines: Vec>, 346 | right_lines: Vec>, 347 | }, 348 | } 349 | 350 | let mut sections = vec![]; 351 | let mut state = State::Empty; 352 | for line in conflicted_text.split_inclusive('\n') { 353 | let marker_type = if line.starts_with(&left_marker) { 354 | Some(MarkerType::Left) 355 | } else if line.starts_with(&base_start_marker) { 356 | Some(MarkerType::BaseStart) 357 | } else if line.starts_with(&base_end_marker) { 358 | Some(MarkerType::BaseEnd) 359 | } else if line.starts_with(&right_marker) { 360 | Some(MarkerType::Right) 361 | } else { 362 | None 363 | }; 364 | 365 | let line = Cow::Owned(line.to_owned()); 366 | let (new_state, new_section) = match (state, marker_type) { 367 | (State::Empty, Some(MarkerType::Left)) => { 368 | let new_state = State::Left { 369 | left_lines: Default::default(), 370 | }; 371 | (new_state, None) 372 | } 373 | (State::Empty, _) => { 374 | let new_state = State::Unchanged { lines: vec![line] }; 375 | (new_state, None) 376 | } 377 | 378 | (State::Unchanged { lines }, Some(MarkerType::Left)) => { 379 | let new_state = State::Left { 380 | left_lines: Default::default(), 381 | }; 382 | let new_section = Section::Unchanged { lines }; 383 | (new_state, Some(new_section)) 384 | } 385 | (State::Unchanged { mut lines }, _) => { 386 | lines.push(line); 387 | let new_state = State::Unchanged { lines }; 388 | (new_state, None) 389 | } 390 | 391 | (State::Left { left_lines }, Some(MarkerType::BaseStart)) => { 392 | let new_state = State::Base { 393 | left_lines, 394 | base_lines: Default::default(), 395 | }; 396 | (new_state, None) 397 | } 398 | (State::Left { mut left_lines }, _) => { 399 | left_lines.push(line); 400 | let new_state = State::Left { left_lines }; 401 | (new_state, None) 402 | } 403 | 404 | ( 405 | State::Base { 406 | left_lines, 407 | base_lines, 408 | }, 409 | Some(MarkerType::BaseEnd), 410 | ) => { 411 | let new_state = State::Right { 412 | left_lines, 413 | base_lines, 414 | right_lines: Default::default(), 415 | }; 416 | (new_state, None) 417 | } 418 | ( 419 | State::Base { 420 | left_lines, 421 | mut base_lines, 422 | }, 423 | _, 424 | ) => { 425 | base_lines.push(line); 426 | let new_state = State::Base { 427 | left_lines, 428 | base_lines, 429 | }; 430 | (new_state, None) 431 | } 432 | 433 | ( 434 | State::Right { 435 | left_lines, 436 | base_lines, 437 | right_lines, 438 | }, 439 | Some(MarkerType::Right), 440 | ) => { 441 | let new_state = State::Empty; 442 | let new_section = Section::Changed { 443 | lines: left_lines 444 | .into_iter() 445 | .map(|line| (line, ChangeType::Added)) 446 | .chain( 447 | base_lines 448 | .into_iter() 449 | .map(|line| (line, ChangeType::Removed)), 450 | ) 451 | .chain( 452 | right_lines 453 | .into_iter() 454 | .map(|line| (line, ChangeType::Added)), 455 | ) 456 | .map(|(line, change_type)| SectionChangedLine { 457 | is_checked: false, 458 | change_type, 459 | line, 460 | }) 461 | .collect(), 462 | }; 463 | (new_state, Some(new_section)) 464 | } 465 | ( 466 | State::Right { 467 | left_lines, 468 | base_lines, 469 | mut right_lines, 470 | }, 471 | _, 472 | ) => { 473 | right_lines.push(line); 474 | let new_state = State::Right { 475 | left_lines, 476 | base_lines, 477 | right_lines, 478 | }; 479 | (new_state, None) 480 | } 481 | }; 482 | 483 | state = new_state; 484 | if let Some(new_section) = new_section { 485 | sections.push(new_section); 486 | } 487 | } 488 | 489 | match state { 490 | State::Empty => {} 491 | State::Unchanged { lines } => { 492 | sections.push(Section::Unchanged { lines }); 493 | } 494 | state @ (State::Left { .. } | State::Base { .. } | State::Right { .. }) => { 495 | warn!(?state, "Diff section not terminated"); 496 | } 497 | } 498 | 499 | sections 500 | } 501 | -------------------------------------------------------------------------------- /scm-diff-editor/src/testing.rs: -------------------------------------------------------------------------------- 1 | //! Testing utilities. 2 | use std::collections::{BTreeMap, BTreeSet}; 3 | use std::io; 4 | use std::path::{Path, PathBuf}; 5 | 6 | use scm_record::{File, FileMode}; 7 | 8 | use crate::{Error, FileContents, FileInfo, Filesystem, Result}; 9 | 10 | /// In-memory filesystem for testing purposes. 11 | #[derive(Debug)] 12 | pub struct TestFilesystem { 13 | files: BTreeMap, 14 | dirs: BTreeSet, 15 | } 16 | 17 | impl TestFilesystem { 18 | /// Construct a new [`TestFilesystem`] with the provided set of files. 19 | pub fn new(files: BTreeMap) -> Self { 20 | let dirs = files 21 | .keys() 22 | .flat_map(|path| path.ancestors().skip(1)) 23 | .map(|path| path.to_owned()) 24 | .collect(); 25 | Self { files, dirs } 26 | } 27 | 28 | fn assert_parent_dir_exists(&self, path: &Path) { 29 | if let Some(parent_dir) = path.parent() { 30 | assert!( 31 | self.dirs.contains(parent_dir), 32 | "parent dir for {path:?} does not exist" 33 | ); 34 | } 35 | } 36 | } 37 | 38 | impl Filesystem for TestFilesystem { 39 | fn read_dir_diff_paths(&self, left: &Path, right: &Path) -> Result> { 40 | let left_files = self 41 | .files 42 | .keys() 43 | .filter_map(|path| path.strip_prefix(left).ok()); 44 | let right_files = self 45 | .files 46 | .keys() 47 | .filter_map(|path| path.strip_prefix(right).ok()); 48 | Ok(left_files 49 | .chain(right_files) 50 | .map(|path| path.to_path_buf()) 51 | .collect()) 52 | } 53 | 54 | fn read_file_info(&self, path: &Path) -> Result { 55 | match self.files.get(path) { 56 | Some(file_info) => Ok(file_info.clone()), 57 | None => match self.dirs.get(path) { 58 | Some(_path) => Err(Error::ReadFile { 59 | path: path.to_owned(), 60 | source: io::Error::new(io::ErrorKind::Other, "is a directory"), 61 | }), 62 | None => Ok(FileInfo { 63 | file_mode: FileMode::Absent, 64 | contents: FileContents::Absent, 65 | }), 66 | }, 67 | } 68 | } 69 | 70 | fn write_file(&mut self, path: &Path, contents: &str) -> Result<()> { 71 | self.assert_parent_dir_exists(path); 72 | self.files.insert(path.to_owned(), file_info(contents)); 73 | Ok(()) 74 | } 75 | 76 | fn copy_file(&mut self, old_path: &Path, new_path: &Path) -> Result<()> { 77 | self.assert_parent_dir_exists(new_path); 78 | let file_info = self.read_file_info(old_path)?; 79 | self.files.insert(new_path.to_owned(), file_info); 80 | Ok(()) 81 | } 82 | 83 | fn remove_file(&mut self, path: &Path) -> Result<()> { 84 | self.files.remove(path); 85 | Ok(()) 86 | } 87 | 88 | fn create_dir_all(&mut self, path: &Path) -> Result<()> { 89 | self.dirs.insert(path.to_owned()); 90 | Ok(()) 91 | } 92 | } 93 | 94 | /// Helper function to create a `FileInfo` object containing the provided file 95 | /// contents and a default hash and file mode. 96 | pub fn file_info(contents: impl Into) -> FileInfo { 97 | let contents = contents.into(); 98 | let num_bytes = contents.len().try_into().unwrap(); 99 | FileInfo { 100 | file_mode: FileMode::Unix(0o100644), 101 | contents: FileContents::Text { 102 | contents, 103 | hash: "abc123".to_string(), 104 | num_bytes, 105 | }, 106 | } 107 | } 108 | 109 | /// Set all checkboxes in the UI. 110 | pub fn select_all(files: &mut [File]) { 111 | for file in files { 112 | file.set_checked(true); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /scm-diff-editor/tests/test_scm_diff_editor.rs: -------------------------------------------------------------------------------- 1 | use std::path::PathBuf; 2 | 3 | use insta::assert_debug_snapshot; 4 | use maplit::btreemap; 5 | 6 | use scm_diff_editor::testing::{file_info, select_all, TestFilesystem}; 7 | use scm_diff_editor::{apply_changes, process_opts, DiffContext, Opts, Result}; 8 | use scm_record::{RecordState, Section}; 9 | 10 | #[test] 11 | fn test_diff() -> Result<()> { 12 | let mut filesystem = TestFilesystem::new(btreemap! { 13 | PathBuf::from("left") => file_info("\ 14 | foo 15 | common1 16 | common2 17 | bar 18 | "), 19 | PathBuf::from("right") => file_info("\ 20 | qux1 21 | common1 22 | common2 23 | qux2 24 | "), 25 | }); 26 | let DiffContext { 27 | mut files, 28 | write_root, 29 | } = process_opts( 30 | &filesystem, 31 | &Opts { 32 | dir_diff: false, 33 | left: PathBuf::from("left"), 34 | right: PathBuf::from("right"), 35 | base: None, 36 | output: None, 37 | read_only: false, 38 | dry_run: false, 39 | }, 40 | )?; 41 | assert_debug_snapshot!(files, @r###" 42 | [ 43 | File { 44 | old_path: Some( 45 | "left", 46 | ), 47 | path: "right", 48 | file_mode: Unix( 49 | 33188, 50 | ), 51 | sections: [ 52 | Changed { 53 | lines: [ 54 | SectionChangedLine { 55 | is_checked: false, 56 | change_type: Removed, 57 | line: "foo\n", 58 | }, 59 | SectionChangedLine { 60 | is_checked: false, 61 | change_type: Added, 62 | line: "qux1\n", 63 | }, 64 | ], 65 | }, 66 | Unchanged { 67 | lines: [ 68 | "common1\n", 69 | "common2\n", 70 | ], 71 | }, 72 | Changed { 73 | lines: [ 74 | SectionChangedLine { 75 | is_checked: false, 76 | change_type: Removed, 77 | line: "bar\n", 78 | }, 79 | SectionChangedLine { 80 | is_checked: false, 81 | change_type: Added, 82 | line: "qux2\n", 83 | }, 84 | ], 85 | }, 86 | ], 87 | }, 88 | ] 89 | "###); 90 | 91 | select_all(&mut files); 92 | apply_changes( 93 | &mut filesystem, 94 | &write_root, 95 | RecordState { 96 | is_read_only: false, 97 | commits: Default::default(), 98 | files, 99 | }, 100 | )?; 101 | insta::assert_debug_snapshot!(filesystem, @r###" 102 | TestFilesystem { 103 | files: { 104 | "left": FileInfo { 105 | file_mode: Unix( 106 | 33188, 107 | ), 108 | contents: Text { 109 | contents: "foo\ncommon1\ncommon2\nbar\n", 110 | hash: "abc123", 111 | num_bytes: 24, 112 | }, 113 | }, 114 | "right": FileInfo { 115 | file_mode: Unix( 116 | 33188, 117 | ), 118 | contents: Text { 119 | contents: "qux1\ncommon1\ncommon2\nqux2\n", 120 | hash: "abc123", 121 | num_bytes: 26, 122 | }, 123 | }, 124 | }, 125 | dirs: { 126 | "", 127 | }, 128 | } 129 | "###); 130 | 131 | Ok(()) 132 | } 133 | 134 | #[test] 135 | fn test_diff_no_changes() -> Result<()> { 136 | let mut filesystem = TestFilesystem::new(btreemap! { 137 | PathBuf::from("left") => file_info("\ 138 | foo 139 | common1 140 | common2 141 | bar 142 | "), 143 | PathBuf::from("right") => file_info("\ 144 | qux1 145 | common1 146 | common2 147 | qux2 148 | "), 149 | }); 150 | let DiffContext { files, write_root } = process_opts( 151 | &filesystem, 152 | &Opts { 153 | dir_diff: false, 154 | left: PathBuf::from("left"), 155 | right: PathBuf::from("right"), 156 | base: None, 157 | output: None, 158 | read_only: false, 159 | dry_run: false, 160 | }, 161 | )?; 162 | 163 | apply_changes( 164 | &mut filesystem, 165 | &write_root, 166 | RecordState { 167 | is_read_only: false, 168 | commits: Default::default(), 169 | files, 170 | }, 171 | )?; 172 | insta::assert_debug_snapshot!(filesystem, @r###" 173 | TestFilesystem { 174 | files: { 175 | "left": FileInfo { 176 | file_mode: Unix( 177 | 33188, 178 | ), 179 | contents: Text { 180 | contents: "foo\ncommon1\ncommon2\nbar\n", 181 | hash: "abc123", 182 | num_bytes: 24, 183 | }, 184 | }, 185 | "right": FileInfo { 186 | file_mode: Unix( 187 | 33188, 188 | ), 189 | contents: Text { 190 | contents: "foo\ncommon1\ncommon2\nbar\n", 191 | hash: "abc123", 192 | num_bytes: 24, 193 | }, 194 | }, 195 | }, 196 | dirs: { 197 | "", 198 | }, 199 | } 200 | "###); 201 | 202 | Ok(()) 203 | } 204 | 205 | #[test] 206 | fn test_diff_absent_left() -> Result<()> { 207 | let mut filesystem = TestFilesystem::new(btreemap! { 208 | PathBuf::from("right") => file_info("right\n"), 209 | }); 210 | let DiffContext { 211 | mut files, 212 | write_root, 213 | } = process_opts( 214 | &filesystem, 215 | &Opts { 216 | dir_diff: false, 217 | left: PathBuf::from("left"), 218 | right: PathBuf::from("right"), 219 | base: None, 220 | output: None, 221 | read_only: false, 222 | dry_run: false, 223 | }, 224 | )?; 225 | assert_debug_snapshot!(files, @r###" 226 | [ 227 | File { 228 | old_path: Some( 229 | "left", 230 | ), 231 | path: "right", 232 | file_mode: Absent, 233 | sections: [ 234 | FileMode { 235 | is_checked: false, 236 | mode: Unix( 237 | 33188, 238 | ), 239 | }, 240 | Changed { 241 | lines: [ 242 | SectionChangedLine { 243 | is_checked: false, 244 | change_type: Added, 245 | line: "right\n", 246 | }, 247 | ], 248 | }, 249 | ], 250 | }, 251 | ] 252 | "###); 253 | 254 | select_all(&mut files); 255 | apply_changes( 256 | &mut filesystem, 257 | &write_root, 258 | RecordState { 259 | is_read_only: false, 260 | commits: Default::default(), 261 | files, 262 | }, 263 | )?; 264 | insta::assert_debug_snapshot!(filesystem, @r###" 265 | TestFilesystem { 266 | files: { 267 | "right": FileInfo { 268 | file_mode: Unix( 269 | 33188, 270 | ), 271 | contents: Text { 272 | contents: "right\n", 273 | hash: "abc123", 274 | num_bytes: 6, 275 | }, 276 | }, 277 | }, 278 | dirs: { 279 | "", 280 | }, 281 | } 282 | "###); 283 | 284 | Ok(()) 285 | } 286 | 287 | #[test] 288 | fn test_diff_absent_right() -> Result<()> { 289 | let mut filesystem = TestFilesystem::new(btreemap! { 290 | PathBuf::from("left") => file_info("left\n"), 291 | }); 292 | let DiffContext { 293 | mut files, 294 | write_root, 295 | } = process_opts( 296 | &filesystem, 297 | &Opts { 298 | dir_diff: false, 299 | left: PathBuf::from("left"), 300 | right: PathBuf::from("right"), 301 | base: None, 302 | output: None, 303 | read_only: false, 304 | dry_run: false, 305 | }, 306 | )?; 307 | assert_debug_snapshot!(files, @r###" 308 | [ 309 | File { 310 | old_path: Some( 311 | "left", 312 | ), 313 | path: "right", 314 | file_mode: Unix( 315 | 33188, 316 | ), 317 | sections: [ 318 | FileMode { 319 | is_checked: false, 320 | mode: Absent, 321 | }, 322 | Changed { 323 | lines: [ 324 | SectionChangedLine { 325 | is_checked: false, 326 | change_type: Removed, 327 | line: "left\n", 328 | }, 329 | ], 330 | }, 331 | ], 332 | }, 333 | ] 334 | "###); 335 | 336 | select_all(&mut files); 337 | apply_changes( 338 | &mut filesystem, 339 | &write_root, 340 | RecordState { 341 | is_read_only: false, 342 | commits: Default::default(), 343 | files, 344 | }, 345 | )?; 346 | insta::assert_debug_snapshot!(filesystem, @r###" 347 | TestFilesystem { 348 | files: { 349 | "left": FileInfo { 350 | file_mode: Unix( 351 | 33188, 352 | ), 353 | contents: Text { 354 | contents: "left\n", 355 | hash: "abc123", 356 | num_bytes: 5, 357 | }, 358 | }, 359 | }, 360 | dirs: { 361 | "", 362 | }, 363 | } 364 | "###); 365 | 366 | Ok(()) 367 | } 368 | 369 | #[test] 370 | fn test_reject_diff_non_files() -> Result<()> { 371 | let filesystem = TestFilesystem::new(btreemap! { 372 | PathBuf::from("left/foo") => file_info("left\n"), 373 | PathBuf::from("right/foo") => file_info("right\n"), 374 | }); 375 | let result = process_opts( 376 | &filesystem, 377 | &Opts { 378 | dir_diff: false, 379 | left: PathBuf::from("left"), 380 | right: PathBuf::from("right"), 381 | base: None, 382 | output: None, 383 | read_only: false, 384 | dry_run: false, 385 | }, 386 | ); 387 | insta::assert_debug_snapshot!(result, @r###" 388 | Err( 389 | ReadFile { 390 | path: "left", 391 | source: Custom { 392 | kind: Other, 393 | error: "is a directory", 394 | }, 395 | }, 396 | ) 397 | "###); 398 | 399 | Ok(()) 400 | } 401 | 402 | #[test] 403 | fn test_diff_files_in_subdirectories() -> Result<()> { 404 | let mut filesystem = TestFilesystem::new(btreemap! { 405 | PathBuf::from("left/foo") => file_info("left contents\n"), 406 | PathBuf::from("right/foo") => file_info("right contents\n"), 407 | }); 408 | 409 | let DiffContext { files, write_root } = process_opts( 410 | &filesystem, 411 | &Opts { 412 | dir_diff: false, 413 | left: PathBuf::from("left/foo"), 414 | right: PathBuf::from("right/foo"), 415 | base: None, 416 | output: None, 417 | read_only: false, 418 | dry_run: false, 419 | }, 420 | )?; 421 | 422 | apply_changes( 423 | &mut filesystem, 424 | &write_root, 425 | RecordState { 426 | is_read_only: false, 427 | commits: Default::default(), 428 | files, 429 | }, 430 | )?; 431 | assert_debug_snapshot!(filesystem, @r###" 432 | TestFilesystem { 433 | files: { 434 | "left/foo": FileInfo { 435 | file_mode: Unix( 436 | 33188, 437 | ), 438 | contents: Text { 439 | contents: "left contents\n", 440 | hash: "abc123", 441 | num_bytes: 14, 442 | }, 443 | }, 444 | "right/foo": FileInfo { 445 | file_mode: Unix( 446 | 33188, 447 | ), 448 | contents: Text { 449 | contents: "left contents\n", 450 | hash: "abc123", 451 | num_bytes: 14, 452 | }, 453 | }, 454 | }, 455 | dirs: { 456 | "", 457 | "left", 458 | "right", 459 | }, 460 | } 461 | "###); 462 | 463 | Ok(()) 464 | } 465 | 466 | #[test] 467 | fn test_dir_diff_no_changes() -> Result<()> { 468 | let mut filesystem = TestFilesystem::new(btreemap! { 469 | PathBuf::from("left/foo") => file_info("left contents\n"), 470 | PathBuf::from("right/foo") => file_info("right contents\n"), 471 | }); 472 | 473 | let DiffContext { files, write_root } = process_opts( 474 | &filesystem, 475 | &Opts { 476 | dir_diff: false, 477 | left: PathBuf::from("left/foo"), 478 | right: PathBuf::from("right/foo"), 479 | base: None, 480 | output: None, 481 | read_only: false, 482 | dry_run: false, 483 | }, 484 | )?; 485 | 486 | apply_changes( 487 | &mut filesystem, 488 | &write_root, 489 | RecordState { 490 | is_read_only: false, 491 | commits: Default::default(), 492 | files, 493 | }, 494 | )?; 495 | assert_debug_snapshot!(filesystem, @r###" 496 | TestFilesystem { 497 | files: { 498 | "left/foo": FileInfo { 499 | file_mode: Unix( 500 | 33188, 501 | ), 502 | contents: Text { 503 | contents: "left contents\n", 504 | hash: "abc123", 505 | num_bytes: 14, 506 | }, 507 | }, 508 | "right/foo": FileInfo { 509 | file_mode: Unix( 510 | 33188, 511 | ), 512 | contents: Text { 513 | contents: "left contents\n", 514 | hash: "abc123", 515 | num_bytes: 14, 516 | }, 517 | }, 518 | }, 519 | dirs: { 520 | "", 521 | "left", 522 | "right", 523 | }, 524 | } 525 | "###); 526 | 527 | Ok(()) 528 | } 529 | 530 | #[test] 531 | fn test_create_merge() -> Result<()> { 532 | let base_contents = "\ 533 | Hello world 1 534 | Hello world 2 535 | Hello world 3 536 | Hello world 4 537 | "; 538 | let left_contents = "\ 539 | Hello world 1 540 | Hello world 2 541 | Hello world L 542 | Hello world 4 543 | "; 544 | let right_contents = "\ 545 | Hello world 1 546 | Hello world 2 547 | Hello world R 548 | Hello world 4 549 | "; 550 | let mut filesystem = TestFilesystem::new(btreemap! { 551 | PathBuf::from("base") => file_info(base_contents), 552 | PathBuf::from("left") => file_info(left_contents), 553 | PathBuf::from("right") => file_info(right_contents), 554 | }); 555 | 556 | let DiffContext { 557 | mut files, 558 | write_root, 559 | } = process_opts( 560 | &filesystem, 561 | &Opts { 562 | dir_diff: false, 563 | left: "left".into(), 564 | right: "right".into(), 565 | read_only: false, 566 | dry_run: false, 567 | base: Some("base".into()), 568 | output: Some("output".into()), 569 | }, 570 | )?; 571 | insta::assert_debug_snapshot!(files, @r###" 572 | [ 573 | File { 574 | old_path: Some( 575 | "base", 576 | ), 577 | path: "output", 578 | file_mode: Unix( 579 | 33188, 580 | ), 581 | sections: [ 582 | Unchanged { 583 | lines: [ 584 | "Hello world 1\n", 585 | "Hello world 2\n", 586 | ], 587 | }, 588 | Changed { 589 | lines: [ 590 | SectionChangedLine { 591 | is_checked: false, 592 | change_type: Added, 593 | line: "Hello world L\n", 594 | }, 595 | SectionChangedLine { 596 | is_checked: false, 597 | change_type: Removed, 598 | line: "Hello world 3\n", 599 | }, 600 | SectionChangedLine { 601 | is_checked: false, 602 | change_type: Added, 603 | line: "Hello world R\n", 604 | }, 605 | ], 606 | }, 607 | Unchanged { 608 | lines: [ 609 | "Hello world 4\n", 610 | ], 611 | }, 612 | ], 613 | }, 614 | ] 615 | "###); 616 | 617 | select_all(&mut files); 618 | apply_changes( 619 | &mut filesystem, 620 | &write_root, 621 | RecordState { 622 | is_read_only: false, 623 | commits: Default::default(), 624 | files, 625 | }, 626 | )?; 627 | 628 | assert_debug_snapshot!(filesystem, @r###" 629 | TestFilesystem { 630 | files: { 631 | "base": FileInfo { 632 | file_mode: Unix( 633 | 33188, 634 | ), 635 | contents: Text { 636 | contents: "Hello world 1\nHello world 2\nHello world 3\nHello world 4\n", 637 | hash: "abc123", 638 | num_bytes: 56, 639 | }, 640 | }, 641 | "left": FileInfo { 642 | file_mode: Unix( 643 | 33188, 644 | ), 645 | contents: Text { 646 | contents: "Hello world 1\nHello world 2\nHello world L\nHello world 4\n", 647 | hash: "abc123", 648 | num_bytes: 56, 649 | }, 650 | }, 651 | "output": FileInfo { 652 | file_mode: Unix( 653 | 33188, 654 | ), 655 | contents: Text { 656 | contents: "Hello world 1\nHello world 2\nHello world L\nHello world R\nHello world 4\n", 657 | hash: "abc123", 658 | num_bytes: 70, 659 | }, 660 | }, 661 | "right": FileInfo { 662 | file_mode: Unix( 663 | 33188, 664 | ), 665 | contents: Text { 666 | contents: "Hello world 1\nHello world 2\nHello world R\nHello world 4\n", 667 | hash: "abc123", 668 | num_bytes: 56, 669 | }, 670 | }, 671 | }, 672 | dirs: { 673 | "", 674 | }, 675 | } 676 | "###); 677 | 678 | Ok(()) 679 | } 680 | 681 | #[test] 682 | fn test_new_file() -> Result<()> { 683 | let new_file_contents = "\ 684 | Hello world 1 685 | Hello world 2 686 | "; 687 | let mut filesystem = TestFilesystem::new(btreemap! { 688 | PathBuf::from("right") => file_info(new_file_contents), 689 | }); 690 | 691 | let DiffContext { 692 | mut files, 693 | write_root, 694 | } = process_opts( 695 | &filesystem, 696 | &Opts { 697 | dir_diff: false, 698 | left: "left".into(), 699 | right: "right".into(), 700 | read_only: false, 701 | dry_run: false, 702 | base: None, 703 | output: None, 704 | }, 705 | )?; 706 | insta::assert_debug_snapshot!(files, @r###" 707 | [ 708 | File { 709 | old_path: Some( 710 | "left", 711 | ), 712 | path: "right", 713 | file_mode: Absent, 714 | sections: [ 715 | FileMode { 716 | is_checked: false, 717 | mode: Unix( 718 | 33188, 719 | ), 720 | }, 721 | Changed { 722 | lines: [ 723 | SectionChangedLine { 724 | is_checked: false, 725 | change_type: Added, 726 | line: "Hello world 1\n", 727 | }, 728 | SectionChangedLine { 729 | is_checked: false, 730 | change_type: Added, 731 | line: "Hello world 2\n", 732 | }, 733 | ], 734 | }, 735 | ], 736 | }, 737 | ] 738 | "###); 739 | 740 | // Select no changes from new file. 741 | apply_changes( 742 | &mut filesystem, 743 | &write_root, 744 | RecordState { 745 | is_read_only: false, 746 | commits: Default::default(), 747 | files: files.clone(), 748 | }, 749 | )?; 750 | insta::assert_debug_snapshot!(filesystem, @r###" 751 | TestFilesystem { 752 | files: {}, 753 | dirs: { 754 | "", 755 | }, 756 | } 757 | "###); 758 | 759 | // Select all changes from new file. 760 | select_all(&mut files); 761 | apply_changes( 762 | &mut filesystem, 763 | &write_root, 764 | RecordState { 765 | is_read_only: false, 766 | commits: Default::default(), 767 | files: files.clone(), 768 | }, 769 | )?; 770 | insta::assert_debug_snapshot!(filesystem, @r###" 771 | TestFilesystem { 772 | files: { 773 | "right": FileInfo { 774 | file_mode: Unix( 775 | 33188, 776 | ), 777 | contents: Text { 778 | contents: "Hello world 1\nHello world 2\n", 779 | hash: "abc123", 780 | num_bytes: 28, 781 | }, 782 | }, 783 | }, 784 | dirs: { 785 | "", 786 | }, 787 | } 788 | "###); 789 | 790 | // Select only some changes from new file. 791 | match files[0].sections.get_mut(1).unwrap() { 792 | Section::Changed { ref mut lines } => lines[0].is_checked = false, 793 | _ => panic!("Expected changed section"), 794 | } 795 | apply_changes( 796 | &mut filesystem, 797 | &write_root, 798 | RecordState { 799 | is_read_only: false, 800 | commits: Default::default(), 801 | files: files.clone(), 802 | }, 803 | )?; 804 | insta::assert_debug_snapshot!(filesystem, @r###" 805 | TestFilesystem { 806 | files: { 807 | "right": FileInfo { 808 | file_mode: Unix( 809 | 33188, 810 | ), 811 | contents: Text { 812 | contents: "Hello world 2\n", 813 | hash: "abc123", 814 | num_bytes: 14, 815 | }, 816 | }, 817 | }, 818 | dirs: { 819 | "", 820 | }, 821 | } 822 | "###); 823 | 824 | Ok(()) 825 | } 826 | -------------------------------------------------------------------------------- /scm-record/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["Waleed Khan "] 3 | description = "UI component to interactively select changes to include in a commit." 4 | edition = "2021" 5 | license = "MIT OR Apache-2.0" 6 | name = "scm-record" 7 | repository = "https://github.com/arxanas/scm-record" 8 | version = "0.8.0" 9 | 10 | # Main consumers to consider: 11 | # - git-branchless: https://github.com/arxanas/git-branchless/blob/master/Cargo.toml 12 | # - jj: https://github.com/martinvonz/jj/blob/main/Cargo.toml 13 | rust-version = "1.74" 14 | 15 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 16 | 17 | [features] 18 | debug = ["serde"] 19 | default = ["debug"] 20 | serde = ["dep:serde", "dep:serde_json"] 21 | 22 | [dependencies] 23 | cassowary = "0.3" 24 | crossterm = "0.28" 25 | num-traits = "0.2" 26 | thiserror = "2.0" 27 | tracing = "0.1" 28 | ratatui = "0.29.0" 29 | unicode-width = "0.2" 30 | 31 | # Features: serde 32 | serde = { version = "1.0", features = ["serde_derive"], optional = true } 33 | serde_json = { version = "1.0", optional = true } 34 | 35 | [dev-dependencies] 36 | assert_matches = "1.5" 37 | criterion = "0.5" 38 | insta = "1.43" 39 | proptest = "1.6.0" 40 | serde_json = "1.0" 41 | 42 | [[bench]] 43 | name = "benches" 44 | harness = false 45 | 46 | [package.metadata.release] 47 | pre-release-replacements = [ 48 | { file = "../CHANGELOG.md", search = "Unreleased", replace = "{{version}}", min = 1 }, 49 | { file = "../CHANGELOG.md", search = "ReleaseDate", replace = "{{date}}", min = 1 }, 50 | { file = "../CHANGELOG.md", search = "", replace = "\n## [Unreleased] - ReleaseDate\n", exactly = 1 }, 51 | ] 52 | -------------------------------------------------------------------------------- /scm-record/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /scm-record/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Individual contributors 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /scm-record/benches/benches.rs: -------------------------------------------------------------------------------- 1 | use std::{borrow::Cow, path::Path}; 2 | 3 | use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; 4 | 5 | use scm_record::{ 6 | helpers::TestingInput, ChangeType, Event, File, FileMode, RecordState, Recorder, Section, 7 | SectionChangedLine, 8 | }; 9 | 10 | fn bench_record(c: &mut Criterion) { 11 | c.bench_function("scm_record: toggle line", |b| { 12 | let before_line = SectionChangedLine { 13 | line: Cow::Borrowed("foo"), 14 | is_checked: false, 15 | change_type: ChangeType::Removed, 16 | }; 17 | let after_line = SectionChangedLine { 18 | line: Cow::Borrowed("foo"), 19 | is_checked: false, 20 | change_type: ChangeType::Added, 21 | }; 22 | let record_state = RecordState { 23 | is_read_only: false, 24 | commits: Default::default(), 25 | files: vec![File { 26 | old_path: None, 27 | path: Cow::Borrowed(Path::new("foo")), 28 | file_mode: FileMode::FILE_DEFAULT, 29 | sections: vec![Section::Changed { 30 | lines: [vec![before_line; 1000], vec![after_line; 1000]].concat(), 31 | }], 32 | }], 33 | }; 34 | let mut input = TestingInput::new( 35 | 80, 36 | 24, 37 | [Event::ToggleItem, Event::ToggleItem, Event::QuitAccept], 38 | ); 39 | b.iter_batched( 40 | || record_state.clone(), 41 | |record_state| { 42 | let recorder = Recorder::new(record_state, &mut input); 43 | recorder.run() 44 | }, 45 | BatchSize::PerIteration, 46 | ) 47 | }); 48 | } 49 | 50 | criterion_group!( 51 | name = benches; 52 | config = Criterion::default().sample_size(10); 53 | targets = bench_record, 54 | ); 55 | criterion_main!(benches); 56 | -------------------------------------------------------------------------------- /scm-record/examples/load_json.rs: -------------------------------------------------------------------------------- 1 | #![warn(clippy::all, clippy::as_conversions)] 2 | #![allow(clippy::too_many_arguments)] 3 | 4 | use std::path::Path; 5 | 6 | use scm_record::{ 7 | helpers::CrosstermInput, FileMode, RecordError, RecordState, Recorder, SelectedChanges, 8 | SelectedContents, 9 | }; 10 | 11 | #[cfg(feature = "serde")] 12 | fn load_state(path: impl AsRef) -> RecordState<'static> { 13 | let json_file = std::fs::File::open(path).expect("opening JSON file"); 14 | serde_json::from_reader(json_file).expect("deserializing state") 15 | } 16 | 17 | #[cfg(not(feature = "serde"))] 18 | fn load_state(_path: impl AsRef) -> RecordState<'static> { 19 | panic!("load_json example requires `serde` feature") 20 | } 21 | 22 | fn main() { 23 | let args: Vec = std::env::args().collect(); 24 | let json_filename = args.get(1).expect("expected JSON dump as first argument"); 25 | let record_state: RecordState = load_state(json_filename); 26 | 27 | let mut input = CrosstermInput; 28 | let recorder = Recorder::new(record_state, &mut input); 29 | let result = recorder.run(); 30 | match result { 31 | Ok(result) => { 32 | let RecordState { 33 | is_read_only: _, 34 | commits: _, 35 | files, 36 | } = result; 37 | for file in files { 38 | println!("--- Path {:?} final lines: ---", file.path); 39 | let (selected, _unselected) = file.get_selected_contents(); 40 | 41 | let SelectedChanges { 42 | contents, 43 | file_mode, 44 | } = selected; 45 | 46 | if file_mode == FileMode::Absent { 47 | println!(""); 48 | } else { 49 | print!( 50 | "{}", 51 | match contents { 52 | SelectedContents::Unchanged => "".to_string(), 53 | SelectedContents::Binary { 54 | old_description: _, 55 | new_description: None, 56 | } => "\n".to_string(), 57 | SelectedContents::Binary { 58 | old_description: _, 59 | new_description: Some(description), 60 | } => format!("\n"), 61 | SelectedContents::Text { contents } => contents.clone(), 62 | } 63 | ); 64 | } 65 | } 66 | } 67 | Err(RecordError::Cancelled) => println!("Cancelled!\n"), 68 | Err(err) => { 69 | println!("Error: {err}"); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /scm-record/examples/static_contents.rs: -------------------------------------------------------------------------------- 1 | #![warn(clippy::all, clippy::as_conversions)] 2 | #![allow(clippy::too_many_arguments)] 3 | 4 | use std::borrow::Cow; 5 | use std::path::Path; 6 | 7 | use scm_record::{ 8 | helpers::CrosstermInput, ChangeType, File, FileMode, RecordError, RecordState, Recorder, 9 | Section, SectionChangedLine, SelectedChanges, SelectedContents, 10 | }; 11 | 12 | fn main() { 13 | let files = vec![ 14 | File { 15 | old_path: None, 16 | path: Cow::Borrowed(Path::new("foo/bar")), 17 | file_mode: FileMode::FILE_DEFAULT, 18 | sections: vec![ 19 | Section::Unchanged { 20 | lines: std::iter::repeat(Cow::Borrowed("this is some text\n")) 21 | .take(20) 22 | .collect(), 23 | }, 24 | Section::Changed { 25 | lines: vec![ 26 | SectionChangedLine { 27 | is_checked: true, 28 | change_type: ChangeType::Removed, 29 | line: Cow::Borrowed("before text 1\n"), 30 | }, 31 | SectionChangedLine { 32 | is_checked: true, 33 | change_type: ChangeType::Removed, 34 | line: Cow::Borrowed("before text 2\n"), 35 | }, 36 | SectionChangedLine { 37 | is_checked: true, 38 | change_type: ChangeType::Added, 39 | 40 | line: Cow::Borrowed("after text 1\n"), 41 | }, 42 | SectionChangedLine { 43 | is_checked: false, 44 | change_type: ChangeType::Added, 45 | line: Cow::Borrowed("after text 2\n"), 46 | }, 47 | ], 48 | }, 49 | Section::Unchanged { 50 | lines: vec![Cow::Borrowed("this is some trailing text\n")], 51 | }, 52 | ], 53 | }, 54 | File { 55 | old_path: None, 56 | path: Cow::Borrowed(Path::new("baz")), 57 | file_mode: FileMode::FILE_DEFAULT, 58 | sections: vec![ 59 | Section::Unchanged { 60 | lines: vec![ 61 | Cow::Borrowed("Some leading text 1\n"), 62 | Cow::Borrowed("Some leading text 2\n"), 63 | ], 64 | }, 65 | Section::Changed { 66 | lines: vec![ 67 | SectionChangedLine { 68 | is_checked: true, 69 | change_type: ChangeType::Removed, 70 | line: Cow::Borrowed("before text 1\n"), 71 | }, 72 | SectionChangedLine { 73 | is_checked: true, 74 | change_type: ChangeType::Removed, 75 | line: Cow::Borrowed("before text 2\n"), 76 | }, 77 | SectionChangedLine { 78 | is_checked: true, 79 | change_type: ChangeType::Added, 80 | line: Cow::Borrowed("after text 1\n"), 81 | }, 82 | SectionChangedLine { 83 | is_checked: true, 84 | change_type: ChangeType::Added, 85 | line: Cow::Borrowed("after text 2\n"), 86 | }, 87 | ], 88 | }, 89 | Section::Unchanged { 90 | lines: vec![Cow::Borrowed("this is some trailing text")], 91 | }, 92 | ], 93 | }, 94 | ]; 95 | let record_state = RecordState { 96 | is_read_only: false, 97 | commits: Default::default(), 98 | files, 99 | }; 100 | let mut input = CrosstermInput; 101 | let recorder = Recorder::new(record_state, &mut input); 102 | let result = recorder.run(); 103 | match result { 104 | Ok(result) => { 105 | let RecordState { 106 | is_read_only: _, 107 | commits: _, 108 | files, 109 | } = result; 110 | for file in files { 111 | println!("--- Path {:?} final lines: ---", file.path); 112 | let (selected, _unselected) = file.get_selected_contents(); 113 | 114 | let SelectedChanges { 115 | contents, 116 | file_mode, 117 | } = selected; 118 | 119 | if file_mode == FileMode::Absent { 120 | println!(""); 121 | } else { 122 | print!( 123 | "{}", 124 | match contents { 125 | SelectedContents::Binary { 126 | old_description: _, 127 | new_description: None, 128 | } => "\n".to_string(), 129 | SelectedContents::Binary { 130 | old_description: _, 131 | new_description: Some(description), 132 | } => format!("\n"), 133 | SelectedContents::Text { contents } => contents.clone(), 134 | SelectedContents::Unchanged => "".to_string(), 135 | } 136 | ); 137 | } 138 | } 139 | } 140 | Err(RecordError::Cancelled) => println!("Cancelled!\n"), 141 | Err(err) => { 142 | println!("Error: {err}"); 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /scm-record/proptest-regressions/ui.txt: -------------------------------------------------------------------------------- 1 | # Seeds for failure cases proptest has generated in the past. It is 2 | # automatically read and these particular cases re-run before any 3 | # novel cases are generated. 4 | # 5 | # It is recommended to check this file in to source control so that 6 | # everyone who runs the test benefits from these saved cases. 7 | cc 4ad364b7a4bfbb4cf16c5dac6dcfbb3e014356930cd855d76f110aed3856a9ed # shrinks to line = "¡" 8 | cc b7d37d182f61b73b6ef4fcd469caff5ccd21379903ce66bd02e14e1abc9344dd # shrinks to line = "\t" 9 | cc de75c8131f6e198916f45226f06c6a09f6cf805a464bbf6954b1a3b03b0c7940 # shrinks to line = "\0" 10 | cc e1eedb87f79680aebd62a9f3f94e31c009e12ab13b855695eb0ce793f43d29aa 11 | -------------------------------------------------------------------------------- /scm-record/src/consts.rs: -------------------------------------------------------------------------------- 1 | //! Special runtime variables. 2 | 3 | /// Upon launch, write a serialized version of the UI state to the file named 4 | /// [`DUMP_UI_STATE_FILENAME`] in the current directory. Only works if compiled 5 | /// with the `debug` feature. 6 | pub const ENV_VAR_DUMP_UI_STATE: &str = "SCM_RECORD_DUMP_UI_STATE"; 7 | 8 | /// The filename to write to for [`ENV_VAR_DUMP_UI_STATE`]. 9 | pub const DUMP_UI_STATE_FILENAME: &str = "scm_record_ui_state.json"; 10 | 11 | /// Render a debug pane over the file. Only works if compiled with the `debug` 12 | /// feature. 13 | pub const ENV_VAR_DEBUG_UI: &str = "SCM_RECORD_DEBUG_UI"; 14 | -------------------------------------------------------------------------------- /scm-record/src/helpers.rs: -------------------------------------------------------------------------------- 1 | //! Helper functions for rendering UI components. 2 | 3 | use std::{collections::VecDeque, time::Duration}; 4 | 5 | use crate::{Event, RecordError, RecordInput, TerminalKind}; 6 | 7 | /// Generate a one-line description of a binary file change. 8 | pub fn make_binary_description(hash: &str, num_bytes: u64) -> String { 9 | format!("{} ({} bytes)", hash, num_bytes) 10 | } 11 | 12 | /// Reads input events from the terminal using `crossterm`. 13 | /// 14 | /// Its default implementation of `edit_commit_message` returns the provided 15 | /// message unchanged. 16 | pub struct CrosstermInput; 17 | 18 | impl RecordInput for CrosstermInput { 19 | fn terminal_kind(&self) -> TerminalKind { 20 | TerminalKind::Crossterm 21 | } 22 | 23 | fn next_events(&mut self) -> Result, RecordError> { 24 | // Ensure we block for at least one event. 25 | let first_event = crossterm::event::read().map_err(RecordError::ReadInput)?; 26 | let mut events = vec![first_event.into()]; 27 | // Some events, like scrolling, are generated more quickly than 28 | // we can render the UI. In those cases, batch up all available 29 | // events and process them before the next render. 30 | while crossterm::event::poll(Duration::ZERO).map_err(RecordError::ReadInput)? { 31 | let event = crossterm::event::read().map_err(RecordError::ReadInput)?; 32 | events.push(event.into()); 33 | } 34 | Ok(events) 35 | } 36 | 37 | fn edit_commit_message(&mut self, message: &str) -> Result { 38 | Ok(message.to_owned()) 39 | } 40 | } 41 | 42 | /// Reads events from the provided sequence of events. 43 | pub struct TestingInput { 44 | /// The width of the virtual terminal in columns. 45 | pub width: usize, 46 | 47 | /// The height of the virtual terminal in columns. 48 | pub height: usize, 49 | 50 | /// The sequence of events to emit. 51 | pub events: Box>, 52 | 53 | /// Commit messages to use when the commit editor is opened. 54 | pub commit_messages: VecDeque, 55 | } 56 | 57 | impl TestingInput { 58 | /// Helper function to construct a `TestingInput`. 59 | pub fn new( 60 | width: usize, 61 | height: usize, 62 | events: impl IntoIterator + 'static, 63 | ) -> Self { 64 | Self { 65 | width, 66 | height, 67 | events: Box::new(events.into_iter()), 68 | commit_messages: Default::default(), 69 | } 70 | } 71 | } 72 | 73 | impl RecordInput for TestingInput { 74 | fn terminal_kind(&self) -> TerminalKind { 75 | let Self { 76 | width, 77 | height, 78 | events: _, 79 | commit_messages: _, 80 | } = self; 81 | TerminalKind::Testing { 82 | width: *width, 83 | height: *height, 84 | } 85 | } 86 | 87 | fn next_events(&mut self) -> Result, RecordError> { 88 | Ok(vec![self.events.next().unwrap_or(Event::None)]) 89 | } 90 | 91 | fn edit_commit_message(&mut self, _message: &str) -> Result { 92 | self.commit_messages 93 | .pop_front() 94 | .ok_or_else(|| RecordError::Other("No more commit messages available".to_string())) 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /scm-record/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Reusable change selector UI for source control systems. 2 | 3 | #![warn(missing_docs)] 4 | #![warn( 5 | clippy::all, 6 | clippy::as_conversions, 7 | clippy::clone_on_ref_ptr, 8 | clippy::dbg_macro 9 | )] 10 | #![allow(clippy::too_many_arguments, clippy::blocks_in_conditions)] 11 | 12 | mod render; 13 | mod types; 14 | mod ui; 15 | mod util; 16 | 17 | pub mod consts; 18 | pub mod helpers; 19 | pub use types::{ 20 | ChangeType, Commit, File, FileMode, RecordError, RecordState, Section, SectionChangedLine, 21 | SelectedChanges, SelectedContents, Tristate, 22 | }; 23 | pub use ui::{Event, RecordInput, Recorder, TerminalKind, TestingScreenshot}; 24 | -------------------------------------------------------------------------------- /scm-record/src/render.rs: -------------------------------------------------------------------------------- 1 | use std::borrow::Cow; 2 | use std::cmp::{max, min}; 3 | use std::collections::HashMap; 4 | use std::fmt::Debug; 5 | use std::hash::Hash; 6 | use std::mem; 7 | 8 | use cassowary::{Solver, Variable}; 9 | use num_traits::cast; 10 | use ratatui::buffer::Buffer; 11 | use ratatui::style::{Color, Modifier, Style}; 12 | use ratatui::text::{Line, Span}; 13 | use ratatui::widgets::{StatefulWidget, Widget}; 14 | use ratatui::Frame; 15 | use unicode_width::UnicodeWidthStr; 16 | 17 | use crate::util::{IsizeExt, UsizeExt}; 18 | 19 | #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] 20 | pub(crate) struct RectSize { 21 | pub width: usize, 22 | pub height: usize, 23 | } 24 | 25 | impl From for RectSize { 26 | fn from(rect: ratatui::layout::Rect) -> Self { 27 | Rect::from(rect).into() 28 | } 29 | } 30 | 31 | impl From for RectSize { 32 | fn from(rect: Rect) -> Self { 33 | let Rect { 34 | x: _, 35 | y: _, 36 | width, 37 | height, 38 | } = rect; 39 | Self { width, height } 40 | } 41 | } 42 | 43 | /// Like `ratatui::layout::Rect`, but supports addressing negative coordinates. (These 44 | /// coordinates shouldn't be rendered.) 45 | #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] 46 | pub(crate) struct Rect { 47 | pub x: isize, 48 | pub y: isize, 49 | pub width: usize, 50 | pub height: usize, 51 | } 52 | 53 | impl From for Rect { 54 | fn from(value: ratatui::layout::Rect) -> Self { 55 | let ratatui::layout::Rect { 56 | x, 57 | y, 58 | width, 59 | height, 60 | } = value; 61 | Self { 62 | x: x.try_into().unwrap(), 63 | y: y.try_into().unwrap(), 64 | width: width.into(), 65 | height: height.into(), 66 | } 67 | } 68 | } 69 | 70 | impl Rect { 71 | pub fn end_x(self) -> isize { 72 | self.x + self.width.unwrap_isize() 73 | } 74 | 75 | pub fn end_y(self) -> isize { 76 | self.y + self.height.unwrap_isize() 77 | } 78 | 79 | pub fn iter_ys(self) -> impl Iterator { 80 | self.y..self.end_y() 81 | } 82 | 83 | pub fn top_row(self) -> Rect { 84 | Rect { 85 | x: self.x, 86 | y: self.y, 87 | width: self.width, 88 | height: 1, 89 | } 90 | } 91 | 92 | /// The (x, y) coordinate of the top-left corner of this `Rect`. 93 | fn top_left(self) -> (isize, isize) { 94 | (self.x, self.y) 95 | } 96 | 97 | /// The (x, y) coordinate of the bottom-right corner of this `Rect`. 98 | fn bottom_right(self) -> (isize, isize) { 99 | (self.end_x(), self.end_y()) 100 | } 101 | 102 | /// Whether or not this `Rect` contains the given point. 103 | pub fn contains_point(self, x: isize, y: isize) -> bool { 104 | let (x1, y1) = self.top_left(); 105 | let (x2, y2) = self.bottom_right(); 106 | x1 <= x && x < x2 && y1 <= y && y < y2 107 | } 108 | 109 | /// Whether this `Rect` has zero area. 110 | pub fn is_empty(self) -> bool { 111 | self.width == 0 || self.height == 0 112 | } 113 | 114 | /// The largest `Rect` which is contained completely within both `self` and 115 | /// `other`. 116 | pub fn intersect(self, other: Self) -> Self { 117 | let (self_x1, self_y1) = self.top_left(); 118 | let (self_x2, self_y2) = self.bottom_right(); 119 | let (other_x1, other_y1) = other.top_left(); 120 | let (other_x2, other_y2) = other.bottom_right(); 121 | let x1 = max(self_x1, other_x1); 122 | let y1 = max(self_y1, other_y1); 123 | let x2 = min(self_x2, other_x2); 124 | let y2 = min(self_y2, other_y2); 125 | let width = max(0, x2 - x1); 126 | let height = max(0, y2 - y1); 127 | Self { 128 | x: x1, 129 | y: y1, 130 | width: width.unwrap_usize(), 131 | height: height.unwrap_usize(), 132 | } 133 | } 134 | 135 | /// The smallest `Rect` which contains both `self` and `other`. Note that if 136 | /// one of `self` or `other` is empty, the other is returned, i.e. we don't 137 | /// try to calculate the bounding box which includes a zero-area point. 138 | pub fn union_bounding(self, other: Rect) -> Rect { 139 | if self.is_empty() { 140 | other 141 | } else if other.is_empty() { 142 | self 143 | } else { 144 | let (self_x1, self_y1) = self.top_left(); 145 | let (self_x2, self_y2) = self.bottom_right(); 146 | let (other_x1, other_y1) = other.top_left(); 147 | let (other_x2, other_y2) = other.bottom_right(); 148 | let x1 = min(self_x1, other_x1); 149 | let y1 = min(self_y1, other_y1); 150 | let x2 = max(self_x2, other_x2); 151 | let y2 = max(self_y2, other_y2); 152 | let width = max(0, x2 - x1); 153 | let height = max(0, y2 - y1); 154 | Self { 155 | x: x1, 156 | y: y1, 157 | width: width.unwrap_usize(), 158 | height: height.unwrap_usize(), 159 | } 160 | } 161 | } 162 | } 163 | 164 | /// Create a centered `Rect` of at least the given size and at most the provided 165 | /// percentages. 166 | pub(crate) fn centered_rect( 167 | rect: Rect, 168 | min_size: RectSize, 169 | max_percent_width: usize, 170 | max_percent_height: usize, 171 | ) -> Rect { 172 | // `tui` has a `Layout` system that wraps `cassowary`, but it doesn't seem 173 | // to be flexible enough to express the constraints that we want? For 174 | // example, there's no way to express that the width needs to have a minimum 175 | // size *and* a preferred size. 176 | use cassowary::strength::*; 177 | use cassowary::WeightedRelation::*; 178 | 179 | let Rect { 180 | x: min_x, 181 | y: min_y, 182 | width: max_width, 183 | height: max_height, 184 | } = rect; 185 | let min_x: f64 = cast(min_x).unwrap(); 186 | let min_y: f64 = cast(min_y).unwrap(); 187 | let max_width: f64 = cast(max_width).unwrap(); 188 | let max_height: f64 = cast(max_height).unwrap(); 189 | let max_x = min_x + max_width; 190 | let max_y = min_y + max_height; 191 | 192 | let max_percent_width: f64 = cast(max_percent_width).unwrap(); 193 | let max_percent_height: f64 = cast(max_percent_height).unwrap(); 194 | let preferred_width: f64 = max_percent_width * max_width / 100.0; 195 | let preferred_height: f64 = max_percent_height * max_height / 100.0; 196 | 197 | let RectSize { 198 | width: min_width, 199 | height: min_height, 200 | } = min_size; 201 | let min_width: f64 = cast(min_width).unwrap(); 202 | let min_height: f64 = cast(min_height).unwrap(); 203 | 204 | let mut solver = Solver::new(); 205 | let x = Variable::new(); 206 | let y = Variable::new(); 207 | let width = Variable::new(); 208 | let height = Variable::new(); 209 | solver 210 | .add_constraints(&[ 211 | width | GE(REQUIRED) | min_width, 212 | height | GE(REQUIRED) | min_height, 213 | width | LE(REQUIRED) | max_width, 214 | height | LE(REQUIRED) | max_height, 215 | width | EQ(WEAK) | preferred_width, 216 | height | EQ(WEAK) | preferred_height, 217 | ]) 218 | .unwrap(); 219 | solver 220 | .add_constraints(&[ 221 | x | GE(REQUIRED) | min_x, 222 | y | GE(REQUIRED) | min_y, 223 | x | LE(REQUIRED) | max_x, 224 | y | LE(REQUIRED) | max_y, 225 | ]) 226 | .unwrap(); 227 | solver 228 | .add_constraints(&[ 229 | (x - min_x) | EQ(MEDIUM) | (max_x - (x + width)), 230 | (y - min_y) | EQ(MEDIUM) | (max_y - (y + height)), 231 | ]) 232 | .unwrap(); 233 | let changes: HashMap = solver.fetch_changes().iter().copied().collect(); 234 | Rect { 235 | x: cast(changes.get(&x).unwrap_or(&0.0).floor()).unwrap(), 236 | y: cast(changes.get(&y).unwrap_or(&0.0).floor()).unwrap(), 237 | width: cast(changes.get(&width).unwrap_or(&0.0).floor()).unwrap(), 238 | height: cast(changes.get(&height).unwrap_or(&0.0).floor()).unwrap(), 239 | } 240 | } 241 | 242 | /// A "half-open" `Rect` used to to restrict drawing to a certain portion of the screen. 243 | #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] 244 | pub(crate) struct Mask { 245 | pub x: isize, 246 | pub y: isize, 247 | 248 | /// If `None`, the mask is unrestricted on the x-axis past the `x` value. 249 | pub width: Option, 250 | 251 | /// If `None`, the mask is unrestricted on the y-axis past the `y` value. 252 | pub height: Option, 253 | } 254 | 255 | impl Mask { 256 | /// Restrict the `Rect` size to be only the portion that is inside the mask. 257 | pub fn apply(self, rect: Rect) -> Rect { 258 | let end_x = self.end_x().unwrap_or_else(|| rect.end_x()); 259 | let end_y = self.end_y().unwrap_or_else(|| rect.end_y()); 260 | let width = (end_x - self.x).clamp_into_usize(); 261 | let height = (end_y - self.y).clamp_into_usize(); 262 | let mask_rect = Rect { 263 | x: self.x, 264 | y: self.y, 265 | width, 266 | height, 267 | }; 268 | mask_rect.intersect(rect) 269 | } 270 | 271 | pub fn end_x(self) -> Option { 272 | self.width.map(|width| self.x + width.unwrap_isize()) 273 | } 274 | 275 | pub fn end_y(self) -> Option { 276 | self.height.map(|height| self.y + height.unwrap_isize()) 277 | } 278 | } 279 | 280 | impl From for Mask { 281 | fn from(rect: Rect) -> Self { 282 | let Rect { 283 | x, 284 | y, 285 | width, 286 | height, 287 | } = rect; 288 | Self { 289 | x, 290 | y, 291 | width: Some(width), 292 | height: Some(height), 293 | } 294 | } 295 | } 296 | 297 | /// Recording of where the component with a certain ID drew on the virtual 298 | /// canvas. 299 | #[derive(Debug)] 300 | struct DrawTrace { 301 | /// The bounding box of all cells where the component drew. 302 | /// 303 | /// This `Rect` is at least as big as the bounding box containing all child 304 | /// component `Rect`s, and could be bigger if the component drew somewhere 305 | /// to the screen where no child component drew. 306 | rect: Rect, 307 | 308 | /// The bounding boxes of where each child component drew. 309 | components: HashMap, 310 | } 311 | 312 | impl DrawTrace { 313 | /// Update the bounding box of this trace to include `other_rect`. 314 | pub fn merge_rect(&mut self, other_rect: Rect) { 315 | let Self { 316 | rect, 317 | components: _, 318 | } = self; 319 | *rect = rect.union_bounding(other_rect) 320 | } 321 | 322 | /// Update the bounding box of this trace to include `other.rect` and copy 323 | /// all child component `Rect`s. 324 | pub fn merge(&mut self, other: Self) { 325 | let Self { rect, components } = self; 326 | let Self { 327 | rect: other_rect, 328 | components: other_components, 329 | } = other; 330 | *rect = rect.union_bounding(other_rect); 331 | for (id, rect) in other_components { 332 | components.insert(id.clone(), rect); 333 | } 334 | } 335 | } 336 | 337 | impl Default for DrawTrace { 338 | fn default() -> Self { 339 | Self { 340 | rect: Default::default(), 341 | components: Default::default(), 342 | } 343 | } 344 | } 345 | 346 | #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] 347 | pub(crate) struct DrawnRect { 348 | pub rect: Rect, 349 | pub timestamp: usize, 350 | } 351 | 352 | pub(crate) type DrawnRects = HashMap; 353 | 354 | /// Accessor to draw on the virtual canvas. The caller can draw anywhere on the 355 | /// canvas, but the actual renering will be restricted to this viewport. All 356 | /// draw calls are also tracked so that we know where each component was drawn 357 | /// after the fact (see `DrawTrace`). 358 | #[derive(Debug)] 359 | pub(crate) struct Viewport<'a, ComponentId> { 360 | buf: &'a mut Buffer, 361 | rect: Rect, 362 | mask: Option, 363 | timestamp: usize, 364 | trace: Vec>, 365 | debug_messages: Vec, 366 | } 367 | 368 | impl<'a, ComponentId: Clone + Debug + Eq + Hash> Viewport<'a, ComponentId> { 369 | pub fn new(buf: &'a mut Buffer, rect: Rect) -> Self { 370 | Self { 371 | buf, 372 | rect, 373 | mask: Default::default(), 374 | timestamp: Default::default(), 375 | trace: vec![Default::default()], 376 | debug_messages: Default::default(), 377 | } 378 | } 379 | 380 | /// The portion of the virtual canvas that will be rendered to the terminal. 381 | /// Thus, this `Rect` should have the same dimensions as the terminal. 382 | pub fn rect(&self) -> Rect { 383 | self.rect 384 | } 385 | 386 | /// The mask used for rendering. Calls to `draw_span` will only render 387 | /// inside the mask area. This can be used to overlay one component on top 388 | /// of another in a fixed area. 389 | /// 390 | /// This can be set with `Viewport::with_mask`. If no mask has been set in 391 | /// the current call stack, then the returned value defaults to 392 | /// `Viewport::rect`, i.e. the area representing the entire terminal. 393 | pub fn mask(&self) -> Mask { 394 | self.mask.unwrap_or_else(|| self.rect().into()) 395 | } 396 | 397 | /// Get the masked area restricted to the portion that is viewable in the 398 | /// viewport. This lets us return a `Rect` instead of a `Mask`, which could 399 | /// otherwise have `None` `width` or `height` fields. 400 | pub fn mask_rect(&self) -> Rect { 401 | self.mask().apply(self.rect()) 402 | } 403 | 404 | /// Render the provided component using the given `Frame`. Returns a mapping 405 | /// indicating where each component was drawn on the screen. 406 | pub fn render_top_level( 407 | frame: &mut Frame, 408 | x: isize, 409 | y: isize, 410 | component: &C, 411 | ) -> DrawnRects { 412 | let widget = TopLevelWidget { component, x, y }; 413 | let term_area = frame.area(); 414 | let mut drawn_rects = Default::default(); 415 | frame.render_stateful_widget(widget, term_area, &mut drawn_rects); 416 | drawn_rects 417 | } 418 | 419 | fn current_trace_mut(&mut self) -> &mut DrawTrace { 420 | self.trace.last_mut() 421 | .expect("draw trace stack is empty, so can't update trace for current component; did you call `Viewport::render_top_level` to render the top-level component?") 422 | } 423 | 424 | /// Set the terminal styling for a certain area. This can also be 425 | /// accomplished using `draw_span` with a styled `Span`, but in some cases, 426 | /// it may be more appropriate to set the style of certain cells directly. 427 | pub fn set_style(&mut self, rect: Rect, style: Style) { 428 | self.buf.set_style(self.translate_rect(rect), style); 429 | self.current_trace_mut().merge_rect(rect); 430 | } 431 | 432 | /// Render a debug message to the screen (at an unspecified location). 433 | pub fn debug(&mut self, message: impl Into) { 434 | self.debug_messages.push(message.into()) 435 | } 436 | 437 | /// Set a mask to be used for rendering inside `f`. 438 | pub fn with_mask(&mut self, mask: Mask, f: impl FnOnce(&mut Self) -> T) -> T { 439 | let mut mask = Some(mask); 440 | mem::swap(&mut self.mask, &mut mask); 441 | let result = f(self); 442 | mem::swap(&mut self.mask, &mut mask); 443 | result 444 | } 445 | 446 | /// Draw the provided child component to the screen at the given `(x, y)` 447 | /// location. 448 | pub fn draw_component>( 449 | &mut self, 450 | x: isize, 451 | y: isize, 452 | component: &C, 453 | ) -> Rect { 454 | let timestamp = { 455 | let timestamp = self.timestamp; 456 | self.timestamp += 1; 457 | timestamp 458 | }; 459 | let mut trace = { 460 | self.trace.push(Default::default()); 461 | component.draw(self, x, y); 462 | self.trace.pop().unwrap() 463 | }; 464 | 465 | let trace_rect = trace.components.values().fold(trace.rect, |acc, elem| { 466 | let DrawnRect { rect, timestamp: _ } = elem; 467 | acc.union_bounding(*rect) 468 | }); 469 | trace.rect = trace_rect; 470 | trace.components.insert( 471 | component.id(), 472 | DrawnRect { 473 | rect: trace_rect, 474 | timestamp, 475 | }, 476 | ); 477 | 478 | self.current_trace_mut().merge(trace); 479 | trace_rect 480 | } 481 | 482 | /// Draw a `Span` directly to the screen at the given `(x, y)` location. 483 | pub fn draw_span(&mut self, x: isize, y: isize, span: &Span) -> Rect { 484 | let Span { content, style } = span; 485 | let span_rect = Rect { 486 | x, 487 | y, 488 | width: content.width(), 489 | height: 1, 490 | }; 491 | self.current_trace_mut().merge_rect(span_rect); 492 | 493 | let draw_rect = self.rect.intersect(span_rect); 494 | let draw_rect = match self.mask { 495 | Some(mask) => mask.apply(draw_rect), 496 | None => draw_rect, 497 | }; 498 | if !draw_rect.is_empty() { 499 | let span_start_idx = (draw_rect.x - span_rect.x).unwrap_usize(); 500 | let span_start_byte_idx = content 501 | .char_indices() 502 | .nth(span_start_idx) 503 | .map(|(i, _c)| i) 504 | .unwrap_or(0); 505 | let span_end_byte_idx = match content 506 | .char_indices() 507 | .nth(span_start_idx + draw_rect.width) 508 | .map(|(i, _c)| i) 509 | { 510 | Some(span_end_byte_index) => span_end_byte_index, 511 | None => content.len(), 512 | }; 513 | let draw_span = Span { 514 | content: Cow::Borrowed(&content.as_ref()[span_start_byte_idx..span_end_byte_idx]), 515 | style: *style, 516 | }; 517 | 518 | let buf_rect = self.translate_rect(draw_rect); 519 | self.buf 520 | .set_span(buf_rect.x, buf_rect.y, &draw_span, buf_rect.width); 521 | } 522 | 523 | span_rect 524 | } 525 | 526 | /// Draw a [`Line`] directly to the screen at `(x, y)` location. 527 | pub fn draw_line(&mut self, x: isize, y: isize, line: &Line) -> Rect { 528 | let line_rect = Rect { 529 | x, 530 | y, 531 | width: line.width(), 532 | height: 1, 533 | }; 534 | self.current_trace_mut().merge_rect(line_rect); 535 | 536 | let draw_rect = self.rect.intersect(line_rect); 537 | 538 | let draw_rect = match self.mask { 539 | Some(mask) => mask.apply(draw_rect), 540 | None => draw_rect, 541 | }; 542 | if !draw_rect.is_empty() { 543 | let buf_rect = self.translate_rect(draw_rect); 544 | line.render(buf_rect, self.buf); 545 | } 546 | 547 | line_rect 548 | } 549 | 550 | /// Draw the given text. If the text would overflow the current mask, then 551 | /// it is truncated with an ellipsis. 552 | pub fn draw_text<'line>(&mut self, x: isize, y: isize, line: impl Into>) -> Rect { 553 | let line_rect = self.draw_line(x, y, &line.into()); 554 | 555 | let mask_rect = self.mask_rect(); 556 | if line_rect.end_x() > mask_rect.end_x() { 557 | self.draw_span(mask_rect.end_x() - 1, line_rect.y, &Span::raw("…")); 558 | } 559 | line_rect 560 | } 561 | 562 | pub fn draw_widget(&mut self, rect: ratatui::layout::Rect, widget: impl Widget) { 563 | self.current_trace_mut().merge_rect(rect.into()); 564 | widget.render(rect, self.buf); 565 | } 566 | 567 | pub fn draw_blank(&mut self, rect: Rect) { 568 | for y in rect.iter_ys() { 569 | self.draw_span( 570 | rect.x, 571 | y, 572 | &Span::styled(" ".repeat(rect.width), Style::reset()), 573 | ); 574 | } 575 | } 576 | 577 | /// Convert the virtual `Rect` being displayed on the viewport, potentially 578 | /// including an area off-screen, into a real terminal `ratatui::layout::Rect` 579 | /// indicating the actual positions of the characters to be printed 580 | /// on-screen. 581 | pub fn translate_rect(&self, rect: impl Into) -> ratatui::layout::Rect { 582 | let draw_rect = self.rect.intersect(rect.into()); 583 | let x = draw_rect.x - self.rect.x; 584 | let y = draw_rect.y - self.rect.y; 585 | let width = draw_rect.width; 586 | let height = draw_rect.height; 587 | ratatui::layout::Rect { 588 | x: x.try_into().unwrap(), 589 | y: y.try_into().unwrap(), 590 | width: width.try_into().unwrap(), 591 | height: height.try_into().unwrap(), 592 | } 593 | } 594 | } 595 | 596 | /// Wrapper to render via `ratatui::Frame`. 597 | struct TopLevelWidget<'a, C> { 598 | component: &'a C, 599 | x: isize, 600 | y: isize, 601 | } 602 | 603 | impl StatefulWidget for TopLevelWidget<'_, C> { 604 | type State = DrawnRects; 605 | 606 | fn render(self, area: ratatui::layout::Rect, buf: &mut Buffer, state: &mut Self::State) { 607 | let Self { component, x, y } = self; 608 | let mut viewport: Viewport = Viewport::new( 609 | buf, 610 | Rect { 611 | x, 612 | y, 613 | width: area.width.into(), 614 | height: area.height.into(), 615 | }, 616 | ); 617 | viewport.draw_component(0, 0, component); 618 | *state = viewport.trace.pop().unwrap().components; 619 | debug_assert!(viewport.trace.is_empty()); 620 | 621 | // Render debug messages. 622 | { 623 | let x = 50_u16; 624 | let debug_messages: Vec = viewport 625 | .debug_messages 626 | .into_iter() 627 | .flat_map(|message| -> Vec { 628 | message.split('\n').map(|s| s.to_string()).collect() 629 | }) 630 | .collect(); 631 | let max_line_len = min( 632 | debug_messages.iter().map(|s| s.len()).max().unwrap_or(0), 633 | viewport.buf.area.width.into(), 634 | ); 635 | for (y, message) in debug_messages.into_iter().enumerate() { 636 | let spaces = " ".repeat(max_line_len - message.len()); 637 | let span = Span::styled( 638 | message + &spaces, 639 | Style::default() 640 | .fg(Color::Yellow) 641 | .add_modifier(Modifier::REVERSED), 642 | ); 643 | if y < viewport.buf.area.height.into() { 644 | viewport.buf.set_span( 645 | x, 646 | y.clamp_into_u16(), 647 | &span, 648 | max_line_len.clamp_into_u16(), 649 | ); 650 | } 651 | } 652 | } 653 | } 654 | } 655 | 656 | /// A component which can be rendered on the virtual canvas. All calls to draw 657 | /// components are traced so that it can be determined later where a given 658 | /// component was drawn. 659 | pub(crate) trait Component: Sized { 660 | /// A unique identifier which identifies this component or one of its child 661 | /// components. This can be used with the return value of 662 | /// `Viewport::render_top_level` to find where the component with a given ID 663 | /// was drawn. 664 | type Id: Clone + Debug + Eq + Hash; 665 | 666 | /// Get the ID for this component. 667 | fn id(&self) -> Self::Id; 668 | 669 | /// Draw this component and any child components. 670 | fn draw(&self, viewport: &mut Viewport, x: isize, y: isize); 671 | } 672 | -------------------------------------------------------------------------------- /scm-record/src/types.rs: -------------------------------------------------------------------------------- 1 | //! Data types for the change selector interface. 2 | 3 | use std::borrow::Cow; 4 | use std::fmt::Display; 5 | use std::io; 6 | use std::num::TryFromIntError; 7 | use std::path::Path; 8 | 9 | use thiserror::Error; 10 | 11 | /// The state used to render the changes. This is passed into 12 | /// [`crate::Recorder::new`] and then updated and returned with 13 | /// [`crate::Recorder::run`]. 14 | #[derive(Clone, Debug, Default, Eq, PartialEq)] 15 | #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] 16 | pub struct RecordState<'a> { 17 | /// Render the UI as read-only, such that the checkbox states cannot be 18 | /// changed by the user. 19 | pub is_read_only: bool, 20 | 21 | /// The commits containing the selected changes. Each changed section be 22 | /// assigned to exactly one commit. 23 | /// 24 | /// If there are fewer than two commits in this list, then it is padded to 25 | /// two commits using `Commit::default` before being returned. 26 | /// 27 | /// It's important to note that the `Commit`s do not literally contain the 28 | /// selected changes. They are stored out-of-band in the `files` field. It 29 | /// would be possible to store the changes in the `Commit`s, but we would no 30 | /// longer get the invariant that each change belongs to a single commit for 31 | /// free. (That being said, we now have to uphold the invariant that the 32 | /// changes are all assigned to valid commits.) It would also be somewhat 33 | /// more tedious to write the code that removes the change from one `Commit` 34 | /// and adds it to the correct relative position (with respect to all of the 35 | /// other changes) in another `Commit`. 36 | pub commits: Vec, 37 | 38 | /// The state of each file. This is rendered in order, so you may want to 39 | /// sort this list by path before providing it. 40 | pub files: Vec>, 41 | } 42 | 43 | /// An error which occurred when attempting to record changes. 44 | #[allow(missing_docs)] 45 | #[derive(Debug, Error)] 46 | pub enum RecordError { 47 | /// The user cancelled the operation. 48 | #[error("cancelled by user")] 49 | Cancelled, 50 | 51 | #[error("failed to set up terminal: {0}")] 52 | SetUpTerminal(#[source] io::Error), 53 | 54 | #[error("failed to clean up terminal: {0}")] 55 | CleanUpTerminal(#[source] io::Error), 56 | 57 | #[error("failed to render new frame: {0}")] 58 | RenderFrame(#[source] io::Error), 59 | 60 | #[error("failed to read user input: {0}")] 61 | ReadInput(#[source] io::Error), 62 | 63 | #[cfg(feature = "serde")] 64 | #[error("failed to serialize JSON: {0}")] 65 | SerializeJson(#[source] serde_json::Error), 66 | 67 | #[error("failed to wrote file: {0}")] 68 | WriteFile(#[source] io::Error), 69 | 70 | #[error("{0}")] 71 | Other(String), 72 | 73 | #[error("bug: {0}")] 74 | Bug(String), 75 | } 76 | 77 | /// The file mode. 78 | #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] 79 | #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] 80 | pub enum FileMode { 81 | /// A Read Write Execute style Unix file mode 82 | Unix(usize), 83 | 84 | /// Indicates that the file did not exists. 85 | Absent, 86 | } 87 | 88 | impl FileMode { 89 | /// The default Unix permissions for files. 90 | pub const FILE_DEFAULT: FileMode = FileMode::Unix(0o100644); 91 | } 92 | 93 | impl Display for FileMode { 94 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 95 | match self { 96 | FileMode::Unix(mode) => { 97 | write!(f, "{mode:o}") 98 | } 99 | FileMode::Absent => { 100 | write!(f, "") 101 | } 102 | } 103 | } 104 | } 105 | 106 | impl From for FileMode { 107 | fn from(value: usize) -> Self { 108 | Self::Unix(value) 109 | } 110 | } 111 | 112 | impl TryFrom for FileMode { 113 | type Error = TryFromIntError; 114 | 115 | fn try_from(value: u32) -> Result { 116 | Ok(Self::Unix(value.try_into()?)) 117 | } 118 | } 119 | 120 | impl TryFrom for FileMode { 121 | type Error = TryFromIntError; 122 | 123 | fn try_from(value: i32) -> Result { 124 | Ok(Self::Unix(value.try_into()?)) 125 | } 126 | } 127 | 128 | /// The state of the selection. 129 | #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] 130 | pub enum Tristate { 131 | /// All elements are not selected. 132 | False, 133 | /// Some elements are selected. 134 | Partial, 135 | /// All elements are selected. 136 | True, 137 | } 138 | 139 | impl From for Tristate { 140 | fn from(value: bool) -> Self { 141 | match value { 142 | true => Tristate::True, 143 | false => Tristate::False, 144 | } 145 | } 146 | } 147 | 148 | /// A container of selected changes and commit metadata. 149 | #[derive(Clone, Debug, Default, Eq, PartialEq)] 150 | #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] 151 | pub struct Commit { 152 | /// The commit message. If `Some`, then the commit message will be previewed 153 | /// in the UI and the user will be able to edit it. If `None`, the commit 154 | /// message will not be shown or editable. 155 | pub message: Option, 156 | } 157 | 158 | /// The state of a file to be recorded. 159 | #[derive(Clone, Debug, Eq, PartialEq)] 160 | #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] 161 | pub struct File<'a> { 162 | /// The path to the previous version of the file, for display purposes. This 163 | /// should be set if the file was renamed or copied from another file. 164 | pub old_path: Option>, 165 | 166 | /// The path to the current version of the file, for display purposes. 167 | pub path: Cow<'a, Path>, 168 | 169 | /// The Unix file mode of the file (before any changes), if available. This 170 | /// may be rendered by the UI. 171 | /// 172 | /// This value is not directly modified by the UI; instead, construct a 173 | /// [`Section::FileMode`] and look for a user-provided update to the file 174 | /// mode in the changes returned from [`File::get_selected_contents()`]. 175 | pub file_mode: FileMode, 176 | 177 | /// The set of [`Section`]s inside the file. 178 | pub sections: Vec>, 179 | } 180 | 181 | /// The changes for a particular file selected as part of the record operation. 182 | #[derive(Debug)] 183 | pub struct SelectedChanges<'a> { 184 | /// The file's mode. 185 | pub file_mode: FileMode, 186 | 187 | /// The file's contents. 188 | pub contents: SelectedContents<'a>, 189 | } 190 | 191 | /// The contents of a file selected as part of the record operation. 192 | #[derive(Clone, Debug, Hash, Eq, PartialEq, PartialOrd, Ord)] 193 | pub enum SelectedContents<'a> { 194 | /// The file contents have not changed. 195 | Unchanged, 196 | 197 | /// The file contains binary contents. 198 | Binary { 199 | /// The UI description of the old version of the file. 200 | old_description: Option>, 201 | /// The UI description of the new version of the file. 202 | new_description: Option>, 203 | }, 204 | 205 | /// The file contained the following text contents. 206 | Text { 207 | /// The contents of the file. 208 | contents: String, 209 | }, 210 | } 211 | 212 | impl SelectedContents<'_> { 213 | fn push_str(&mut self, s: &str) { 214 | match self { 215 | SelectedContents::Unchanged => { 216 | *self = SelectedContents::Text { 217 | contents: s.to_owned(), 218 | } 219 | } 220 | SelectedContents::Binary { 221 | old_description: _, 222 | new_description: _, 223 | } => { 224 | // Do nothing. 225 | } 226 | SelectedContents::Text { contents } => { 227 | contents.push_str(s); 228 | } 229 | } 230 | } 231 | } 232 | 233 | impl File<'_> { 234 | /// Calculate the `(selected, unselected)` contents of the file. For 235 | /// example, the first value would be suitable for staging or committing, 236 | /// and the second value would be suitable for potentially recording again. 237 | pub fn get_selected_contents(&self) -> (SelectedChanges, SelectedChanges) { 238 | let mut acc_selected = SelectedContents::Unchanged; 239 | let mut acc_unselected = SelectedContents::Unchanged; 240 | 241 | let Self { 242 | old_path: _, 243 | path: _, 244 | file_mode, 245 | sections, 246 | } = self; 247 | 248 | let file_mode_section = sections.iter().find_map(|section| match section { 249 | Section::Unchanged { .. } | Section::Changed { .. } | Section::Binary { .. } => None, 250 | 251 | Section::FileMode { is_checked, mode } => Some((mode, is_checked)), 252 | }); 253 | 254 | // The file mode for the selected changes is the selected file mode, if one was selected, 255 | // or the original mode of the file, if not. 256 | let selected_file_mode = file_mode_section 257 | .filter(|(_, is_checked)| **is_checked) 258 | .map(|(change, _)| *change) 259 | .unwrap_or(*file_mode); 260 | 261 | // The file mode for the unselected changes is the unselected file mode, if one was provided, 262 | // or the original mode of the file, if not 263 | let unselected_file_mode = file_mode_section 264 | .filter(|(_, is_checked)| !**is_checked) 265 | .map(|(change, _)| *change) 266 | .unwrap_or(*file_mode); 267 | 268 | for section in sections { 269 | match section { 270 | Section::Unchanged { lines } => { 271 | for line in lines { 272 | acc_selected.push_str(line); 273 | acc_unselected.push_str(line); 274 | } 275 | } 276 | 277 | Section::Changed { lines } => { 278 | for line in lines { 279 | let SectionChangedLine { 280 | is_checked, 281 | change_type, 282 | line, 283 | } = line; 284 | match (change_type, is_checked) { 285 | (ChangeType::Added, true) | (ChangeType::Removed, false) => { 286 | acc_selected.push_str(line); 287 | } 288 | (ChangeType::Added, false) | (ChangeType::Removed, true) => { 289 | acc_unselected.push_str(line); 290 | 291 | // Ensure that if the file existed before and still does, that 292 | // we never report Unchanged for the selected contents in the case 293 | // that all the lines are removed (i.e. we empty the file without 294 | // deleting it) 295 | if selected_file_mode != FileMode::Absent { 296 | acc_selected.push_str(""); 297 | } 298 | } 299 | } 300 | } 301 | } 302 | 303 | Section::FileMode { .. } => { 304 | // Do nothing - this is handled outside of the loop 305 | } 306 | 307 | Section::Binary { 308 | is_checked, 309 | old_description, 310 | new_description, 311 | } => { 312 | let selected_contents = SelectedContents::Binary { 313 | old_description: old_description.clone(), 314 | new_description: new_description.clone(), 315 | }; 316 | if *is_checked { 317 | acc_selected = selected_contents; 318 | acc_unselected = SelectedContents::Unchanged; 319 | } else { 320 | acc_selected = SelectedContents::Unchanged; 321 | acc_unselected = selected_contents; 322 | } 323 | } 324 | } 325 | } 326 | 327 | // If an empty file was added, we won't have seen any lines in order to ensure the selected contents is "", so handle it here for the 328 | // selected and un-selected cases 329 | if *file_mode == FileMode::Absent 330 | && selected_file_mode != FileMode::Absent 331 | && acc_selected == SelectedContents::Unchanged 332 | { 333 | acc_selected.push_str(""); 334 | } 335 | 336 | if *file_mode == FileMode::Absent 337 | && unselected_file_mode != FileMode::Absent 338 | && acc_unselected == SelectedContents::Unchanged 339 | { 340 | acc_unselected.push_str(""); 341 | } 342 | 343 | ( 344 | SelectedChanges { 345 | contents: acc_selected, 346 | file_mode: selected_file_mode, 347 | }, 348 | SelectedChanges { 349 | contents: acc_unselected, 350 | file_mode: unselected_file_mode, 351 | }, 352 | ) 353 | } 354 | 355 | /// Get the tristate value of the file. If there are no sections in this 356 | /// file, returns `Tristate::False`. 357 | pub fn tristate(&self) -> Tristate { 358 | let Self { 359 | old_path: _, 360 | path: _, 361 | file_mode: _, 362 | sections, 363 | } = self; 364 | let mut seen_value = None; 365 | for section in sections { 366 | match section { 367 | Section::Unchanged { .. } => {} 368 | Section::Changed { lines } => { 369 | for line in lines { 370 | seen_value = match (seen_value, line.is_checked) { 371 | (None, is_checked) => Some(is_checked), 372 | (Some(true), true) => Some(true), 373 | (Some(false), false) => Some(false), 374 | (Some(true), false) | (Some(false), true) => return Tristate::Partial, 375 | }; 376 | } 377 | } 378 | Section::FileMode { 379 | is_checked, 380 | mode: _, 381 | } 382 | | Section::Binary { 383 | is_checked, 384 | old_description: _, 385 | new_description: _, 386 | } => { 387 | seen_value = match (seen_value, is_checked) { 388 | (None, is_checked) => Some(*is_checked), 389 | (Some(true), true) => Some(true), 390 | (Some(false), false) => Some(false), 391 | (Some(true), false) | (Some(false), true) => return Tristate::Partial, 392 | } 393 | } 394 | } 395 | } 396 | match seen_value { 397 | Some(true) => Tristate::True, 398 | None | Some(false) => Tristate::False, 399 | } 400 | } 401 | 402 | /// Set the selection of all sections and lines in this file. 403 | pub fn set_checked(&mut self, checked: bool) { 404 | let Self { 405 | old_path: _, 406 | path: _, 407 | file_mode: _, 408 | sections, 409 | } = self; 410 | for section in sections { 411 | section.set_checked(checked); 412 | } 413 | } 414 | 415 | /// Toggle the selection of all sections in this file. 416 | pub fn toggle_all(&mut self) { 417 | let Self { 418 | old_path: _, 419 | path: _, 420 | file_mode: _, 421 | sections, 422 | } = self; 423 | for section in sections { 424 | section.toggle_all(); 425 | } 426 | } 427 | } 428 | 429 | /// A section of a file to be rendered and recorded. 430 | #[derive(Clone, Debug, Eq, PartialEq)] 431 | #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] 432 | pub enum Section<'a> { 433 | /// This section of the file is unchanged and just used for context. 434 | /// 435 | /// By default, only part of the context will be shown. However, all of the 436 | /// context lines should be provided so that they can be used to globally 437 | /// number the lines correctly. 438 | Unchanged { 439 | /// The contents of the lines, including their trailing newline 440 | /// character(s), if any. 441 | lines: Vec>, 442 | }, 443 | 444 | /// This section of the file is changed, and the user needs to select which 445 | /// specific changed lines to record. 446 | Changed { 447 | /// The contents of the lines, including their trailing newline 448 | /// character(s), if any. 449 | lines: Vec>, 450 | }, 451 | 452 | /// This indicates that the Unix file mode of the file changed, and that the 453 | /// user needs to accept that mode change or not. This is not part of the 454 | /// "contents" of the file per se, but it's rendered inline as if it were. 455 | FileMode { 456 | /// Whether or not the file mode change was selected for inclusion in 457 | /// the UI. 458 | is_checked: bool, 459 | 460 | /// The mode of the file after these changes. 461 | mode: FileMode, 462 | }, 463 | 464 | /// This file contains binary contents. 465 | Binary { 466 | /// Whether or not the binary contents change was selected for inclusion 467 | /// in the UI. 468 | is_checked: bool, 469 | 470 | /// The description of the old binary contents, for use in the UI only. 471 | old_description: Option>, 472 | 473 | /// The description of the new binary contents, for use in the UI only. 474 | new_description: Option>, 475 | }, 476 | } 477 | 478 | impl Section<'_> { 479 | /// Whether or not this section contains user-editable content (as opposed 480 | /// to simply contextual content). 481 | pub fn is_editable(&self) -> bool { 482 | match self { 483 | Section::Unchanged { .. } => false, 484 | Section::Changed { .. } | Section::FileMode { .. } | Section::Binary { .. } => true, 485 | } 486 | } 487 | 488 | /// Get the tristate value of this section. If there are no items in this 489 | /// section, returns `Tristate::False`. 490 | pub fn tristate(&self) -> Tristate { 491 | let mut seen_value = None; 492 | match self { 493 | Section::Unchanged { .. } => {} 494 | Section::Changed { lines } => { 495 | for line in lines { 496 | seen_value = match (seen_value, line.is_checked) { 497 | (None, is_checked) => Some(is_checked), 498 | (Some(true), true) => Some(true), 499 | (Some(false), false) => Some(false), 500 | (Some(true), false) | (Some(false), true) => return Tristate::Partial, 501 | }; 502 | } 503 | } 504 | Section::FileMode { 505 | is_checked, 506 | mode: _, 507 | } 508 | | Section::Binary { 509 | is_checked, 510 | old_description: _, 511 | new_description: _, 512 | } => { 513 | seen_value = match (seen_value, is_checked) { 514 | (None, is_checked) => Some(*is_checked), 515 | (Some(true), true) => Some(true), 516 | (Some(false), false) => Some(false), 517 | (Some(true), false) | (Some(false), true) => return Tristate::Partial, 518 | } 519 | } 520 | } 521 | match seen_value { 522 | Some(true) => Tristate::True, 523 | None | Some(false) => Tristate::False, 524 | } 525 | } 526 | 527 | /// Select or unselect all items in this section. 528 | pub fn set_checked(&mut self, checked: bool) { 529 | match self { 530 | Section::Unchanged { .. } => {} 531 | Section::Changed { lines } => { 532 | for line in lines { 533 | line.is_checked = checked; 534 | } 535 | } 536 | Section::FileMode { 537 | is_checked, 538 | mode: _, 539 | } => { 540 | *is_checked = checked; 541 | } 542 | Section::Binary { is_checked, .. } => { 543 | *is_checked = checked; 544 | } 545 | } 546 | } 547 | 548 | /// Toggle the selection of this section. 549 | pub fn toggle_all(&mut self) { 550 | match self { 551 | Section::Unchanged { .. } => {} 552 | Section::Changed { lines } => { 553 | for line in lines { 554 | line.is_checked = !line.is_checked; 555 | } 556 | } 557 | Section::FileMode { is_checked, .. } => { 558 | *is_checked = !*is_checked; 559 | } 560 | Section::Binary { is_checked, .. } => { 561 | *is_checked = !*is_checked; 562 | } 563 | } 564 | } 565 | } 566 | 567 | /// The type of change in the patch/diff. 568 | #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] 569 | #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] 570 | pub enum ChangeType { 571 | /// The line was added. 572 | Added, 573 | 574 | /// The line was removed. 575 | Removed, 576 | } 577 | 578 | /// A changed line inside a `Section`. 579 | #[derive(Clone, Debug, Eq, PartialEq)] 580 | #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] 581 | pub struct SectionChangedLine<'a> { 582 | /// Whether or not this line was selected to be recorded. 583 | pub is_checked: bool, 584 | 585 | /// The type of change this line was. 586 | pub change_type: ChangeType, 587 | 588 | /// The contents of the line, including its trailing newline character(s), 589 | /// if any. 590 | pub line: Cow<'a, str>, 591 | } 592 | -------------------------------------------------------------------------------- /scm-record/src/util.rs: -------------------------------------------------------------------------------- 1 | pub trait UsizeExt { 2 | fn unwrap_isize(self) -> isize; 3 | fn clamp_into_u16(self) -> u16; 4 | } 5 | 6 | impl UsizeExt for usize { 7 | fn unwrap_isize(self) -> isize { 8 | isize::try_from(self).unwrap() 9 | } 10 | 11 | fn clamp_into_u16(self) -> u16 { 12 | if self > u16::MAX.into() { 13 | u16::MAX 14 | } else { 15 | self.try_into().unwrap() 16 | } 17 | } 18 | } 19 | 20 | pub trait IsizeExt { 21 | fn unwrap_usize(self) -> usize; 22 | #[allow(dead_code)] 23 | fn clamp_into_u16(self) -> u16; 24 | fn clamp_into_usize(self) -> usize; 25 | } 26 | 27 | impl IsizeExt for isize { 28 | fn unwrap_usize(self) -> usize { 29 | usize::try_from(self).unwrap() 30 | } 31 | 32 | fn clamp_into_u16(self) -> u16 { 33 | if self < 0 { 34 | 0 35 | } else { 36 | self.try_into().unwrap_or(u16::MAX) 37 | } 38 | } 39 | 40 | fn clamp_into_usize(self) -> usize { 41 | if self < 0 { 42 | 0 43 | } else { 44 | self.try_into().unwrap_or(usize::MAX) 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /scm-record/tests/example_contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "is_read_only": false, 3 | "commits": [], 4 | "files": [ 5 | { 6 | "path": "foo/bar", 7 | "file_mode": { "Unix": 33188 }, 8 | "sections": [ 9 | { 10 | "Unchanged": { 11 | "lines": [ 12 | "this is some text\n", 13 | "this is some text\n", 14 | "this is some text\n", 15 | "this is some text\n", 16 | "this is some text\n", 17 | "this is some text\n", 18 | "this is some text\n", 19 | "this is some text\n", 20 | "this is some text\n", 21 | "this is some text\n", 22 | "this is some text\n", 23 | "this is some text\n", 24 | "this is some text\n", 25 | "this is some text\n", 26 | "this is some text\n", 27 | "this is some text\n", 28 | "this is some text\n", 29 | "this is some text\n", 30 | "this is some text\n", 31 | "this is some text\n" 32 | ] 33 | } 34 | }, 35 | { 36 | "Changed": { 37 | "lines": [ 38 | { 39 | "is_checked": true, 40 | "change_type": "Removed", 41 | "line": "before text 1\n" 42 | }, 43 | { 44 | "is_checked": true, 45 | "change_type": "Removed", 46 | "line": "before text 2\n" 47 | }, 48 | { 49 | "is_checked": true, 50 | "change_type": "Added", 51 | "line": "after text 1\n" 52 | }, 53 | { 54 | "is_checked": false, 55 | "change_type": "Added", 56 | "line": "after text 2\n" 57 | } 58 | ] 59 | } 60 | }, 61 | { 62 | "Unchanged": { 63 | "lines": ["this is some trailing text\n"] 64 | } 65 | } 66 | ] 67 | }, 68 | { 69 | "path": "baz", 70 | "file_mode": { "Unix": 33188 }, 71 | "sections": [ 72 | { 73 | "Unchanged": { 74 | "lines": ["Some leading text 1\n", "Some leading text 2\n"] 75 | } 76 | }, 77 | { 78 | "Changed": { 79 | "lines": [ 80 | { 81 | "is_checked": true, 82 | "change_type": "Removed", 83 | "line": "before text 1\n" 84 | }, 85 | { 86 | "is_checked": true, 87 | "change_type": "Removed", 88 | "line": "before text 2\n" 89 | }, 90 | { 91 | "is_checked": true, 92 | "change_type": "Added", 93 | "line": "after text 1\n" 94 | }, 95 | { 96 | "is_checked": true, 97 | "change_type": "Added", 98 | "line": "after text 2\n" 99 | } 100 | ] 101 | } 102 | }, 103 | { 104 | "Unchanged": { 105 | "lines": ["this is some trailing text\n"] 106 | } 107 | } 108 | ] 109 | } 110 | ] 111 | } 112 | --------------------------------------------------------------------------------