Skip to content

Commit ca681e9

Browse files
lestadimevro
authored andcommitted
feat: change title colors and formatting (#209)
also indent `action` line
1 parent eda2ba4 commit ca681e9

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/core.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ function defaultTitleFormatter(options) {
3131
return (action, time, took) => {
3232
const parts = [`action`];
3333

34-
if (timestamp) parts.push(`@ ${time}`);
35-
parts.push(String(action.type));
36-
if (duration) parts.push(`(in ${took.toFixed(2)} ms)`);
34+
parts.push(`%c${String(action.type)}`);
35+
if (timestamp) parts.push(`%c@ ${time}`);
36+
if (duration) parts.push(`%c(in ${took.toFixed(2)} ms)`);
3737

3838
return parts.join(` `);
3939
};
@@ -65,16 +65,20 @@ export function printBuffer(buffer, options) {
6565
const isCollapsed = (typeof collapsed === `function`) ? collapsed(() => nextState, action, logEntry) : collapsed;
6666

6767
const formattedTime = formatTime(startedTime);
68-
const titleCSS = colors.title ? `color: ${colors.title(formattedAction)};` : null;
68+
const titleCSS = colors.title ? `color: ${colors.title(formattedAction)};` : ``;
69+
const headerCSS = [`color: gray; font-weight: lighter;`];
70+
headerCSS.push(titleCSS);
71+
if (options.timestamp) headerCSS.push(`color: gray; font-weight: lighter;`);
72+
if (options.duration) headerCSS.push(`font-style: italic; color: gray; font-weight: lighter;`);
6973
const title = titleFormatter(formattedAction, formattedTime, took);
7074

7175
// Render
7276
try {
7377
if (isCollapsed) {
74-
if (colors.title) logger.groupCollapsed(`%c ${title}`, titleCSS);
78+
if (colors.title) logger.groupCollapsed(`%c ${title}`, ...headerCSS);
7579
else logger.groupCollapsed(title);
7680
} else {
77-
if (colors.title) logger.group(`%c ${title}`, titleCSS);
81+
if (colors.title) logger.group(`%c ${title}`, ...headerCSS);
7882
else logger.group(title);
7983
}
8084
} catch (e) {
@@ -92,12 +96,12 @@ export function printBuffer(buffer, options) {
9296
}
9397

9498
if (actionLevel) {
95-
if (colors.action) logger[actionLevel](`%c action`, `color: ${colors.action(formattedAction)}; font-weight: bold`, formattedAction);
99+
if (colors.action) logger[actionLevel](`%c action `, `color: ${colors.action(formattedAction)}; font-weight: bold`, formattedAction);
96100
else logger[actionLevel](`action `, formattedAction);
97101
}
98102

99103
if (error && errorLevel) {
100-
if (colors.error) logger[errorLevel](`%c error`, `color: ${colors.error(error, prevState)}; font-weight: bold`, error);
104+
if (colors.error) logger[errorLevel](`%c error `, `color: ${colors.error(error, prevState)}; font-weight: bold;`, error);
101105
else logger[errorLevel](`error `, error);
102106
}
103107

0 commit comments

Comments
 (0)