From c56578808ad70e16f8911c843cdc43ddfcfeb557 Mon Sep 17 00:00:00 2001 From: Kyle Gottfried <6462596+Spitfire1900@users.noreply.github.com> Date: Thu, 28 Mar 2024 00:35:25 -0400 Subject: [PATCH] implement lines_added and lines_deleted --- TODO.md | 4 ++-- xontrib/pygitstatus/entrypoint.py | 6 ++++-- xontrib/pygitstatus/prompts.py | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/TODO.md b/TODO.md index 12e0dec..8415cf9 100644 --- a/TODO.md +++ b/TODO.md @@ -15,8 +15,8 @@ 'gitstatus.conflicts': , # DONE 'gitstatus.staged': , # DONE 'gitstatus.numstat': , # DONE -'gitstatus.lines_added': , # TODO -'gitstatus.lines_removed': # TODO , +'gitstatus.lines_added': , # DONE +'gitstatus.lines_removed': , # DONE 'gitstatus.clean': , # DONE 'gitstatus': , # TODO ``` diff --git a/xontrib/pygitstatus/entrypoint.py b/xontrib/pygitstatus/entrypoint.py index 7d9bc3d..546b1d1 100644 --- a/xontrib/pygitstatus/entrypoint.py +++ b/xontrib/pygitstatus/entrypoint.py @@ -3,8 +3,8 @@ from xonsh.built_ins import XonshSession from .prompts import (ahead, behind, branch, changed, clean, conflicts, curr_branch, - deleted, numstat, repo_path, short_head, staged, stash_count, tag, - tag_or_hash, untracked) + deleted, lines_added, lines_deleted, numstat, repo_path, + short_head, staged, stash_count, tag, tag_or_hash, untracked) def _load_xontrib_(xsh: XonshSession, **_) -> dict: @@ -36,6 +36,8 @@ def _load_xontrib_(xsh: XonshSession, **_) -> dict: prompt_fields['pygitstatus.clean'] = clean prompt_fields['pygitstatus.conflicts'] = conflicts prompt_fields['pygitstatus.deleted'] = deleted + prompt_fields['pygitstatus.lines_added'] = lines_added + prompt_fields['pygitstatus.lines_deleted'] = lines_deleted prompt_fields['pygitstatus.numstat'] = numstat prompt_fields['pygitstatus.repo_path'] = repo_path prompt_fields['pygitstatus.short_head'] = short_head diff --git a/xontrib/pygitstatus/prompts.py b/xontrib/pygitstatus/prompts.py index d03b25f..fa503ad 100644 --- a/xontrib/pygitstatus/prompts.py +++ b/xontrib/pygitstatus/prompts.py @@ -107,6 +107,28 @@ def deleted(fld: PromptField, ctx: PromptFields): fld.value = str(untracked_count) +@PromptField.wrap(prefix="{CYAN}+", suffix="{RESET}") +def lines_added(fld: PromptField, ctx: PromptFields): + fld.value = '' + + with contextlib.suppress(GitError): + repo = Repo('.') + diff = repo.diff() + if isinstance(diff, Diff) and (inserts := diff.stats.insertions) > 0: + fld.value = str(inserts) + + +@PromptField.wrap(prefix="{INTENSE_RED}-", suffix="{RESET}") +def lines_deleted(fld: PromptField, ctx: PromptFields): + fld.value = '' + + with contextlib.suppress(GitError): + repo = Repo('.') + diff = repo.diff() + if isinstance(diff, Diff) and (deletes := diff.stats.deletions) > 0: + fld.value = str(deletes) + + @PromptField.wrap() def numstat(fld: PromptField, ctx: PromptFields): fld.value = str((0, 0))