diff --git a/bin/leetcode b/bin/leetcode index 19bb1e35..beb950c6 100755 --- a/bin/leetcode +++ b/bin/leetcode @@ -1,3 +1,3 @@ -#!/usr/bin/env node +#!/usr/bin/env node --no-warnings require('../lib/cli').run(); diff --git a/colors/dracula.json b/colors/dracula.json new file mode 100644 index 00000000..ef32d09e --- /dev/null +++ b/colors/dracula.json @@ -0,0 +1,11 @@ +{ + "black": "#282a36", + "blue": "#6272a4", + "cyan": "#8be9fd", + "gray": "#44475a", + "green": "#50fa7b", + "magenta": "#bd93f9", + "red": "#ff5555", + "white": "#f8f8f2", + "yellow": "#ffb86c" +} diff --git a/lib/commands/show.js b/lib/commands/show.js index 93f643e2..022a4403 100644 --- a/lib/commands/show.js +++ b/lib/commands/show.js @@ -96,10 +96,11 @@ function genFileName(problem, opts) { } function showProblem(problem, argv) { + const path = require('path'); const taglist = [problem.category] .concat(problem.companies || []) .concat(problem.tags || []) - .map(x => h.badge(x, 'blue')) + .map(x => h.badge(x, 'gray')) .join(' '); const langlist = problem.templates .map(x => h.badge(x.value, 'yellow')) @@ -169,11 +170,13 @@ function showProblem(problem, argv) { if (problem.totalSubmit) log.printf('* Total Submissions: %s', problem.totalSubmit); if (problem.testable && problem.testcase) + problem.testcase = problem.testcase.replace(/\n/g, ' ') log.printf('* Testcase Example: %s', chalk.yellow(util.inspect(problem.testcase))); if (filename) - log.printf('* Source Code: %s', chalk.yellow.underline(filename)); + log.printf('* Source Code: %s', chalk.gray.underline(path.basename(filename))); log.info(); + problem = core.formatProblem(problem, {lang: argv.lang}); log.info(problem.desc); } diff --git a/lib/commands/stat.js b/lib/commands/stat.js index 44cc72dc..3b8c4a71 100644 --- a/lib/commands/stat.js +++ b/lib/commands/stat.js @@ -168,7 +168,7 @@ function showCal(problems) { const idx = now.diff(d, 'days'); const j = (N_WEEKS - idx / N_WEEKDAYS + 1) * 2; - if (j >= 0) buf.write(MONTHS[d.month()], j); + if (j >= 0) buf.write(MONTHS[d.month()], ~~j); } log.printf('%7s%s', ' ', buf.toString()); diff --git a/lib/config.js b/lib/config.js index 82cfee17..38d0c03d 100644 --- a/lib/config.js +++ b/lib/config.js @@ -71,8 +71,8 @@ const DEFAULT_CONFIG = { retry: 2 }, code: { - editor: 'vim', - lang: 'cpp' + editor: 'nvim', + lang: 'python3' }, file: { show: '${fid}.${slug}', @@ -80,7 +80,7 @@ const DEFAULT_CONFIG = { }, color: { enable: true, - theme: 'default' + theme: 'dracula' }, icon: { theme: '' diff --git a/lib/core.js b/lib/core.js index c9df6322..18cfe72f 100644 --- a/lib/core.js +++ b/lib/core.js @@ -89,7 +89,7 @@ core.getProblem = function(keyword, needTranslation, cb) { this.getProblems(needTranslation, function(e, problems) { if (e) return cb(e); - keyword = Number(keyword) || keyword; + keyword = Number(keyword) || keyword; const metaFid = file.exist(keyword) ? Number(file.meta(keyword).id) : NaN; const problem = problems.find(function(x) { return x.fid + '' === keyword + '' || x.fid + '' === metaFid + '' || x.name === keyword || x.slug === keyword; @@ -135,4 +135,17 @@ core.exportProblem = function(problem, opts) { return file.render(opts.tpl, data); }; +core.formatProblem = function(problem, opts) { + const data = _.extend({}, problem); + if (!data.lang) data.lang = opts.lang; + data.comment = h.langToCommentStyle(data.lang); + let desc = data.desc; + desc = desc.replace(/<\/sup>/gm, '').replace(//gm, '^'); + desc = he.decode(cheerio.load(desc).root().text()); + desc = desc.replace(/\r\n/g, '\n').replace(/^ /mg, '⁠').replace(/\n\n/g, '\n'); + const wrap = require('wordwrap')(79 - data.comment.line.length); + data.desc = wrap(desc); + return data; +}; + module.exports = core; diff --git a/lib/file.js b/lib/file.js index c2262df1..210df537 100644 --- a/lib/file.js +++ b/lib/file.js @@ -25,7 +25,7 @@ file.userHomeDir = function() { }; file.homeDir = function() { - return path.join(this.userHomeDir(), '.lc'); + return path.join(this.userHomeDir(), '.config/lc'); }; file.appDir = function() {