-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.js
106 lines (84 loc) · 3.82 KB
/
views.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const boxen = require('boxen');
const chalk = require('chalk');
const gradient = require('gradient-string');
const stringLength = require('string-length');
// -------------------------------------------------------------------- //
// -------------------------------------------------------------------- //
// -------------------------------------------------------------------- //
function viewGit(git) {
const lines = git.split('\n');
const lookup = {};
let modifications = 0;
for (let line of lines) {
if (line[0] === '#') {
words = line.split(' ');
lookup[words[1]] = words.slice(2);
} else {
modifications += 1;
}
}
const [oid] = lookup['branch.oid'] || ['OID'];
const [head] = lookup['branch.head'] || ['HEAD'];
const [upstream] = lookup['branch.upstream'] || ['???'];
let [a, b] = lookup['branch.ab'] || ['+0', '-0'];
a = Math.abs(parseInt(a));
b = Math.abs(parseInt(b));
total = modifications + a + b;
if (total > 0) {
flag = '🔥';
} else {
flag = '🌱';
}
const short_oid = oid.slice(0, 7);
return ` ${chalk.yellow(head)} ${chalk.green(upstream)} ${flag}`;
}
// -------------------------------------------------------------------- //
// -------------------------------------------------------------------- //
// -------------------------------------------------------------------- //
function viewConda(conda) {
return chalk.black.bgYellow(' ' + conda) + chalk.yellow('');
}
// -------------------------------------------------------------------- //
// -------------------------------------------------------------------- //
// -------------------------------------------------------------------- //
function viewUser(user) {
return chalk.hex('#33ffcc')(user);
}
// -------------------------------------------------------------------- //
// -------------------------------------------------------------------- //
// -------------------------------------------------------------------- //
function viewHostname(hostname) {
return chalk.dim.white.inverse(hostname);
}
// -------------------------------------------------------------------- //
// -------------------------------------------------------------------- //
// -------------------------------------------------------------------- //
function viewHex(hex) {
return chalk.hex('#4a3f35').italic(hex);
}
// -------------------------------------------------------------------- //
// -------------------------------------------------------------------- //
// -------------------------------------------------------------------- //
function viewNodeVer(nodever) {
return chalk.yellow(nodever);
}
// -------------------------------------------------------------------- //
// -------------------------------------------------------------------- //
// -------------------------------------------------------------------- //
function viewDirectory(home, directory) {
if (directory.startsWith(home)) directory = directory.replace(home, '~');
return chalk.hex('#ff33cc')('') + chalk.black.bgHex('#ff33cc')(' ' + directory) + chalk.hex('#ff33cc')('');
}
// -------------------------------------------------------------------- //
// -------------------------------------------------------------------- //
// -------------------------------------------------------------------- //
module.exports.display = (conda, user, hostname, home, directory, hex, nodever, git) => {
// https://en.wikipedia.org/wiki/Box-drawing_character
let output = `\n${viewConda(conda)} ${viewDirectory(home, directory)}`;
if (git) output += ` ${viewGit(git)}`;
output += '\n ';
process.stdout.write(output);
};
// -------------------------------------------------------------------- //
// -------------------------------------------------------------------- //
// -------------------------------------------------------------------- //