Skip to content

Commit b47ecd8

Browse files
Add the ability to customize grey text
1 parent 9cc92e8 commit b47ecd8

3 files changed

Lines changed: 40 additions & 24 deletions

File tree

lib/render.js

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const config = require('./config');
66
signale.config({displayLabel: false});
77

88
const {error, log, note, pending, success} = signale;
9-
const {blue, green, grey, magenta, red, underline, yellow} = chalk;
9+
const {blue, green, magenta, red, underline, yellow} = chalk;
1010

1111
const priorities = {2: 'yellow', 3: 'red'};
1212

@@ -16,7 +16,7 @@ class Render {
1616
}
1717

1818
_colorBoards(boards) {
19-
return boards.map(x => grey(x)).join(' ');
19+
return boards.map(x => this.greyRender(x)).join(' ');
2020
}
2121

2222
_isBoardComplete(items) {
@@ -27,12 +27,12 @@ class Render {
2727
_getAge(birthday) {
2828
const daytime = 24 * 60 * 60 * 1000;
2929
const age = Math.round(Math.abs((birthday - Date.now()) / daytime));
30-
return (age === 0) ? '' : grey(`${age}d`);
30+
return (age === 0) ? '' : this.greyRender(`${age}d`);
3131
}
3232

3333
_getCorrelation(items) {
3434
const {tasks, complete} = this._getItemStats(items);
35-
return grey(`[${complete}/${tasks}]`);
35+
return this.greyRender(`[${complete}/${tasks}]`);
3636
}
3737

3838
_getItemStats(items) {
@@ -56,7 +56,7 @@ class Render {
5656
}
5757

5858
_buildTitle(key, items) {
59-
const title = (key === new Date().toDateString()) ? `${underline(key)} ${grey('[Today]')}` : underline(key);
59+
const title = (key === new Date().toDateString()) ? `${underline(key)} ${this.greyRender('[Today]')}` : underline(key);
6060
const correlation = this._getCorrelation(items);
6161
return {title, correlation};
6262
}
@@ -66,7 +66,7 @@ class Render {
6666

6767
const {_id} = item;
6868
prefix.push(' '.repeat(4 - String(_id).length));
69-
prefix.push(grey(`${_id}.`));
69+
prefix.push(this.greyRender(`${_id}.`));
7070

7171
return prefix.join(' ');
7272
}
@@ -80,7 +80,7 @@ class Render {
8080
if (!isComplete && priority > 1) {
8181
message.push(underline[priorities[priority]](description));
8282
} else {
83-
message.push(isComplete ? grey(description) : description);
83+
message.push(isComplete ? this.greyRender(description) : description);
8484
}
8585

8686
if (!isComplete && priority > 1) {
@@ -133,6 +133,12 @@ class Render {
133133
return note(msgObj);
134134
}
135135

136+
greyRender(text) {
137+
const func = chalk[this._configuration.greyRendererMethod] || chalk.grey;
138+
139+
return func(text);
140+
}
141+
136142
displayByBoard(data) {
137143
Object.entries(data).forEach(([board, items]) => {
138144
if (this._isBoardComplete(items) && !this._configuration.displayCompleteTasks) {
@@ -171,9 +177,9 @@ class Render {
171177
percent = percent >= 75 ? green(`${percent}%`) : percent >= 50 ? yellow(`${percent}%`) : `${percent}%`;
172178

173179
const status = [
174-
`${green(complete)} ${grey('done')}`,
175-
`${magenta(pending)} ${grey('pending')}`,
176-
`${blue(notes)} ${grey('notes')}`
180+
`${green(complete)} ${this.greyRender('done')}`,
181+
`${magenta(pending)} ${this.greyRender('pending')}`,
182+
`${blue(notes)} ${this.greyRender('notes')}`
177183
];
178184

179185
if (complete !== 0 && pending === 0 && notes === 0) {
@@ -184,8 +190,8 @@ class Render {
184190
log({prefix: '\n ', message: 'Type `taskbook --help` to get started!', suffix: yellow('★')});
185191
}
186192

187-
log({prefix: '\n ', message: grey(`${percent} of all tasks complete.`)});
188-
log({prefix: ' ', message: status.join(grey(' · ')), suffix: '\n'});
193+
log({prefix: '\n ', message: this.greyRender(`${percent} of all tasks complete.`)});
194+
log({prefix: ' ', message: status.join(this.greyRender(' · ')), suffix: '\n'});
189195
}
190196

191197
invalidCustomAppDir(path) {
@@ -195,7 +201,7 @@ class Render {
195201
}
196202

197203
invalidID(id) {
198-
const [prefix, suffix] = ['\n', grey(id)];
204+
const [prefix, suffix] = ['\n', this.greyRender(id)];
199205
const message = 'Unable to find item with id:';
200206
error({prefix, message, suffix});
201207
}
@@ -213,13 +219,13 @@ class Render {
213219
}
214220

215221
markComplete(ids) {
216-
const [prefix, suffix] = ['\n', grey(ids.join(', '))];
222+
const [prefix, suffix] = ['\n', this.greyRender(ids.join(', '))];
217223
const message = `Checked ${ids.length > 1 ? 'tasks' : 'task'}:`;
218224
success({prefix, message, suffix});
219225
}
220226

221227
markStarred(ids) {
222-
const [prefix, suffix] = ['\n', grey(ids.join(', '))];
228+
const [prefix, suffix] = ['\n', this.greyRender(ids.join(', '))];
223229
const message = `Starred ${ids.length > 1 ? 'items' : 'item'}:`;
224230
success({prefix, message, suffix});
225231
}
@@ -243,38 +249,38 @@ class Render {
243249
}
244250

245251
successCreate({_id, _isTask}) {
246-
const [prefix, suffix] = ['\n', grey(_id)];
252+
const [prefix, suffix] = ['\n', this.greyRender(_id)];
247253
const message = `Created ${_isTask ? 'task:' : 'note:'}`;
248254
success({prefix, message, suffix});
249255
}
250256

251257
successEdit(id) {
252-
const [prefix, suffix] = ['\n', grey(id)];
258+
const [prefix, suffix] = ['\n', this.greyRender(id)];
253259
const message = 'Updated description of item:';
254260
success({prefix, message, suffix});
255261
}
256262

257263
successDelete(ids) {
258-
const [prefix, suffix] = ['\n', grey(ids.join(', '))];
264+
const [prefix, suffix] = ['\n', this.greyRender(ids.join(', '))];
259265
const message = `Deleted ${ids.length > 1 ? 'items' : 'item'}:`;
260266
success({prefix, message, suffix});
261267
}
262268

263269
successMove(id, boards) {
264-
const [prefix, suffix] = ['\n', grey(boards.join(', '))];
265-
const message = `Move item: ${grey(id)} to`;
270+
const [prefix, suffix] = ['\n', this.greyRender(boards.join(', '))];
271+
const message = `Move item: ${this.greyRender(id)} to`;
266272
success({prefix, message, suffix});
267273
}
268274

269275
successPriority(id, level) {
270276
const prefix = '\n';
271-
const message = `Updated priority of task: ${grey(id)} to`;
277+
const message = `Updated priority of task: ${this.greyRender(id)} to`;
272278
const suffix = level === '3' ? red('high') : (level === '2' ? yellow('medium') : green('normal'));
273279
success({prefix, message, suffix});
274280
}
275281

276282
successRestore(ids) {
277-
const [prefix, suffix] = ['\n', grey(ids.join(', '))];
283+
const [prefix, suffix] = ['\n', this.greyRender(ids.join(', '))];
278284
const message = `Restored ${ids.length > 1 ? 'items' : 'item'}:`;
279285
success({prefix, message, suffix});
280286
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"default": {
3838
"taskbookDirectory": "",
3939
"displayCompleteTasks": true,
40-
"displayProgressOverview": true
40+
"displayProgressOverview": true,
41+
"greyRendererMethod": "grey"
4142
}
4243
},
4344
"scripts": {

readme.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ The following illustrates all the available options with their respective defaul
135135
{
136136
"taskbookDirectory": "",
137137
"displayCompleteTasks": true,
138-
"displayProgressOverview": true
138+
"displayProgressOverview": true,
139+
"greyRendererMethod": "grey"
139140
}
140141
```
141142

@@ -164,6 +165,14 @@ Display tasks that are marked as complete.
164165

165166
Display progress overview below the timeline and board views.
166167

168+
169+
##### `greyRendererMethod`
170+
171+
- Type: `String`
172+
- Default: `grey`
173+
174+
[Chalk Colors](https://github.com/chalk/chalk#colors) to render grey text. Use it in case you want to customize grey text render or we can not see it in terminal.
175+
167176
## Flight Manual
168177

169178
The following is a minor walkthrough containing a set of examples on how to use taskbook.

0 commit comments

Comments
 (0)