Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ For the list of available translations, please refer to the main [tldr](https://

You can configure the `tldr` client by adding a `.tldrrc` file in your HOME directory. You can copy the contents of the `config.json` file from the repo to get the basic structure to start with, and modify it to suit your needs.

The default color theme is the one named `"simple"`. You can change the theme by assigning a different value to the `"theme"` variable -- either to one of the pre-configured themes, or to a new theme that you have previously created in the `"themes"` section. Note that the colors and text effects you can choose are limited. Refer to the [chalk documentation](https://github.com/chalk/chalk#styles) for all options.
The default color theme is the one named `"simple"`. You can change the theme by assigning a different value to the `"theme"` variable -- either to one of the pre-configured themes, or to a new theme that you have previously created in the `"themes"` section. Note that the colors and text effects you can choose are limited. Refer to the [Node.js documentation](https://nodejs.org/api/util.html#modifiers) for all options.

```json
{
Expand Down
6 changes: 3 additions & 3 deletions lib/parser.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

const { styleText } = require('node:util');
const unescape = require('lodash/unescape');
const marked = require('marked');
const chalk = require('chalk');
const index = require('./index');

const allElements = [
Expand Down Expand Up @@ -70,11 +70,11 @@ exports.parse = (markdown) => {
};

r.strong = (text) => {
return chalk.bold(text);
return styleText('bold', text);
};

r.em = (text) => {
return chalk.italic(text);
return styleText('italic', text);
};

r.listitem = (text) => {
Expand Down
11 changes: 5 additions & 6 deletions lib/theme.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
'use strict';

const get = require('lodash/get');
const isEmpty = require('lodash/isEmpty');
const identity = require('lodash/identity');
const chalk = require('chalk');
const { styleText } = require('node:util');

// Translates strings like 'red, underline, bold'
// into function chalk.red.underline.bold(text)
// into function styleText(['red', 'underline', 'bold'], text)
function buildStylingFunction(styles) {
if (isEmpty(styles)) {
return identity;
}
let stylingFunction = chalk;
let stylesPath = styles.replace(/,\s*/g, '.');
return get(stylingFunction, stylesPath);

let stylesArr = styles.split(/,\s*/g);
return (text) => styleText(stylesArr, text);
}

class Theme {
Expand Down
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"dependencies": {
"adm-zip": "^0.5.10",
"axios": "^1.6.0",
"chalk": "^4.1.0",
"commander": "^6.1.0",
"fs-extra": "^11.2.0",
"glob": "^11.0.0",
Expand Down
36 changes: 18 additions & 18 deletions test/theme.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { styleText } = require('node:util');
const Theme = require('../lib/theme');
const chalk = require('chalk');

describe('Theme', () => {

Expand All @@ -18,31 +18,31 @@ describe('Theme', () => {
it('should render name with green and bold', () => {
theme.renderCommandName('text')
.should.equal(
chalk.green.bold('text'));
styleText(['green', 'bold'], 'text'));
});

it('should render description with red and underline', () => {
theme.renderMainDescription('text')
.should.equal(
chalk.red.underline('text'));
styleText(['red', 'underline'], 'text'));
});

it('should render example description with blue', () => {
theme.renderExampleDescription('text')
.should.equal(
chalk.blue('text'));
styleText('blue', 'text'));
});

it('should render example code with blue', () => {
theme.renderExampleCode('text')
.should.equal(
chalk.bold('text'));
styleText('bold', 'text'));
});

it('should render example argument with yellow, dim, underline', () => {
theme.renderExampleToken('text')
.should.equal(
chalk.yellow.dim.underline('text'));
styleText(['yellow', 'dim', 'underline'], 'text'));
});
});

Expand All @@ -59,31 +59,31 @@ describe('Theme', () => {
it('should render name with greenBright and bold', () => {
theme.renderCommandName('text')
.should.equal(
chalk.greenBright.bold('text'));
styleText(['greenBright', 'bold'], 'text'));
});

it('should render description with greenBright and bold', () => {
theme.renderMainDescription('text')
.should.equal(
chalk.greenBright.bold('text'));
styleText(['greenBright', 'bold'], 'text'));
});

it('should render example description with greenBright', () => {
theme.renderExampleDescription('text')
.should.equal(
chalk.greenBright('text'));
styleText('greenBright', 'text'));
});

it('should render example code with redBright', () => {
theme.renderExampleCode('text')
.should.equal(
chalk.redBright('text'));
styleText('redBright', 'text'));
});

it('should render example argument with white', () => {
theme.renderExampleToken('text')
.should.equal(
chalk.white('text'));
styleText('white', 'text'));
});
});

Expand All @@ -102,37 +102,37 @@ describe('Theme', () => {
it('should render name with greenBright and bold', () => {
theme.renderCommandName('text')
.should.equal(
chalk.greenBright.bold('text'));
styleText(['greenBright', 'bold'], 'text'));
});

it('should render description with greenBright and bold', () => {
theme.renderMainDescription('text')
.should.equal(
chalk.greenBright.bold('text'));
styleText(['greenBright', 'bold'], 'text'));
});

it('should render example description with greenBright', () => {
theme.renderExampleDescription('text')
.should.equal(
chalk.greenBright('text'));
styleText('greenBright', 'text'));
});

it('should render example code with redBright', () => {
theme.renderExampleCode('text')
.should.equal(
chalk.redBright('text'));
styleText('redBright', 'text'));
});

it('should render example arguments with magenta, white, and blue, for boolean, number, and string respectively', () => {
theme.renderExampleToken('true')
.should.equal(
chalk.magenta('true'));
styleText('magenta', 'true'));
theme.renderExampleToken('9')
.should.equal(
chalk.white('9'));
styleText('white', '9'));
theme.renderExampleToken('text')
.should.equal(
chalk.blue('text'));
styleText('blue', 'text'));
});
});
});