This repository has been archived by the owner on Jun 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.c
64 lines (59 loc) · 1.58 KB
/
util.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "consts.c"
#include <git2/oid.h>
#include <stdio.h>
void print_cwd(char *s) { printf(BLUE BOLD "%s" RESET, s); }
void print_git_branch(const char *s) {
printf(MAGENTA BOLD GIT_BRANCH " %s" RESET, s);
}
int stash_cb(size_t _index, const char *_msg, const git_oid *_id,
void *status) {
// has stash
(*(unsigned *)status) |= (1u << 3);
// we don't need to know how many stashes there are
return 114514;
}
void print_red_bold(const char *s) { printf(RED BOLD "%s" RESET, s); }
void print_git_info(unsigned map) {
if (map == 0) {
return;
}
char *git_info[] = {GIT_DELETED, GIT_ADDED, GIT_MODIFIED,
GIT_STASH, GIT_UNTRACKED, GIT_DIVERGE,
GIT_AHEAD_REMOTE, GIT_BEHIND_REMOTE};
print_red_bold(" [");
for (int i = 0; i < 8; i++) {
if (map & (1u << i)) {
print_red_bold(git_info[i]);
}
}
print_red_bold("]");
}
void print_job_count(int cnt) {
if (cnt != 0) {
printf(BLUE "[%d] " RESET, cnt);
}
}
void print_time(int time) {
if (time < 3) {
return;
}
if (time >= 3600) {
printf(YELLOW BOLD "%dh" RESET, time / 3600);
time %= 3600;
}
if (time >= 60) {
printf(YELLOW BOLD "%dm" RESET, time / 60);
time %= 60;
}
if (time != 0) {
printf(YELLOW BOLD "%ds" RESET, time);
}
printf(" ");
}
void print_prompt(int exit_code) {
if (exit_code == 0) {
printf(GREEN BOLD PROMPT RESET);
} else {
printf(RED BOLD PROMPT RESET);
}
}