From 2259c00124f3e73af6e22bdbd1590387e97533fc Mon Sep 17 00:00:00 2001 From: exshak Date: Thu, 1 Jul 2021 17:41:43 -0400 Subject: [PATCH 1/3] fix: stat range error, use xdg_config_home default --- bin/leetcode | 2 +- lib/commands/stat.js | 2 +- lib/file.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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/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/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() { From fa6736afd2130a01b34a832d6811ac1dc6c888a5 Mon Sep 17 00:00:00 2001 From: exshak Date: Thu, 1 Jul 2021 17:49:01 -0400 Subject: [PATCH 2/3] add: dracula color palette, nvim & python3 defaults --- colors/dracula.json | 11 +++++++++++ lib/config.js | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 colors/dracula.json 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/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: '' From 69b91aab763976be6869b5e3bd4f260b44bd46a6 Mon Sep 17 00:00:00 2001 From: exshak Date: Thu, 1 Jul 2021 18:32:02 -0400 Subject: [PATCH 3/3] feat: show formatted problem description --- lib/commands/show.js | 7 +++++-- lib/core.js | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) 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/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;