-
Notifications
You must be signed in to change notification settings - Fork 0
/
org.conky.js
77 lines (74 loc) · 1.79 KB
/
org.conky.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
const org = require('org-mode-parser');
const colors = [
{
pattern: /(TODO)/g,
color: '#ffaa88'
},
{
pattern: /(DONE)/g,
color: '#aaff88'
},
{
pattern: /(CLOSED)/g,
color: '#0295a9'
},
{
pattern: /(DEADLINE)/g,
color: '#FF6F69'
},
{
pattern: /(SCHEDULED)/g,
color: '#f8e2a8'
}
]
function colorize(line) {
const match = colors.find((obj) => {
return obj.pattern.test(line);
});
if (match) {
return line.replace(match.pattern, '${color ' + match.color + '}$1${color}')
} else {
return line;
}
}
org.makelist(process.argv.slice(2)[0], (nodelist) => {
const min = process.argv.slice(3)[0].split(',')[0] || 0;
const max = process.argv.slice(3)[0].split(',')[1] || 100;
let i = 0;
nodelist.forEach(node => {
let tags = '';
if (Object.keys(node.tags).length) {
tags = `:${Object.keys(node.tags).join(':')}:`;
}
if (i >= min && i < max) {
if (node.todo) {
console.log(`${' '.repeat(node.level)} ${colorize(node.todo)} ${node.headline} ${tags}`);
} else {
console.log(`${' '.repeat(node.level)} ${colorize(node.headline)} ${tags}`);
}
}
i += 1;
if (node.body) {
node.body.split('\n').forEach(line => {
if (line) {
if (i >= min && i < max) {
console.log(`${' '.repeat(node.level + 1)} ${colorize(line)}`);
}
i += 1;
}
})
}
if (node.deadline) {
if (i >= min && i < max) {
console.log(`${' '.repeat(node.level + 1)} ${colorize('DEADLINE')}: ${node.deadline}`);
}
i += 1;
}
if (node.scheduled) {
if (i >= min && i < max) {
console.log(`${' '.repeat(node.level + 1)} ${colorize('SCHEDULED')}: ${node.scheduled}`);
}
i += 1;
}
});
});