{"id":22249007,"url":"https://github.com/purplebooth/termdiff","last_synced_at":"2026-04-30T18:31:27.990Z","repository":{"id":40418369,"uuid":"419893287","full_name":"PurpleBooth/termdiff","owner":"PurpleBooth","description":"Diff a string for presentation to a user in the terminal","archived":false,"fork":false,"pushed_at":"2023-08-07T22:42:23.000Z","size":221,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-14T10:15:22.622Z","etag":null,"topics":["diff","terminal"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/termdiff","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PurpleBooth.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-21T22:21:30.000Z","updated_at":"2024-07-27T06:25:34.194Z","dependencies_parsed_at":"2024-07-27T06:25:31.156Z","dependency_job_id":"37d04c93-afaa-44f8-aad5-02c0fa478a56","html_url":"https://github.com/PurpleBooth/termdiff","commit_stats":{"total_commits":71,"total_committers":4,"mean_commits":17.75,"dds":"0.46478873239436624","last_synced_commit":"3d04f74cac8499f50c64ee33e553291da438f4bd"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PurpleBooth%2Ftermdiff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PurpleBooth%2Ftermdiff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PurpleBooth%2Ftermdiff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PurpleBooth%2Ftermdiff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PurpleBooth","download_url":"https://codeload.github.com/PurpleBooth/termdiff/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245458195,"owners_count":20618693,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["diff","terminal"],"created_at":"2024-12-03T06:21:12.577Z","updated_at":"2026-04-30T18:31:27.961Z","avatar_url":"https://github.com/PurpleBooth.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# termdiff\n\nDiff a string for presentation to a user in the terminal.\n\n## Usage\n\n``` rust\nuse termdiff::{SignsTheme, DrawDiff};\nlet old = \"The quick brown fox and\\njumps over the sleepy dog\";\nlet new = \"The quick red fox and\\njumps over the lazy dog\";\nlet theme = SignsTheme::default();\nlet actual = format!(\"{}\", DrawDiff::new(old, new, \u0026theme));\n\nassert_eq!(\n    actual,\n    \"--- remove | insert +++\n-The quick brown fox and\n-jumps over the sleepy dog\n+The quick red fox and\n+jumps over the lazy dog\n\"\n);\n```\n\nAlternatively you can use this interface\n\n``` rust\nuse termdiff::{ArrowsTheme, diff};\nlet old = \"The quick brown fox and\\njumps over the sleepy dog\";\nlet new = \"The quick red fox and\\njumps over the lazy dog\";\nlet theme = ArrowsTheme::default();\nlet mut buffer: Vec\u003cu8\u003e = Vec::new();\ndiff(\u0026mut buffer, old, new, \u0026theme).unwrap();\nlet actual: String = String::from_utf8(buffer).expect(\"Not valid UTF-8\");\n\nassert_eq!(\n    actual,\n    \"\u003c left / \u003e right\n\u003cThe quick brown fox and\n\u003cjumps over the sleepy dog\n\u003eThe quick red fox and\n\u003ejumps over the lazy dog\n\"\n);\n```\n\nRead more at [Docs.rs](https://docs.rs/termdiff/)\n\n## Themes\n\nWe have a limited number of built in themes\n\n### Arrows\n\n![Demo of the arrows\nformat](./demo_arrows.png \"Demo of the arrows format\")\n\n### Signs\n\n![Demo of the signs format](./demo_signs.png \"Demo of the signs format\")\n\n### Custom\n\n``` rust\nuse termdiff::DrawDiff;\nuse termdiff::Theme;\nuse crossterm::style::Stylize;\nuse std::borrow::Cow;\n\n#[derive(Debug)]\nstruct MyTheme {}\nimpl Theme for MyTheme {\n    fn highlight_insert\u003c'this\u003e(\u0026self, input: \u0026'this str) -\u003e Cow\u003c'this, str\u003e {\n        input.into()\n    }\n\n    fn highlight_delete\u003c'this\u003e(\u0026self, input: \u0026'this str) -\u003e Cow\u003c'this, str\u003e {\n        input.into()\n    }\n\n    fn equal_content\u003c'this\u003e(\u0026self, input: \u0026'this str) -\u003e Cow\u003c'this, str\u003e {\n        input.into()\n    }\n\n    fn delete_content\u003c'this\u003e(\u0026self, input: \u0026'this str) -\u003e Cow\u003c'this, str\u003e {\n        input.into()\n    }\n\n    fn equal_prefix\u003c'this\u003e(\u0026self) -\u003e Cow\u003c'this, str\u003e {\n        \"=\".into()\n    }\n\n    fn delete_prefix\u003c'this\u003e(\u0026self) -\u003e Cow\u003c'this, str\u003e {\n        \"!\".into()\n    }\n\n    fn insert_line\u003c'this\u003e(\u0026self, input: \u0026'this str) -\u003e Cow\u003c'this, str\u003e {\n        input.into()\n    }\n\n    fn insert_prefix\u003c'this\u003e(\u0026self) -\u003e Cow\u003c'this, str\u003e {\n        \"|\".into()\n    }\n\n    fn line_end\u003c'this\u003e(\u0026self) -\u003e Cow\u003c'this, str\u003e {\n        \"\\n\".into()\n    }\n\n    fn header\u003c'this\u003e(\u0026self) -\u003e Cow\u003c'this, str\u003e {\n        format!(\"{}\\n\", \"Header\").into()\n    }\n}\n\nlet my_theme = MyTheme {};\n\nlet old = \"The quick brown fox and\\njumps over the sleepy dog\";\nlet new = \"The quick red fox and\\njumps over the lazy dog\";\nlet actual = format!(\"{}\", DrawDiff::new(old, new, \u0026my_theme));\n\nassert_eq!(\n    actual,\n    \"Header\n!The quick brown fox and\n!jumps over the sleepy dog\n|The quick red fox and\n|jumps over the lazy dog\n\"\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurplebooth%2Ftermdiff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpurplebooth%2Ftermdiff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurplebooth%2Ftermdiff/lists"}