reader-shell 1.0.1 → 1.0.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.
@@ -0,0 +1,11 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(git add:*)",
5
+ "Bash(git commit:*)",
6
+ "Bash(git push:*)"
7
+ ],
8
+ "deny": [],
9
+ "ask": []
10
+ }
11
+ }
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # 终端电子书阅读器
2
2
 
3
- 一个基于 Node.js 的终端电子书阅读器,支持导入 epub 文件、记住阅读进度、快捷键翻页和字体颜色切换。
3
+ 一个基于 Node.js 的终端电子书阅读器,支持导入 epub 文件、记住阅读进度、快捷键翻页。
4
+
5
+ ![reader-shell-demo.gif?raw=true](https://cdn.jsdelivr.net/gh/jichangee/gallery@master/imgur/reader-shell-demo.gif?raw=true)
4
6
 
5
7
  ## 功能特性
6
8
  - 支持导入 epub 电子书
@@ -48,4 +50,4 @@ node src/ui.js ./books/三体.epub
48
50
  - [chalk](https://www.npmjs.com/package/chalk) 终端字体颜色
49
51
 
50
52
  ## 许可协议
51
- MIT
53
+ MIT
package/cli.js CHANGED
@@ -1,8 +1,9 @@
1
- import { startReader } from './src/ui.js'
2
- import path from 'path'
1
+ #!/usr/bin/env node
2
+ import { startReader } from './src/ui.js';
3
+ import path from 'path';
3
4
  const epubPath = process.argv[2];
4
5
  if (!epubPath) {
5
- console.error("用法: node cli.js <epub文件路径>");
6
+ console.error('用法: reader-shell <epub文件路径>');
6
7
  process.exit(1);
7
8
  }
8
9
  startReader(path.resolve(epubPath));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reader-shell",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "main": "cli.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -14,5 +14,8 @@
14
14
  "blessed": "^0.1.81",
15
15
  "chalk": "^5.4.1",
16
16
  "epub": "^1.3.0"
17
+ },
18
+ "bin": {
19
+ "reader-shell": "./cli.js"
17
20
  }
18
21
  }
package/src/epubReader.js CHANGED
@@ -19,7 +19,7 @@ function parseEpub(epubPath) {
19
19
  chapters[idx] = '';
20
20
  } else {
21
21
  let text = data.toString('utf-8');
22
- chapters[idx] = text.replace(/<[^>]+>/g, '').replace(/\r\n/g, '') + '\n\n 本章完';
22
+ chapters[idx] = text.replace(/<[^>]+>/g, '').replace(/\r\n/g, '');
23
23
  }
24
24
  loaded++;
25
25
  if (loaded === chapterIds.length) {
package/src/ui.js CHANGED
@@ -72,9 +72,18 @@ async function startReader(epubPath) {
72
72
  screen.append(box);
73
73
  screen.append(status);
74
74
 
75
- function render() {
75
+ // 用于跟踪当前显示的章节,避免重复设置相同内容
76
+ let lastDisplayedChapter = -1;
77
+
78
+ function render(forceContentRefresh = false) {
76
79
  const colorFn = colorFns[fontColor] || chalk.white;
77
- box.setContent(colorFn(chapters[currentChapter] || ""));
80
+
81
+ // 只有当章节改变或强制刷新时才重新设置内容
82
+ if (forceContentRefresh || lastDisplayedChapter !== currentChapter) {
83
+ box.setContent(colorFn(chapters[currentChapter] || ""));
84
+ lastDisplayedChapter = currentChapter;
85
+ }
86
+
78
87
  status.setContent(
79
88
  `progress: ${currentScroll}/${box.getScrollHeight()} | chapter: ${currentChapter + 1}/${
80
89
  chapters.length
@@ -93,7 +102,7 @@ async function startReader(epubPath) {
93
102
  currentChapter += chapter;
94
103
  currentScroll = 0;
95
104
  saveProgress();
96
- render();
105
+ render(true); // 切换章节时强制刷新内容
97
106
  }
98
107
 
99
108
  // 快捷键
@@ -134,7 +143,7 @@ async function startReader(epubPath) {
134
143
  box.height = 0
135
144
  status.height = 0
136
145
  }
137
- render()
146
+ render(false) // 老板键切换时不强制刷新内容
138
147
  });
139
148
  screen.key(["q", "C-c"], () => {
140
149
  saveProgress();
@@ -145,7 +154,7 @@ async function startReader(epubPath) {
145
154
  saveProgress();
146
155
  });
147
156
 
148
- render();
157
+ render(true); // 初始渲染时强制设置内容
149
158
  }
150
159
 
151
160
  // 允许命令行直接运行