wrote an improved repo status output.
This commit is contained in:
parent
1e4d8c18c7
commit
02fc9cc8bf
@ -9,14 +9,37 @@ import json
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
def ind():
|
||||
print('\u2B06\uFE0F\u0031\uFE0F\u20E3') # ⬆️1️⃣
|
||||
print('\u2B07\uFE0F\u0032\uFE0F\u20E3') # ⬇️2️⃣
|
||||
for i in range(1, 6):
|
||||
digit = str(i)
|
||||
keycap = digit + '\uFE0F\u20E3'
|
||||
print(f"\u2B06\uFE0F{keycap} Up {i}")
|
||||
print(f"\u2B07\uFE0F{keycap} Down {i}")
|
||||
def to_keycap(ch: str) -> str:
|
||||
"""
|
||||
Converts a single character (0-9, #, *) into a keycap emoji.
|
||||
Returns the original character if not valid for keycaps.
|
||||
"""
|
||||
if ch in '0123456789#*':
|
||||
return ch + '\uFE0F\u20E3'
|
||||
else:
|
||||
raise ValueError(f"Unsupported keycap character: {ch!r}")
|
||||
|
||||
def indicators(props, ind = "tl"):
|
||||
tl = "\U0001F7E2"
|
||||
if props["ab"]["push"] + props["ab"]["pull"] > 0:
|
||||
tl = "\U0001F7E1"
|
||||
if props["n"] > 0:
|
||||
tl = "\U0001F534"
|
||||
unstaged = "\U0001F4DD"
|
||||
up_keycap = "\U0001F53C" # "\u2B06\uFE0F"
|
||||
down_keycap = "\U0001F53D" # "\u2B07\uFE0F"
|
||||
status_digit = "#" if props["n"] > 9 else str(props["n"] % 10)
|
||||
status_indicator = f"{to_keycap(status_digit)}{unstaged}"
|
||||
push_digit = "#" if props["ab"]["push"] > 9 else str(props["ab"]["push"] % 10)
|
||||
push_indicator = f"{to_keycap(push_digit)}{up_keycap}"
|
||||
pull_digit = "#" if props["ab"]["pull"] > 9 else str(props["ab"]["pull"] % 10)
|
||||
pull_indicator = f"{to_keycap(pull_digit)}{down_keycap}"
|
||||
ret = "?"
|
||||
if ind == "tl":
|
||||
ret = f"{tl}"
|
||||
if ind == "flags":
|
||||
ret = f"{status_indicator} {push_indicator} {pull_indicator}"
|
||||
return ret
|
||||
|
||||
def rm(p):
|
||||
if os.path.exists(p):
|
||||
@ -168,10 +191,14 @@ if __name__ == "__main__":
|
||||
dat[k] = props
|
||||
with open(cache_file, "wt") as fout:
|
||||
json.dump(dat, fout, indent = 2)
|
||||
ml = 0
|
||||
for k in dat:
|
||||
status = "-" if dat[k]["n"] == 0 else dat[k]["n"]
|
||||
print(f"{str(status).rjust(3)} {k}")
|
||||
print(json.dumps(dat, indent = 2))
|
||||
ml = len(k) if len(k) > ml else ml
|
||||
for k in dat:
|
||||
tl = indicators(dat[k], "tl")
|
||||
flags = indicators(dat[k], "flags")
|
||||
print(f" {tl} {k.ljust(ml + 1)} {flags}")
|
||||
# print(json.dumps(dat, indent = 2))
|
||||
elif sys.argv[1] == "status":
|
||||
dat = dict()
|
||||
cache_file = filepath("status")
|
||||
|
Loading…
x
Reference in New Issue
Block a user