Skip to content

Commit

Permalink
implement lines_added and lines_deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Spitfire1900 committed Mar 28, 2024
1 parent 4a5f7eb commit c565788
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
'gitstatus.conflicts': <Prompt: gitstatus.conflicts>, # DONE
'gitstatus.staged': <Prompt: gitstatus.staged>, # DONE
'gitstatus.numstat': <Prompt: gitstatus.numstat>, # DONE
'gitstatus.lines_added': <Prompt: gitstatus.lines_added>, # TODO
'gitstatus.lines_removed': <Prompt: gitstatus.lines_removed> # TODO ,
'gitstatus.lines_added': <Prompt: gitstatus.lines_added>, # DONE
'gitstatus.lines_removed': <Prompt: gitstatus.lines_removed>, # DONE
'gitstatus.clean': <Prompt: gitstatus.clean>, # DONE
'gitstatus': <Prompt: gitstatus>, # TODO
```
Expand Down
6 changes: 4 additions & 2 deletions xontrib/pygitstatus/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions xontrib/pygitstatus/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit c565788

Please sign in to comment.