diff options
author | Iru Cai <mytbk920423@gmail.com> | 2014-05-08 01:51:07 +0800 |
---|---|---|
committer | Iru Cai <mytbk920423@gmail.com> | 2014-05-08 01:51:07 +0800 |
commit | 082f8edfa0f8178fa005cc28e1ec0e06fab74d10 (patch) | |
tree | f0326ac4c29be3cfc5d36a5e0bd71f526af604aa /res | |
parent | 66b3f3d28fd97c494fc4bb16c556f6ed8e720814 (diff) | |
download | fqterm-082f8edfa0f8178fa005cc28e1ec0e06fab74d10.tar.xz |
rename downloadart.js to downloadart_ansi.js
Diffstat (limited to 'res')
-rw-r--r-- | res/script/downloadart_ansi.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/res/script/downloadart_ansi.js b/res/script/downloadart_ansi.js new file mode 100644 index 0000000..8438a52 --- /dev/null +++ b/res/script/downloadart_ansi.js @@ -0,0 +1,44 @@ +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'); +var content = ""; + +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)); + content += 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); + content += cur; +} + +fqterm.artDialog(content); + |