jsir 2.4.2 → 2.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cmd/oaa.js +7 -2
- package/deps/util.js +40 -4
- package/package.json +1 -1
package/cmd/oaa.js
CHANGED
|
@@ -12,7 +12,8 @@ const {
|
|
|
12
12
|
getEditor, errorStr, getConfigDir,
|
|
13
13
|
getFullPath, parseUniqueName, toUniqueName, isJsirFileName, toJsirFileName,
|
|
14
14
|
getAlias, wrapperJsirText, eia, getKeyTips, getValTips, getJsirTypeKey,
|
|
15
|
-
createDetachedProcess, interceptStdStreams
|
|
15
|
+
createDetachedProcess, interceptStdStreams,
|
|
16
|
+
draftModify
|
|
16
17
|
} = $lib;
|
|
17
18
|
const _args = process.argv.slice(2).map(trim);
|
|
18
19
|
const evalCode = require('../deps/evalCode')
|
|
@@ -600,7 +601,11 @@ async function _wrapperInput(str) {
|
|
|
600
601
|
} else {
|
|
601
602
|
let fLine = trim(str.substr(1))
|
|
602
603
|
if (fLine) {
|
|
603
|
-
|
|
604
|
+
if (/\s+[+-]$/.test(fLine)) {
|
|
605
|
+
console.log((await draftModify(fLine)).join("\n"))
|
|
606
|
+
} else {
|
|
607
|
+
console.log(draftQuery(fLine).join("\n"))
|
|
608
|
+
}
|
|
604
609
|
} else {
|
|
605
610
|
console.$draft(await nextText(line => line, fstr))
|
|
606
611
|
}
|
package/deps/util.js
CHANGED
|
@@ -424,6 +424,42 @@ function parseDraftLog(draftPath) {
|
|
|
424
424
|
}
|
|
425
425
|
|
|
426
426
|
function draftQuery(fLine) {
|
|
427
|
+
fLine = fLine.trim();
|
|
428
|
+
let results = [];
|
|
429
|
+
let draftPath = getLibDataDir() + "/log/draft.log";
|
|
430
|
+
if (!fs.existsSync(draftPath)) {
|
|
431
|
+
return results;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
let { lines } = parseDraftLog(draftPath);
|
|
435
|
+
let limit = 0;
|
|
436
|
+
let filterKeywords = '';
|
|
437
|
+
|
|
438
|
+
if (/\s+\d+$/.test(fLine)) {
|
|
439
|
+
filterKeywords = fLine.replace(/\s+\d+$/, '');
|
|
440
|
+
limit = parseInt(fLine.match(/\d+$/)[0]);
|
|
441
|
+
} else {
|
|
442
|
+
filterKeywords = fLine;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (/^\d+$/.test(filterKeywords)) {
|
|
446
|
+
results = lines.slice(- parseInt(filterKeywords));
|
|
447
|
+
} else {
|
|
448
|
+
lines.forEach(line => {
|
|
449
|
+
if (isMatch(line, filterKeywords)) {
|
|
450
|
+
results.push(line);
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (limit > 0) {
|
|
456
|
+
results = results.slice(-limit);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
return results;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
async function draftModify(fLine) {
|
|
427
463
|
fLine = fLine.trim();
|
|
428
464
|
let results = [];
|
|
429
465
|
let deleteRanges = [];
|
|
@@ -486,7 +522,7 @@ function draftQuery(fLine) {
|
|
|
486
522
|
if (isEdit && results.length === 1) {
|
|
487
523
|
let tempPath = getLibDataDir() + "/log/draft.temp";
|
|
488
524
|
fs.writeFileSync(tempPath, results[0].split(/\n/).slice(1).join('\n'))
|
|
489
|
-
|
|
525
|
+
await eia(getEditor(), [tempPath])
|
|
490
526
|
let tempText = String(fs.readFileSync(tempPath))
|
|
491
527
|
let lineRange = lineRanges.get(results[0]);
|
|
492
528
|
let before = allLines.filter((_, index) => {
|
|
@@ -702,9 +738,8 @@ function createLimitLogger(fileName, {
|
|
|
702
738
|
if (error) {
|
|
703
739
|
global.$newError = true;
|
|
704
740
|
}
|
|
705
|
-
text = `${pad(3, String(process.pid%1000), process.pid >= 1000 ? '0':' ')}> ${text}`
|
|
706
741
|
if (time) {
|
|
707
|
-
text = `${timeStr('YYYY-MM-DD HH:mm:ss.SSS')} ${text}`
|
|
742
|
+
text = `${timeStr('YYYY-MM-DD HH:mm:ss.SSS')} ${pad(3, String(process.pid%1000), process.pid >= 1000 ? '0':' ')}> ${text}`
|
|
708
743
|
}
|
|
709
744
|
syncQueue(() => fp.appendFile(logPath, text + '\n'), logPath)
|
|
710
745
|
let _minNum = (Date.now()/(1000 * 60 * 10)).toFixed(0)
|
|
@@ -2164,5 +2199,6 @@ module.exports = {
|
|
|
2164
2199
|
getJsirTypeKey,
|
|
2165
2200
|
isRunningInBackground,
|
|
2166
2201
|
createDetachedProcess,
|
|
2167
|
-
interceptStdStreams
|
|
2202
|
+
interceptStdStreams,
|
|
2203
|
+
draftModify
|
|
2168
2204
|
}
|