oipage 1.2.1 → 1.3.0-alpha.0
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/CHANGELOG +59 -51
- package/README.md +80 -80
- package/bin/data/mineTypes.json +104 -104
- package/bin/disk.js +31 -31
- package/bin/help.js +24 -24
- package/bin/run +95 -95
- package/bin/serve.js +108 -108
- package/bin/template/404.html +171 -171
- package/bin/tools/format.js +88 -88
- package/bin/tools/network.js +42 -42
- package/bin/tools/resolve404.js +83 -83
- package/bin/tools/resolveImport.js +79 -79
- package/nodejs/animation/index.d.ts +11 -11
- package/nodejs/animation/index.js +104 -104
- package/nodejs/cmdlog/index.d.ts +20 -20
- package/nodejs/cmdlog/index.js +75 -75
- package/nodejs/disk/index.d.ts +16 -16
- package/nodejs/disk/index.js +78 -78
- package/nodejs/logform/index.d.ts +18 -18
- package/nodejs/logform/index.js +94 -94
- package/nodejs/reader/index.d.ts +33 -0
- package/nodejs/reader/index.js +26 -0
- package/nodejs/throttle/index.d.ts +30 -30
- package/nodejs/throttle/index.js +50 -50
- package/package.json +40 -40
- package/web/animation/index.d.ts +11 -11
- package/web/animation/index.js +104 -104
- package/web/onReady/index.d.ts +7 -7
- package/web/onReady/index.js +8 -8
- package/web/reader/index.d.ts +33 -0
- package/web/reader/index.js +25 -0
- package/web/style/index.d.ts +21 -21
- package/web/style/index.js +19 -19
- package/web/throttle/index.d.ts +30 -30
- package/web/throttle/index.js +50 -50
package/nodejs/cmdlog/index.js
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* cmdlog of OIPage v1.
|
|
2
|
+
* cmdlog of OIPage v1.3.0-alpha.0
|
|
3
3
|
* git+https://github.com/oi-contrib/OIPage.git
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
// 预定义的常量
|
|
7
|
-
const MOVE_LEFT = Buffer.from('1b5b3130303044', 'hex').toString();
|
|
8
|
-
const MOVE_UP = Buffer.from('1b5b3141', 'hex').toString();
|
|
9
|
-
const CLEAR_LINE = Buffer.from('1b5b304b', 'hex').toString();
|
|
10
|
-
|
|
11
|
-
// 计算字符串长度的方法
|
|
12
|
-
const stringwidth = function (str) {
|
|
13
|
-
return str.length;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* 不换行打印
|
|
18
|
-
* @param {string} stream 打印的内容
|
|
19
|
-
*/
|
|
20
|
-
let linelog = (function (stream) {
|
|
21
|
-
|
|
22
|
-
// 用来记录前置有多少行需要回退
|
|
23
|
-
let prevLineCount = 0;
|
|
24
|
-
|
|
25
|
-
// 返回实际同行打印的方法
|
|
26
|
-
return function (nextStr) {
|
|
27
|
-
if (arguments.length == 0) {
|
|
28
|
-
prevLineCount = 0;
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
let txt = "";
|
|
32
|
-
|
|
33
|
-
// 清除屏幕
|
|
34
|
-
for (let i = 0; i < prevLineCount; i++) {
|
|
35
|
-
txt += MOVE_LEFT + CLEAR_LINE + (i < prevLineCount - 1 ? MOVE_UP : '');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// 写入屏幕
|
|
39
|
-
stream.write(txt + nextStr);
|
|
40
|
-
|
|
41
|
-
// 重新计算需要回滚多少行
|
|
42
|
-
let prevLines = nextStr.split('\n');
|
|
43
|
-
prevLineCount = 0;
|
|
44
|
-
for (let i = 0; i < prevLines.length; i++) {
|
|
45
|
-
// 因为有时候文字过多,因此拿总长度除以一行长度得出真实的行数
|
|
46
|
-
prevLineCount += (Math.ceil(stringwidth(prevLines[i]) / stream.columns) || 1);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
};
|
|
50
|
-
})(process.stdout);
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* 进度打印
|
|
54
|
-
*
|
|
55
|
-
* @param {number} percentum 进度0-100
|
|
56
|
-
* @param {string} stream 说明文字,可选
|
|
57
|
-
*/
|
|
58
|
-
function deeplog (percentum, stream) {
|
|
59
|
-
if (arguments.length == 0) {
|
|
60
|
-
linelog();
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (arguments.length <= 1) stream = "";
|
|
65
|
-
|
|
66
|
-
let txt = "",
|
|
67
|
-
i = 0;
|
|
68
|
-
|
|
69
|
-
// 补充已经有的进度
|
|
70
|
-
for (; i <= percentum && i <= 100; i += 5) {
|
|
71
|
-
txt += "█";
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// 补充余下的空白
|
|
75
|
-
for (; i <= 100; i += 5) {
|
|
76
|
-
txt += "░";
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
linelog(percentum.toFixed(2) + "%[" + txt + "]" + stream);
|
|
6
|
+
// 预定义的常量
|
|
7
|
+
const MOVE_LEFT = Buffer.from('1b5b3130303044', 'hex').toString();
|
|
8
|
+
const MOVE_UP = Buffer.from('1b5b3141', 'hex').toString();
|
|
9
|
+
const CLEAR_LINE = Buffer.from('1b5b304b', 'hex').toString();
|
|
10
|
+
|
|
11
|
+
// 计算字符串长度的方法
|
|
12
|
+
const stringwidth = function (str) {
|
|
13
|
+
return str.length;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 不换行打印
|
|
18
|
+
* @param {string} stream 打印的内容
|
|
19
|
+
*/
|
|
20
|
+
let linelog = (function (stream) {
|
|
21
|
+
|
|
22
|
+
// 用来记录前置有多少行需要回退
|
|
23
|
+
let prevLineCount = 0;
|
|
24
|
+
|
|
25
|
+
// 返回实际同行打印的方法
|
|
26
|
+
return function (nextStr) {
|
|
27
|
+
if (arguments.length == 0) {
|
|
28
|
+
prevLineCount = 0;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
let txt = "";
|
|
32
|
+
|
|
33
|
+
// 清除屏幕
|
|
34
|
+
for (let i = 0; i < prevLineCount; i++) {
|
|
35
|
+
txt += MOVE_LEFT + CLEAR_LINE + (i < prevLineCount - 1 ? MOVE_UP : '');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 写入屏幕
|
|
39
|
+
stream.write(txt + nextStr);
|
|
40
|
+
|
|
41
|
+
// 重新计算需要回滚多少行
|
|
42
|
+
let prevLines = nextStr.split('\n');
|
|
43
|
+
prevLineCount = 0;
|
|
44
|
+
for (let i = 0; i < prevLines.length; i++) {
|
|
45
|
+
// 因为有时候文字过多,因此拿总长度除以一行长度得出真实的行数
|
|
46
|
+
prevLineCount += (Math.ceil(stringwidth(prevLines[i]) / stream.columns) || 1);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
};
|
|
50
|
+
})(process.stdout);
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 进度打印
|
|
54
|
+
*
|
|
55
|
+
* @param {number} percentum 进度0-100
|
|
56
|
+
* @param {string} stream 说明文字,可选
|
|
57
|
+
*/
|
|
58
|
+
function deeplog (percentum, stream) {
|
|
59
|
+
if (arguments.length == 0) {
|
|
60
|
+
linelog();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (arguments.length <= 1) stream = "";
|
|
65
|
+
|
|
66
|
+
let txt = "",
|
|
67
|
+
i = 0;
|
|
68
|
+
|
|
69
|
+
// 补充已经有的进度
|
|
70
|
+
for (; i <= percentum && i <= 100; i += 5) {
|
|
71
|
+
txt += "█";
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// 补充余下的空白
|
|
75
|
+
for (; i <= 100; i += 5) {
|
|
76
|
+
txt += "░";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
linelog(percentum.toFixed(2) + "%[" + txt + "]" + stream);
|
|
80
80
|
}
|
|
81
81
|
exports.linelog = linelog;
|
|
82
82
|
exports.deeplog = deeplog;
|
package/nodejs/disk/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 删除文件或文件夹
|
|
3
|
-
*/
|
|
4
|
-
export interface deleteDiskType {
|
|
5
|
-
(diskPath: string): void
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export let deleteDisk: deleteDiskType
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 复制文件或文件夹
|
|
12
|
-
*/
|
|
13
|
-
export interface copyDiskType {
|
|
14
|
-
(sourcePath: string, targetPath: string, isForce?: boolean): void
|
|
15
|
-
}
|
|
16
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 删除文件或文件夹
|
|
3
|
+
*/
|
|
4
|
+
export interface deleteDiskType {
|
|
5
|
+
(diskPath: string): void
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export let deleteDisk: deleteDiskType
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 复制文件或文件夹
|
|
12
|
+
*/
|
|
13
|
+
export interface copyDiskType {
|
|
14
|
+
(sourcePath: string, targetPath: string, isForce?: boolean): void
|
|
15
|
+
}
|
|
16
|
+
|
|
17
17
|
export let copyDisk: copyDiskType
|
package/nodejs/disk/index.js
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* disk of OIPage v1.
|
|
2
|
+
* disk of OIPage v1.3.0-alpha.0
|
|
3
3
|
* git+https://github.com/oi-contrib/OIPage.git
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
const { join } = require("path");
|
|
7
|
-
const { existsSync, readdirSync, lstatSync, unlinkSync, rmdirSync, mkdirSync, copyFileSync } = require("fs");
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 删除文件或文件夹
|
|
11
|
-
* @param {string} diskPath
|
|
12
|
-
*/
|
|
13
|
-
function deleteDisk(diskPath) {
|
|
14
|
-
// 如果文件夹不存在,直接返回即可
|
|
15
|
-
if (!existsSync(diskPath)) return;
|
|
16
|
-
|
|
17
|
-
// 如果是文件,直接删除即可
|
|
18
|
-
if (!lstatSync(diskPath).isDirectory()) {
|
|
19
|
-
unlinkSync(diskPath);
|
|
20
|
-
} else {
|
|
21
|
-
|
|
22
|
-
// 读取子文件
|
|
23
|
-
const subFiles = readdirSync(diskPath);
|
|
24
|
-
|
|
25
|
-
subFiles.forEach(function (item) {
|
|
26
|
-
|
|
27
|
-
// 调用这个方法,删除子文件或文件夹
|
|
28
|
-
const curPath = join(diskPath, "./" + item);
|
|
29
|
-
deleteDisk(curPath);
|
|
30
|
-
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// 等子文件或文件夹删除完毕以后,删除本文件夹
|
|
34
|
-
rmdirSync(diskPath);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 复制文件或文件夹
|
|
40
|
-
* @param {string} sourcePath
|
|
41
|
-
* @param {string} targetPath
|
|
42
|
-
* @param {boolean} isForce 可选,是否强制执行
|
|
43
|
-
*/
|
|
44
|
-
function copyDisk(sourcePath, targetPath, isForce) {
|
|
45
|
-
|
|
46
|
-
// 如果源文件不存在
|
|
47
|
-
if (!existsSync(sourcePath)) {
|
|
48
|
-
console.log("\x1b[0m\x1b[31m" + sourcePath + "\x1b[0m");
|
|
49
|
-
throw new Error("OIPage: The source path does not exist.");
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// 如果模板文件已经存在
|
|
53
|
-
if (existsSync(targetPath)) {
|
|
54
|
-
if (isForce) {
|
|
55
|
-
deleteDisk(targetPath);
|
|
56
|
-
} else {
|
|
57
|
-
console.log("\x1b[0m\x1b[31m" + targetPath + "\x1b[0m");
|
|
58
|
-
throw new Error("OIPage: The target path already exists.");
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
(function copyDiskFun(sourcePath, targetPath) {
|
|
63
|
-
// 如果是文件,直接复制即可
|
|
64
|
-
if (!lstatSync(sourcePath).isDirectory()) {
|
|
65
|
-
copyFileSync(sourcePath, targetPath);
|
|
66
|
-
} else {
|
|
67
|
-
|
|
68
|
-
// 读取子文件
|
|
69
|
-
const subFiles = readdirSync(sourcePath);
|
|
70
|
-
|
|
71
|
-
// 如果文件夹不存在,创建
|
|
72
|
-
if (!existsSync(targetPath)) {
|
|
73
|
-
mkdirSync(targetPath, { recursive: true });
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// 复制子文件或文件夹
|
|
77
|
-
subFiles.forEach(function (item) {
|
|
78
|
-
copyDiskFun(join(sourcePath, "./" + item), join(targetPath, "./" + item));
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
})(sourcePath, targetPath);
|
|
6
|
+
const { join } = require("path");
|
|
7
|
+
const { existsSync, readdirSync, lstatSync, unlinkSync, rmdirSync, mkdirSync, copyFileSync } = require("fs");
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 删除文件或文件夹
|
|
11
|
+
* @param {string} diskPath
|
|
12
|
+
*/
|
|
13
|
+
function deleteDisk(diskPath) {
|
|
14
|
+
// 如果文件夹不存在,直接返回即可
|
|
15
|
+
if (!existsSync(diskPath)) return;
|
|
16
|
+
|
|
17
|
+
// 如果是文件,直接删除即可
|
|
18
|
+
if (!lstatSync(diskPath).isDirectory()) {
|
|
19
|
+
unlinkSync(diskPath);
|
|
20
|
+
} else {
|
|
21
|
+
|
|
22
|
+
// 读取子文件
|
|
23
|
+
const subFiles = readdirSync(diskPath);
|
|
24
|
+
|
|
25
|
+
subFiles.forEach(function (item) {
|
|
26
|
+
|
|
27
|
+
// 调用这个方法,删除子文件或文件夹
|
|
28
|
+
const curPath = join(diskPath, "./" + item);
|
|
29
|
+
deleteDisk(curPath);
|
|
30
|
+
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// 等子文件或文件夹删除完毕以后,删除本文件夹
|
|
34
|
+
rmdirSync(diskPath);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 复制文件或文件夹
|
|
40
|
+
* @param {string} sourcePath
|
|
41
|
+
* @param {string} targetPath
|
|
42
|
+
* @param {boolean} isForce 可选,是否强制执行
|
|
43
|
+
*/
|
|
44
|
+
function copyDisk(sourcePath, targetPath, isForce) {
|
|
45
|
+
|
|
46
|
+
// 如果源文件不存在
|
|
47
|
+
if (!existsSync(sourcePath)) {
|
|
48
|
+
console.log("\x1b[0m\x1b[31m" + sourcePath + "\x1b[0m");
|
|
49
|
+
throw new Error("OIPage: The source path does not exist.");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 如果模板文件已经存在
|
|
53
|
+
if (existsSync(targetPath)) {
|
|
54
|
+
if (isForce) {
|
|
55
|
+
deleteDisk(targetPath);
|
|
56
|
+
} else {
|
|
57
|
+
console.log("\x1b[0m\x1b[31m" + targetPath + "\x1b[0m");
|
|
58
|
+
throw new Error("OIPage: The target path already exists.");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
(function copyDiskFun(sourcePath, targetPath) {
|
|
63
|
+
// 如果是文件,直接复制即可
|
|
64
|
+
if (!lstatSync(sourcePath).isDirectory()) {
|
|
65
|
+
copyFileSync(sourcePath, targetPath);
|
|
66
|
+
} else {
|
|
67
|
+
|
|
68
|
+
// 读取子文件
|
|
69
|
+
const subFiles = readdirSync(sourcePath);
|
|
70
|
+
|
|
71
|
+
// 如果文件夹不存在,创建
|
|
72
|
+
if (!existsSync(targetPath)) {
|
|
73
|
+
mkdirSync(targetPath, { recursive: true });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 复制子文件或文件夹
|
|
77
|
+
subFiles.forEach(function (item) {
|
|
78
|
+
copyDiskFun(join(sourcePath, "./" + item), join(targetPath, "./" + item));
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
})(sourcePath, targetPath);
|
|
83
83
|
}
|
|
84
84
|
exports.deleteDisk = deleteDisk;
|
|
85
85
|
exports.copyDisk = copyDisk;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export interface inputType {
|
|
2
|
-
type: string
|
|
3
|
-
label: string
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface selectType extends inputType {
|
|
7
|
-
value: Array<string>
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 表单输入
|
|
12
|
-
* @param form 表单内容
|
|
13
|
-
* @returns 返回一个结果数组
|
|
14
|
-
*/
|
|
15
|
-
export interface logformType {
|
|
16
|
-
(config: Array<inputType | selectType>): Promise<Array<string | number>>
|
|
17
|
-
}
|
|
18
|
-
|
|
1
|
+
export interface inputType {
|
|
2
|
+
type: string
|
|
3
|
+
label: string
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface selectType extends inputType {
|
|
7
|
+
value: Array<string>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 表单输入
|
|
12
|
+
* @param form 表单内容
|
|
13
|
+
* @returns 返回一个结果数组
|
|
14
|
+
*/
|
|
15
|
+
export interface logformType {
|
|
16
|
+
(config: Array<inputType | selectType>): Promise<Array<string | number>>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
19
|
export let deeplog: logformType
|
package/nodejs/logform/index.js
CHANGED
|
@@ -1,100 +1,100 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* logform of OIPage v1.
|
|
2
|
+
* logform of OIPage v1.3.0-alpha.0
|
|
3
3
|
* git+https://github.com/oi-contrib/OIPage.git
|
|
4
4
|
*/
|
|
5
5
|
const {linelog} = require("../cmdlog/index.js");
|
|
6
|
-
let getTitle = function (title) {
|
|
7
|
-
return "➤ " + title;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
let closeForm = function () {
|
|
11
|
-
process.removeAllListeners("keypress");
|
|
12
|
-
rl.close();
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
let selectView = (title, list, index) => {
|
|
16
|
-
let txtArray = [];
|
|
17
|
-
for (let i = 0; i < list.length; i++) {
|
|
18
|
-
txtArray.push(" " + (i == index ? "●" : "○") + " " + list[i]);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
linelog(`${title}\n${txtArray.join("\n")}\n`);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
function logform(config) {
|
|
25
|
-
const rl = require("readline").createInterface({
|
|
26
|
-
input: process.stdin,
|
|
27
|
-
output: process.stdout
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return new Promise(function (resolve, reject) {
|
|
31
|
-
let result = [], keyback = () => { };
|
|
32
|
-
|
|
33
|
-
console.log("");
|
|
34
|
-
|
|
35
|
-
process.stdin.on("keypress", (_str, key) => {
|
|
36
|
-
keyback(key.name);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
let getResult = (index) => {
|
|
40
|
-
if (index >= config.length) {
|
|
41
|
-
closeForm();
|
|
42
|
-
resolve(result);
|
|
43
|
-
} else {
|
|
44
|
-
let item = config[index];
|
|
45
|
-
|
|
46
|
-
// 文本输入
|
|
47
|
-
if (item.type == "input") {
|
|
48
|
-
|
|
49
|
-
rl.question(getTitle(item.label), (answer) => {
|
|
50
|
-
result.push(answer);
|
|
51
|
-
setTimeout(() => {
|
|
52
|
-
console.log("");
|
|
53
|
-
getResult(index + 1);
|
|
54
|
-
}, 50);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// 列表选择
|
|
60
|
-
else if (item.type == "select") {
|
|
61
|
-
let title = getTitle(item.label);
|
|
62
|
-
|
|
63
|
-
let selectIndex = 0;
|
|
64
|
-
selectView(title, item.value, selectIndex);
|
|
65
|
-
keyback = (keyname) => {
|
|
66
|
-
if (keyname == "return") {
|
|
67
|
-
result.push(selectIndex);
|
|
68
|
-
keyback = () => { };
|
|
69
|
-
linelog();
|
|
70
|
-
setTimeout(() => {
|
|
71
|
-
getResult(index + 1);
|
|
72
|
-
}, 50);
|
|
73
|
-
} else {
|
|
74
|
-
if (keyname == "left" || keyname == "up") {
|
|
75
|
-
if (selectIndex > 0) selectIndex -= 1;
|
|
76
|
-
else selectIndex = item.value.length - 1;
|
|
77
|
-
} else if (keyname == "right" || keyname == "down") {
|
|
78
|
-
if (selectIndex < item.value.length - 1) selectIndex += 1;
|
|
79
|
-
else selectIndex = 0;
|
|
80
|
-
} else {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
selectView(title, item.value, selectIndex);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// 非法类型
|
|
90
|
-
else {
|
|
91
|
-
closeForm();
|
|
92
|
-
reject(new Error("Illegal type!"));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
};
|
|
97
|
-
getResult(0);
|
|
98
|
-
});
|
|
6
|
+
let getTitle = function (title) {
|
|
7
|
+
return "➤ " + title;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
let closeForm = function () {
|
|
11
|
+
process.removeAllListeners("keypress");
|
|
12
|
+
rl.close();
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
let selectView = (title, list, index) => {
|
|
16
|
+
let txtArray = [];
|
|
17
|
+
for (let i = 0; i < list.length; i++) {
|
|
18
|
+
txtArray.push(" " + (i == index ? "●" : "○") + " " + list[i]);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
linelog(`${title}\n${txtArray.join("\n")}\n`);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function logform(config) {
|
|
25
|
+
const rl = require("readline").createInterface({
|
|
26
|
+
input: process.stdin,
|
|
27
|
+
output: process.stdout
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return new Promise(function (resolve, reject) {
|
|
31
|
+
let result = [], keyback = () => { };
|
|
32
|
+
|
|
33
|
+
console.log("");
|
|
34
|
+
|
|
35
|
+
process.stdin.on("keypress", (_str, key) => {
|
|
36
|
+
keyback(key.name);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
let getResult = (index) => {
|
|
40
|
+
if (index >= config.length) {
|
|
41
|
+
closeForm();
|
|
42
|
+
resolve(result);
|
|
43
|
+
} else {
|
|
44
|
+
let item = config[index];
|
|
45
|
+
|
|
46
|
+
// 文本输入
|
|
47
|
+
if (item.type == "input") {
|
|
48
|
+
|
|
49
|
+
rl.question(getTitle(item.label), (answer) => {
|
|
50
|
+
result.push(answer);
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
console.log("");
|
|
53
|
+
getResult(index + 1);
|
|
54
|
+
}, 50);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 列表选择
|
|
60
|
+
else if (item.type == "select") {
|
|
61
|
+
let title = getTitle(item.label);
|
|
62
|
+
|
|
63
|
+
let selectIndex = 0;
|
|
64
|
+
selectView(title, item.value, selectIndex);
|
|
65
|
+
keyback = (keyname) => {
|
|
66
|
+
if (keyname == "return") {
|
|
67
|
+
result.push(selectIndex);
|
|
68
|
+
keyback = () => { };
|
|
69
|
+
linelog();
|
|
70
|
+
setTimeout(() => {
|
|
71
|
+
getResult(index + 1);
|
|
72
|
+
}, 50);
|
|
73
|
+
} else {
|
|
74
|
+
if (keyname == "left" || keyname == "up") {
|
|
75
|
+
if (selectIndex > 0) selectIndex -= 1;
|
|
76
|
+
else selectIndex = item.value.length - 1;
|
|
77
|
+
} else if (keyname == "right" || keyname == "down") {
|
|
78
|
+
if (selectIndex < item.value.length - 1) selectIndex += 1;
|
|
79
|
+
else selectIndex = 0;
|
|
80
|
+
} else {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
selectView(title, item.value, selectIndex);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 非法类型
|
|
90
|
+
else {
|
|
91
|
+
closeForm();
|
|
92
|
+
reject(new Error("Illegal type!"));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
};
|
|
97
|
+
getResult(0);
|
|
98
|
+
});
|
|
99
99
|
}
|
|
100
100
|
exports.logform = logform;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文本分析读取器
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface readerInstanceType {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 当前字符位置
|
|
9
|
+
*/
|
|
10
|
+
index: number
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 当前字符内容
|
|
14
|
+
*/
|
|
15
|
+
value: string
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 读取下一个字符
|
|
19
|
+
*/
|
|
20
|
+
readNext(): string
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 获取往后count个值
|
|
24
|
+
* @param count
|
|
25
|
+
*/
|
|
26
|
+
getNextN(count: number): string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface readerType {
|
|
30
|
+
(plain: string): readerInstanceType
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export let reader: readerType
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* reader of OIPage v1.3.0-alpha.0
|
|
3
|
+
* git+https://github.com/oi-contrib/OIPage.git
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
function reader(plain) {
|
|
7
|
+
|
|
8
|
+
let handler = {
|
|
9
|
+
index: -1,
|
|
10
|
+
value: null
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// 读取下一个字符
|
|
14
|
+
handler.readNext = function () {
|
|
15
|
+
handler.value = handler.index++ < plain.length - 1 ? plain[handler.index] : null;
|
|
16
|
+
return handler.value;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// 获取往后num个值
|
|
20
|
+
handler.getNextN = function (num) {
|
|
21
|
+
return express.substring(handler.index, num + handler.index > plain.length ? plain.length : num + handler.index);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return handler;
|
|
25
|
+
}
|
|
26
|
+
exports.reader = reader;
|