[Chinese-commits] [fqterm] 08/76: Add a script for downloading an article with ANSI color.
Boyuan Yang
hosiet-guest at moszumanska.debian.org
Thu Oct 27 03:16:56 UTC 2016
This is an automated email from the git hooks/post-receive script.
hosiet-guest pushed a commit to branch master
in repository fqterm.
commit 88c98119b6e8d6d30731cd0d3e7fb3f9af5557cb
Author: Iru Cai <mytbk920423 at gmail.com>
Date: Mon Apr 7 20:32:41 2014 +0800
Add a script for downloading an article with ANSI color.
And it supports more BBS systems than the native copyArticle()
function, but it's slower.
---
res/script/downloadart.js | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/res/script/downloadart.js b/res/script/downloadart.js
new file mode 100644
index 0000000..f0fd212
--- /dev/null
+++ b/res/script/downloadart.js
@@ -0,0 +1,40 @@
+fqterm.importFile("utils.js");
+
+var saveFile = "/tmp/save.txt";
+var LastLine = 23;
+var timeout = 300;
+var retries = 5;
+// when the article is not completely read
+// there'll be a 'XX%' at the last line
+var r = new RegExp("%");
+var esc = new RegExp('\x1b\x1b','g');
+
+getAnsiLine = function(i){
+ var line = fqterm.getAttrText(i).replace(esc, "\x1b[");
+ return line+"\n";
+}
+
+// first copy the previous lines
+for (var i=0; i<LastLine; ++i){
+ fqterm.appendFile(saveFile, getAnsiLine(i));
+}
+
+// then copy until article ends
+while (1){
+ var line = fqterm.getText(LastLine);
+ if (!r.exec(line)){ // article ends
+ break;
+ }
+ var prev = getAnsiLine(LastLine-1);
+ var cur;
+ fqterm.sendString("j");
+ for (var i=0; i<retries; i++){
+ var cur = getAnsiLine(LastLine-1);
+ if (prev == cur){
+ sleep(timeout);
+ }
+ }
+ fqterm.appendFile(saveFile, cur);
+}
+
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/chinese/fqterm.git
More information about the Chinese-commits
mailing list