|
4 | 4 | from pathlib import Path
|
5 | 5 | import re
|
6 | 6 | import subprocess
|
7 |
| -from .style import Color, Styler |
| 7 | +from .styles import Painter |
| 8 | +from .styles import StyleClass as SC |
8 | 9 |
|
9 | 10 | #: Default maximum display length of the repository HEAD
|
10 | 11 | MAX_HEAD_LEN = 15
|
@@ -32,42 +33,43 @@ class GitStatus:
|
32 | 33 | #: repository is not a bare repository
|
33 | 34 | wkt: WorkTreeStatus | None
|
34 | 35 |
|
35 |
| - def display(self, style: Styler) -> str: |
| 36 | + def display(self, paint: Painter) -> str: |
36 | 37 | # Start building the status string with the separator:
|
37 |
| - p = style("@") |
| 38 | + p = "@" |
38 | 39 | if self.wkt is not None and self.wkt.stashed:
|
39 | 40 | # We have stashed changes:
|
40 |
| - p += style("+", fg=Color.LIGHT_YELLOW, bold=True) |
| 41 | + p += paint("+", SC.GIT_STASHED) |
41 | 42 | # Show HEAD; color changes depending on whether it's detached:
|
42 |
| - head_color = Color.LIGHT_BLUE if self.detached else Color.LIGHT_GREEN |
43 |
| - p += style(shorthead(self.head), fg=head_color) |
| 43 | + p += paint( |
| 44 | + shorthead(self.head), SC.GIT_DETACHED if self.detached else SC.GIT_HEAD |
| 45 | + ) |
44 | 46 | if self.ahead:
|
45 | 47 | # Show commits ahead of upstream:
|
46 |
| - p += style(f"+{self.ahead}", fg=Color.GREEN) |
| 48 | + p += paint(f"+{self.ahead}", SC.GIT_AHEAD) |
47 | 49 | if self.behind:
|
48 | 50 | # Ahead/behind separator:
|
49 |
| - p += style(",") |
| 51 | + p += "," |
50 | 52 | if self.behind:
|
51 | 53 | # Show commits behind upstream:
|
52 |
| - p += style(f"-{self.behind}", fg=Color.RED) |
| 54 | + p += paint(f"-{self.behind}", SC.GIT_BEHIND) |
53 | 55 | if (wkt := self.wkt) is not None:
|
54 | 56 | # Show staged/unstaged status:
|
55 | 57 | if wkt.staged and wkt.unstaged:
|
56 |
| - p += style("*", fg=Color.LIGHT_YELLOW, bold=True) |
| 58 | + p += paint("*", SC.GIT_STAGED_UNSTAGED) |
57 | 59 | elif wkt.staged:
|
58 |
| - p += style("*", fg=Color.GREEN) |
| 60 | + p += paint("*", SC.GIT_STAGED) |
59 | 61 | elif wkt.unstaged:
|
60 |
| - p += style("*", fg=Color.RED) |
| 62 | + p += paint("*", SC.GIT_UNSTAGED) |
61 | 63 | # else: Show nothing
|
62 | 64 | if wkt.untracked:
|
63 | 65 | # There are untracked files:
|
64 |
| - p += style("+", fg=Color.RED, bold=True) |
| 66 | + p += paint("+", SC.GIT_UNTRACKED) |
65 | 67 | if wkt.state is not None:
|
66 | 68 | # The repository is in the middle of something special:
|
67 |
| - p += style("[" + wkt.state.value + "]", fg=Color.MAGENTA) |
| 69 | + p += paint("[" + wkt.state.value + "]", SC.GIT_STATE) |
68 | 70 | if wkt.conflict:
|
69 | 71 | # There are conflicted files:
|
70 |
| - p += style("!", fg=Color.RED, bold=True) |
| 72 | + p += paint("!", SC.GIT_CONFLICT) |
71 | 73 | return p
|
72 | 74 |
|
73 | 75 |
|
|
0 commit comments