How to use ansiState method in Best

Best JavaScript code snippet using best

www2-addons.js

Source:www2-addons.js Github

copy

Full Screen

1/**2 * Part of the KBS BBS Code3 * Copyright (c) 2005-2008 KBS Development Team. (http://dev.kcn.cn/)4 * Source file is subject to the pending KBS License.5 *6 * You may use and/or modify the source code only for pure personal study7 * purpose (e.g. using it in a public website is not acceptable), unless8 * you get explicit permission by the KBS Development Team.9 */10function annWriter(path, perm_bm, text, title) {11 this.path = path;12 this.perm_bm = perm_bm;13 this.num = 1;14 this.title = title;15 var str;16 str = '<form id="frmAnnounce" action="bbs0anbm.php?path=' + path + '" method="post">';17 str += '<input type="hidden" id="annAction" name="annAction" value="">';18 str += '<div class="smaller" style="text-align:right">';19 if(text == '')20 {21 str += '¾«»ªÇø¹ÜÀíģʽ£ºÄúÔÚµ±Ç°Ä¿Â¼<span style="color:#FF0000">';22 str += perm_bm ? 'ÓÐ' : 'ûÓÐ';23 str += '</span>¹ÜÀíȨÏÞ¡£';24 }25 else26 str += '<span style="color:#FF0000">' + text + '</span>';27 str += '</div>';28 str += '<table class="main wide"><col width="5%" /><col width="8%" /><col width="4%" /><col width="38%" />';29 str += '<col width="10%" /><col width="10%" /><col width="10%" /><tr><th>#</th><th>ÀàÐÍ</th><th></th>';30 str += '<th>±êÌâ</th><th>°æÖ÷</th><th>' + (perm_bm?'ÎļþÃû':'ÈÕÆÚ') + '</th><th>²Ù×÷</th></tr><tbody>';31 w(str);32}33annWriter.prototype.i = function(type, title, title_enc, bm, filename, date) {34 var str, itempath;35 str = '<tr><td class="center">' + this.num + '</td><td class="center">';36 switch(type) {37 case 0:38 str += '´íÎó';39 break;40 case 1:41 str += 'Ŀ¼';42 break;43 case 2:44 case 3:45 default:46 str += 'Îļþ';47 break;48 }49 str += '</td><td class="center"><input type="checkbox" name="ann' + this.num + '" value="' + filename + '"></td><td>';50 itempath = this.path + '%2F' + filename;51 if (type == 1)52 str += '<a href="bbs0anbm.php?path=' + itempath + '">';53 else if (type >= 2)54 str += '<a href="bbsanc.php?annbm=1&path=' + itempath + '">';55 str += title + '</a></td><td>' + bm + '</td><td>';56 str += this.perm_bm ? (filename + ((type == 1) ? '/' : '')) : date;57 str += '</td><td>';58 if (type == 1)59 str += '<a href="bbs0anbm_editdir.php?path=' + itempath + '&title=' + title_enc + '&bm=' + bm + '">ÐÞ¸Ä</a>';60 else if (type >= 2)61 str += '<a href="bbs0anbm_editfile.php?path=' + itempath + '&title=' + title_enc + '">±à¼­</a>';62 str += ' <a href="javascript:ann_move(' + this.num + ');">µ÷Ðò</a>';63 str += '<span id="divam' + this.num + '"></span>';64 str += '</td></tr>';65 w(str);66 this.num++;67};68annWriter.prototype.f = function() {69 var str;70 str = '</tbody></table>';71 if (this.perm_bm)72 {73 str += '<br><div class="center smaller">';74 str += '[<a href="bbs0anbm_mkdir.php?path=' + this.path + '">´´½¨Ä¿Â¼</a>] ';75 str += '[<a href="bbs0anbm_mkfile.php?path=' + this.path + '">´´½¨Îļþ</a>] ';76 str += '[<a href="javascript:ann_clip(\'cut\');">¼ôÇÐ</a>] ';77 str += '[<a href="javascript:ann_clip(\'copy\');">¸´ÖÆ</a>] ';78 str += '[<a href="javascript:ann_clip(\'paste\');">Õ³Ìù</a>] ';79 str += '[<a href="javascript:ann_delete();">ɾ³ý</a>] ';80 str += '[<a href="bbsipath.php?inann=1&annpath=' + this.path + '&title=' + this.title + '">˿·</a>]';81 str += '</div>';82 }83 str += '<input type="hidden" id="annCount" name="annCount" value="' + (this.num-1) + '">';84 str += '</form>';85 w(str);86};87function ann_delete()88{89 if(confirm('È·¶¨ÒªÉ¾³ýÕâЩÎļþ»òĿ¼Âð£¿'))90 {91 frmAnnounce.annAction.value = 'delete';92 frmAnnounce.submit();93 }94}95function ann_clip(action)96{97 frmAnnounce.annAction.value = action;98 frmAnnounce.submit();99}100function ann_move(num)101{102 var str = '';103 str += '<br>ÐÂÐò<input type="text" size="3" name="newnum">';104 str += '<input type="hidden" name="oldnum" value="' + num + '">';105 str += '<br><input type="button" value="Òƶ¯" onclick="ann_move_do();">';106 str += '<input type="button" value="È¡Ïû" onclick="ann_move_cancel(' + num + ');">';107 document.getElementById('divam' + num).innerHTML = str;108}109function ann_move_do()110{111 frmAnnounce.annAction.value = 'move';112 frmAnnounce.submit();113}114function ann_move_cancel(num)115{116 var thediv = document.getElementById('divam' + num);117 thediv.innerHTML = '';118}119function ipathMakeItem(title, path)120{121 return(title + '<br>' + path);122}123function ipathWriter(inAnn) {124 var str;125 this.num = 1;126 this.annPath = currAnnPath;127 this.inAnn = inAnn;128 str = '<form id="frmipath" method="post" action="bbsipath.php?inann=' + inAnn + '&annpath=' + currAnnPath + '&title=' + currAnnTitle + '">';129 str += '<input type="hidden" id="ipathAction" name="ipathAction" value="">';130 str += '<input type="hidden" id="num" name="num" value="0">';131 str += '<h1 class="bt">˿·</h1><div style="text-align:right">[<a href="bbs0anbm.php?path=' + currAnnPath + '">¾«»ªÇøĿ¼</a>]';132 str += '<table class="main wide"><col width="5%" /><col width="60%" /><col width="35%" />';133 str += '<tr><th>#</th><th>±êÌâ / ·¾¶</th><th>²Ù×÷</th></tr><tbody>';134 w(str);135}136ipathWriter.prototype.i = function(title, path) {137 var str;138 ititle[this.num] = title;139 ipath[this.num] = path;140 str = '<tr><td class="center">' + this.num + '</td>';141 str += '<td id="ipathCon' + this.num + '">' + ipathMakeItem(title, path) + '</td>';142 str += '<td>';143 if(title != '')144 {145 str += '<a href="javascript:ipathPaste(\'' + path + '\');">Õ³Ìù</a> ';146 str += '<a href="javascript:ipathModify(' + this.num + ');">¸Ä±êÌâ</a> ';147 }148 if(this.inAnn)149 str += '<a href="javascript:ipathSet(' + this.num + ');">ÉèΪµ±Ç°Ä¿Â¼</a>';150 str += '</td></tr>';151 this.num++;152 w(str);153}154ipathWriter.prototype.f = function() {155 var str;156 str = '</tbody></table><div id="ipathSetDiv"></div></form>';157 str += '<form id="frmPaste" method="post"><input type="hidden" name="annAction" value="paste"><input type="hidden" name="annCount" value="0"></form>';158 w(str);159}160function ipathPaste(path)161{162 path = path.substr(9, path.length - 9);163 frmPaste.action = 'bbs0anbm.php?path=' + path;164 frmPaste.submit();165}166function ipathModify(num)167{168 var str;169 if(ipathEditing != 0)170 document.getElementById('ipathCon' + ipathEditing).innerHTML = ipathMakeItem(ititle[ipathEditing], ipath[ipathEditing]);171 if(num != ipathEditing)172 {173 ipathEditing = num;174 if(num > 0)175 {176 str = '<input type="text" name="ipathTitle" size="40" maxlength="80" value="' + ititle[num] + '">';177 str += '<input type="button" onclick="ipathDoModify();" value="ÐÞ¸Ä"><br>' + ipath[num];178 document.getElementById('ipathCon' + num).innerHTML = str;179 }180 }181 else182 ipathEditing = 0;183 184}185function ipathDoModify()186{187 if(ipathEditing != 0)188 {189 frmipath.ipathAction.value = 'modify';190 frmipath.num.value = ipathEditing;191 frmipath.submit();192 }193}194function ipathSet(num)195{196 var co = true;197 var str;198 ipathModify(0);199 if(ititle[num] != "")200 co = confirm('Òª¸²¸ÇÕâ¸ö˿·Âð£¿');201 if(co)202 {203 frmipath.ipathAction.value = 'set';204 frmipath.num.value = num;205 str = '<input type="hidden" name="ipathTitle" value="' + currAnnTitle + '">';206 str += '<input type="hidden" name="ipathPath" value="' + currAnnPath + '">';207 document.getElementById('ipathSetDiv').innerHTML = str;208 frmipath.submit();209 }210}211 212var gTreeArts = new Array();213function treeWriter(board, bid, gid, arts) {214 this.board = escape(board);215 this.bid = bid;216 this.gid = gid;217 var i, tI = new Array();218 for (i = 0; i < arts.length; i++) {219 var node = {"id": arts[i][0], "reid": arts[i][1], "owner": arts[i][2], 220 "first_child": -1, "last_child": -1, "next_sibling": -1, "showed": false};221 gTreeArts[i] = node;222 tI[node.id] = i + 1;223 if (i > 0 && tI[node.reid]) {224 var par = gTreeArts[tI[node.reid] - 1];225 if (par.first_child == -1) par.first_child = i;226 if (par.last_child != -1) gTreeArts[par.last_child].next_sibling = i;227 par.last_child = i;228 }229 }230 this.ifs = "";231}232treeWriter.prototype.s = function(idx, flag) { /* flag: -1: root, 1: last */233 if (gTreeArts[idx].showed) return;234 gTreeArts[idx].showed = true;235 var id = gTreeArts[idx].id;236 var owner = gTreeArts[idx].owner;237 var url = 'bbscon.php?bid=' + this.bid + '&id=' + id;238 var ret = '<br/>';239 var c = "treeFold";240 if (flag == -1) c = "treeFoldRoot";241 else if (flag == 1) c = "treeFoldLast";242 243 ret += '<div class="' + c + '">';244 if (flag == 0) {245 ret += '<div class="treeFoldLeaf"> </div>';246 }247 ret += '<div class="tconPager smaller left">';248 ret += '[<a href="' + url + '">±¾ÆªÈ«ÎÄ</a>] ';249 if (isLogin()) {250 ret += '[<a href="bbspst.php?board=' + this.board + '&reid=' + id + '">»Ø¸´ÎÄÕÂ</a>] ';251 ret += '[<a href="bbspstmail.php?board=' + this.board + '&id=' + id + '">»ØПø×÷Õß</a>] ';252 }253 ret += '[±¾Æª×÷Õߣº<a href="bbsqry.php?userid=' + owner + '">' + owner + '</a>] ';254 ret += '[<a href="bbsdoc.php?board=' + this.board + '">½øÈëÌÖÂÛÇø</a>] ';255 ret += '[<a href="#top">·µ»Ø¶¥²¿</a>]';256 ret += '<div class="tnum">' + (idx+1) + '</div>';257 ret += '</div><div class="article" id="art' + id + '"><div align="center">...ÔØÈëÖÐ...</div></div>';258 this.ifs += '<iframe width=0 height=0 frameborder="0" scrolling="no" src="' + url + '"></iframe>';259 w(ret);260 var cur = gTreeArts[idx].first_child;261 while(cur != -1) {262 this.s(cur, (cur == gTreeArts[idx].last_child) ? 1 : 0);263 cur = gTreeArts[cur].next_sibling;264 }265 266 w("</div>");267};268treeWriter.prototype.o = function() {269 var i;270 this.s(0, -1);271 for(i=1;i<gTreeArts.length;i++) this.s(i, -1); //ûÁ¬ÉϸùµÄÄÇЩ֦Ìõ272 w(this.ifs);273};274/* replymode: S/Y/N/R/A */275function generateQuotation(c, mailmode, replymode) {276 replymode = replymode ? replymode.toLowerCase() : 's';277 var subject = "", quotation = "";278 var start, i;279 try {280 var s = c.split("\n");281 /* Ñ°ÕÒ±êÌâ */282 if (s.length > 1) {283 start = s[1].indexOf(":");284 if (start != -1) {285 subject = s[1].substring(start + 2);286 if (subject.substring(0, 4) != "Re: ") subject = "Re: " + subject;287 }288 }289 if (replymode != 'n') {290 /* Ñ°ÕÒ×÷ÕßÐÅÏ¢ */291 var author = "";292 if (s.length > 0) {293 var end = s[0].lastIndexOf(")");294 start = s[0].indexOf(":");295 if (start != -1 && end != -1) {296 author = s[0].substring(start + 2, end + 1);297 }298 }299 300 if (mailmode) {301 quotation += "\n¡¾ ÔÚ " + author + " µÄÀ´ÐÅÖÐÌáµ½: ¡¿\n";302 } else {303 quotation += "\n¡¾ ÔÚ " + author + " µÄ´ó×÷ÖÐÌáµ½: ¡¿\n";304 }305 306 /* ´¦ÀíÒýÎÄ */307 if (replymode == 'a') {308 for (i = 1; i < s.length; i++) {309 quotation += ": " + s[i].replace(/\r[\[\d;]+[a-z]/gi, "") + "\n";310 }311 } else {312 for (i = 2; i < s.length; i++) {313 if (s[i].length == 0) break;314 }315 if (replymode == 'r') {316 for (i++; i < s.length; i++) {317 if (s[i].indexOf("¡ù À´Ô´:¡¤") == -1) {318 quotation += s[i].replace(/\r[\[\d;]+[a-z]/gi, "") + "\n";319 }320 }321 } else {322 var qlines = 0;323 for (i++; i < s.length; i++) {324 if (s[i].substring(0,1) == "¡¾") continue;325 if (s[i].substring(0,2) == ": ") continue;326 if (s[i] == "--") break;327 if (s[i].length == 0) continue;328 quotation += ": " + s[i].replace(/\r[\[\d;]+[a-z]/gi, "") + "\n"; /* filter <textarea> ? */329 if (replymode == 's') {330 qlines++;331 if (qlines >= 3) {332 quotation += ": ...................";333 break;334 }335 }336 }337 }338 }339 }340 } catch(e) {341 }342 return { "subject" : subject, "quotation" : quotation };343}344function showReplyForm(url) {345 if (readParaCookie() & 0x2000) return true;346 if (gIE5 || gKon) return true;347 var o = getObj("divReplyForm");348 o.style.padding = '0.5em';349 o.innerHTML = "ÔØÈëÖУ¬ÇëÉÔºò¡­¡­";350 o = document.createElement('iframe');351 o.style.display = 'none';352 document.body.appendChild(o);353 o.src = url;354 return false;355}356function changeQM(m) {357 var f = getObj('rff');358 if (f) {359 var rr = generateQuotation(strPrint, 0, m);360 f.value = rr.quotation;361 f.focus();362 setCursorPosition(f, 0, 0);363 }364}365function showReplyFormReal(rf) {366 rf.pDiv.innerHTML = rf.f() + '</textarea>' + rf.t();367 changeQM('s');368 makeViewable("divReplyForm");369}370function replyForm(board,reid,title,att,signum,sig,ano,outgo,lsave) {371 this.board = board;372 this.reid = reid;373 this.title = title;374 this.att = att;375 this.signum = signum;376 this.sig = sig;377 this.ano = ano;378 this.outgo = outgo;379 this.lsave = lsave;380 this.pDiv = (parent && parent.document.getElementById("divReplyForm"));381 if (this.pDiv) {382 var self = this;383 addBootFn(function() {384 parent.showReplyFormReal(self);385 });386 }387}388replyForm.prototype.f = function() {389 var i,focusEle = (this.pDiv ? ' id="rff"' : ' id="sfocus"');390 var html = '<form name="postform" method="post" action="bbssnd.php?board=' + this.board + '&reid=' + this.reid + '" class="large">'391 + '<fieldset><legend>' + (this.reid ? "»Ø¸´ÎÄÕÂ" : "·¢±íÎÄÕÂ") + '</legend>'392 + '·¢ÐÅÈË: ' + getUserid() + ', ÐÅÇø: ' + this.board + ' [<a href="bbsdoc.php?board=' + this.board + '">±¾ÌÖÂÛÇø</a>] [<a href="bbsnot.php?board=' + this.board + '" target="_blank">²é¿´ÌÖÂÛÇø±¸Íü¼</a>]<br/>';393 var nt = "";394 if (this.reid) nt = (this.title.substr(0,4).toLowerCase() == "re: ") ? this.title : ("Re: " + this.title);395 html += '±ê&nbsp;&nbsp;Ìâ: <input type="text" tabindex="1" name="title" size="40" maxlength="100" value="'396 + htmlize(nt,1) + '"' + (this.reid?'':focusEle) + '/><br/>';397 if (this.att) {398 html += '¸½&nbsp;&nbsp;¼þ: <input type="text" name="attachname" size="40" value="" disabled="disabled" />'399 + ' <a href="bbsupload.php" target="_blank">²Ù×÷¸½¼þ</a>(д°¿Ú´ò¿ª)<br/>';400 }401 html += 'Ç©Ãûµµ <select name="signature">';402 if (this.signum == 0) html += '<option value="0" selected="selected">²»Ê¹ÓÃÇ©Ãûµµ</option>';403 else {404 html += '<option value="0">²»Ê¹ÓÃÇ©Ãûµµ</option>';405 for (i=1; i<=this.signum; i++) {406 html += '<option value="' + i + '"' + (this.sig==i?' selected="selected"':'') + '>µÚ ' + i + ' ¸ö</option>';407 }408 html += '<option value="-1" ' + (this.sig<0?'selected="selected"':'') + '>Ëæ»úÇ©Ãûµµ</option>';409 }410 html += '</select> [<a target="_blank" href="bbssig.php">²é¿´Ç©Ãûµµ</a>]';411 if (this.ano) html += '<input type="checkbox" name="anony" value="1" />ÄäÃû';412 if (this.outgo) html += '<input type="checkbox" name="outgo" value="1"' + (this.lsave?'':' checked="checked"') + '/>תÐÅ';413 html += '<input type="checkbox" name="mailback" value="1" />reÎij­ËÍÐÅÏä';414 if (havejsmath) html += '<input type="checkbox" name="havemath" value="1" />Êýѧ¹«Ê½';415 if (this.pDiv) {416 var rm = [['S','Ç°ÈýÐÐ(ĬÈÏ)'],['Y','¸Ã×÷ÕßÈ«ÎÄ'],['N','²»ÒýÓÃ'],['R','Rģʽ(²»ÍƼö)'],['A','È«ÎÄ']];417 var v = '['418 for (i in rm) {419 var r = rm[i];420 v += '<span class="clickable" title="»ØÎÄģʽ£º' + r[1] + '" onclick="changeQM(\'' + r[0] + '\')">' + r[0] + '</span>/';421 }422 v = v.substr(0,v.length-1) + ']';423 html += ' ' + v;424 }425 html += '<br />';426 html += '<textarea name="text" tabindex="2" onkeydown="return textarea_okd(dosubmit, event);" wrap="physical"' 427 + (this.reid?focusEle:'') + '>';428 return(html);429};430replyForm.prototype.t = function() {431 var html = '<br/>';432 html += '<div class="oper"><input type="button" onclick="dosubmit();" tabindex="3" name="post" value="·¢±í" />'433 + '&nbsp;&nbsp;&nbsp;&nbsp;<input class="sb1" type="reset" value="·µ»Ø" onclick="history.go(-1)" /></div>';434 html += '</fieldset></form>';435 return(html);436};437function AnsiState() {438 this.s = 0;439}440AnsiState.prototype = {441 ESC_SET: 0x01,442 FONT_SET: 0x02,443 NEW_LINE: 0x04,444 QUOTE_LINE: 0x08,445 QUOTEHEADER_LINE: 0x10,446 SET: function(b) { this.s |= b; },447 CLR: function(b) { this.s &= ~b; },448 ISSET: function(b) { return (this.s & b); },449 ZERO: function() { this.s = 0; }450};451function StyleState() {452 this.s = 0;453 this.ansi = new Array();454 this.ansi_t = 0;455}456StyleState.prototype = {457 SET_FG: function(c) { this.s = (this.s & ~0x07) | (c & 0x07) },458 SET_BG: function(c) { this.s = (this.s & ~0x70) | ((c & 0x07) << 4) },459 GET_FG: function() { return (this.s & 0x0F); },460 GET_BG: function() { return ((this.s & 0x70) >> 4); },461 CLR_FG: function() { this.s &= ~0x0F; },462 CLR_BG: function() { this.s &= ~0xF0; },463 ZERO: function() { this.s = 0; },464 SET: function(b) { this.s |= b; },465 CLR: function(b) { this.s &= ~b; },466 ISSET: function(b) { return (this.s & b); },467 STYLE_UL: 0x0100,468 STYLE_BLINK: 0x0200,469 STYLE_ITALIC: 0x0400,470 FG_BOLD: 0x08,471 COLOR_BLACK: 0x00,472 COLOR_RED: 0x01,473 COLOR_GREEN: 0x02,474 COLOR_YELLOW: 0x03,475 COLOR_BULE: 0x04,476 COLOR_MAGENTA: 0x05,477 COLOR_CYAN: 0x06,478 COLOR_WHITE: 0x07,479 STYLE_QUOTE: 0x0000,480 COLOR_QUOTE: 0x06,481 STYLE_QUOTEHEADER: 0x0800,482 COLOR_QUOTEHEADER: 0x03|0x08,483 BG_SET: 0x80,484 printStyle: function() {485 var bg, fg, font_class;486 if (this.ISSET(this.BG_SET)) {487 bg = 8;488 } else {489 bg = this.GET_BG();490 }491 fg = this.GET_FG();492 if (fg == 0 && bg == 0) {493 font_class = "ff07";494 } else {495 font_class = "fb" + bg + " ff" + fg;496 }497 if (this.ISSET(this.STYLE_UL))498 font_class += " fund";499 if (this.ISSET(this.STYLE_ITALIC)) /* ?? no where set this */500 font_class += " fita";501 if (this.ISSET(this.STYLE_BLINK))502 font_class += " fbli";503 return "<font class=\"" + font_class + "\">";504 },505 addAnsi: function() {506 this.ansi_t++;507 this.ansi[this.ansi_t] = 0;508 },509 clearAnsi: function() {510 this.ansi_t = 0;511 this.ansi[0] = 0;512 },513 generateFontStyle: function() {514 for (var i = 0; i <= this.ansi_t; i++) {515 if (this.ansi[i] == 0) {516 this.ZERO();517 this.SET(this.COLOR_WHITE);518 } else if (this.ansi[i] == 1)519 this.SET(this.FG_BOLD);520 else if (this.ansi[i] == 4)521 this.SET(this.STYLE_UL);522 else if (this.ansi[i] == 5)523 this.SET(this.STYLE_BLINK);524 else if (this.ansi[i] >= 30 && this.ansi[i] <= 37) {525 this.SET_FG(this.ansi[i] - 30);526 } else if (this.ansi[i] >= 40 && this.ansi[i] <= 47) {527 this.SET_BG(this.ansi[i] - 40);528 }529 }530 }531};532function htmlOutput(s) {533 switch(s) {534 case '&':535 return "&amp;";536 case '<':537 return "&lt;";538 case '>':539 return "&gt;";540 case ' ':541 return "&nbsp;";542 default:543 return s;544 }545}546function printRawAnsi(s, start, end) {547 var ret = "";548 for (var i = start; i < end; i++) {549 if (s.charAt(i) == '\r')550 ret += "*";551 else if (s.charAt(i) == '\n')552 ret += "<br/>";553 else554 ret += htmlOutput(s.charAt(i));555 }556 return ret;557}558function convertAnsi(s) {559 var ansiState = new AnsiState();560 var styleState = new StyleState();561 var ret = new StringBuffer();562 var buflen = s.length;563 var ansi_begin = 0;564 styleState.clearAnsi();565 styleState.ZERO();566 styleState.SET(styleState.COLOR_WHITE);567 for (var i = 0; i < buflen; i++) {568 if (ansiState.ISSET(ansiState.NEW_LINE)) {569 ansiState.CLR(ansiState.NEW_LINE);570 if (i < (buflen - 1) && (s.charAt(i) == ':' && s.charAt(i + 1) == ' ')) {571 ansiState.SET(ansiState.QUOTE_LINE);572 if (ansiState.ISSET(ansiState.FONT_SET))573 ret.append("</font>");574 /*575 * set quoted line styles 576 */577 styleState.SET(styleState.STYLE_QUOTE);578 styleState.CLR_FG();579 styleState.CLR_BG();580 styleState.SET(styleState.COLOR_QUOTE);581 ret.append(styleState.printStyle() + ":");582 ansiState.SET(ansiState.FONT_SET);583 ansiState.CLR(ansiState.ESC_SET);584 /*585 * clear ansi_val[] array 586 */587 styleState.clearAnsi();588 continue;589 } else590 ansiState.CLR(ansiState.QUOTE_LINE);591 if (i < (buflen - 3) && (s.substring(i, i + 3) == "¡¾ ÔÚ")) {592 ansiState.SET(ansiState.QUOTEHEADER_LINE);593 if (ansiState.ISSET(ansiState.FONT_SET))594 ret.append("</font>");595 /*596 * set quote header line styles 597 */598 styleState.SET(styleState.STYLE_QUOTEHEADER);599 styleState.CLR_FG();600 styleState.CLR_BG();601 styleState.SET(styleState.COLOR_QUOTEHEADER);602 ret.append(styleState.printStyle() + "¡¾");603 ansiState.SET(ansiState.FONT_SET);604 ansiState.CLR(ansiState.ESC_SET);605 /*606 * clear ansi_val[] array 607 */608 styleState.clearAnsi();609 continue;610 } else611 ansiState.CLR(ansiState.QUOTEHEADER_LINE);612 }613 if (i < (buflen - 1) && (s.charAt(i) == '\r' && s.charAt(i + 1) == '[')) {614 if (ansiState.ISSET(ansiState.ESC_SET)) {615 /*616 *[*[ or *[13;24*[ */617 ret.append(printRawAnsi(s, ansi_begin, i));618 }619 ansiState.SET(ansiState.ESC_SET);620 ansi_begin = i;621 i++; /* skip the next '[' character */622 } else if (s.charAt(i) == '\n') {623 if (ansiState.ISSET(ansiState.ESC_SET)) {624 /*625 *[\n or *[13;24\n */626 ret.append(printRawAnsi(s, ansi_begin, i));627 ansiState.CLR(ansiState.ESC_SET);628 }629 if (ansiState.ISSET(ansiState.QUOTE_LINE)) {630 /*631 * end of a quoted line 632 */633 ret.append("</font>");634 styleState.CLR(styleState.STYLE_QUOTE);635 styleState.CLR(styleState.COLOR_QUOTE);636 ansiState.CLR(ansiState.QUOTE_LINE);637 ansiState.CLR(ansiState.FONT_SET);638 }639 if (ansiState.ISSET(ansiState.QUOTEHEADER_LINE)) {640 /*641 * end of a quote header line 642 */643 ret.append("</font>");644 styleState.CLR(styleState.STYLE_QUOTEHEADER);645 styleState.CLR(styleState.COLOR_QUOTEHEADER);646 ansiState.CLR(ansiState.QUOTEHEADER_LINE);647 ansiState.CLR(ansiState.FONT_SET);648 }649 ret.append("<br/>");650 ansiState.SET(ansiState.NEW_LINE);651 } else {652 var c = s.charAt(i);653 if (ansiState.ISSET(ansiState.ESC_SET)) {654 if (c == 'm') {655 /*656 *[0;1;4;31m */657 if (ansiState.ISSET(ansiState.FONT_SET)) {658 ret.append("</font>");659 ansiState.CLR(ansiState.FONT_SET);660 }661 if (i < buflen - 1) {662 styleState.generateFontStyle();663 ret.append(styleState.printStyle());664 ansiState.SET(ansiState.FONT_SET);665 ansiState.CLR(ansiState.ESC_SET);666 /*667 * STYLE_ZERO(font_style);668 */669 /*670 * clear ansi_val[] array 671 */672 styleState.clearAnsi();673 }674 } else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {675 /*676 *[23;32H */677 /*678 * ignore it 679 */680 ansiState.CLR(ansiState.ESC_SET);681 //styleState.ZERO();682 /*683 * clear ansi_val[] array 684 */685 styleState.clearAnsi();686 continue;687 } else if (c == ';') {688 styleState.addAnsi();689 } else if (c >= '0' && c <= '9') {690 styleState.ansi[styleState.ansi_t] *= 10;691 styleState.ansi[styleState.ansi_t] += (c - '0');692 } else {693 /*694 *[1;32/XXXX or *[* or *[[ */695 /*696 * not a valid ANSI string, just output it 697 */698 ret.append(printRawAnsi(s, ansi_begin, i + 1));699 ansiState.CLR(ansiState.ESC_SET);700 /*701 * clear ansi_val[] array 702 */703 styleState.clearAnsi();704 }705 } else706 ret.append(printRawAnsi(s, i, i + 1));707 }708 }709 if (ansiState.ISSET(ansiState.FONT_SET)) {710 ret.append("</font>");711 ansiState.CLR(ansiState.FONT_SET);712 }713 return ret.toString();714}715/* WARNING: now I can only deal with only one ansi container in a page */716function triggerAnsiDiv(obj,objInner) {717 if (!(obj = getObj(obj))) return;718 if (!(objInner = getObj(objInner))) return;719 addBootFn(function() {720 var o = document.createElement("div");721 o.className = "AnsiSwitch";722 o.innerHTML = "ANSI";723 o.title = "Çл» Ansi ÏÔʾ";724 obj.insertBefore(o,objInner);725 obj.isAnsi = false;726 addEvent(o,"click",function() {727 obj.isAnsi = !obj.isAnsi;728 obj.className = obj.isAnsi?"AnsiArticleColor":"AnsiArticleBW";729 objInner.innerHTML = obj.isAnsi?convertAnsi(strPrint):strArticle;730 });731 });...

Full Screen

Full Screen

ansiparse.js

Source:ansiparse.js Github

copy

Full Screen

1/* eslint-disable no-plusplus, no-continue */2const foregroundColors = {3 '30': 'black',4 '31': 'red',5 '32': 'green',6 '33': 'yellow',7 '34': 'blue',8 '35': 'magenta',9 '36': 'cyan',10 '37': 'white',11 '90': 'grey',12};13const backgroundColors = {14 '40': 'black',15 '41': 'red',16 '42': 'green',17 '43': 'yellow',18 '44': 'blue',19 '45': 'magenta',20 '46': 'cyan',21 '47': 'white',22};23const styles = {24 '1': 'bold',25 '3': 'italic',26 '4': 'underline',27};28const eraseChar = (matchingText, result) => {29 if (matchingText.length) {30 return [matchingText.substr(0, matchingText.length - 1), result];31 } else if (result.length) {32 const index = result.length - 1;33 const { text } = result[index];34 const newResult =35 text.length === 136 ? result.slice(0, result.length - 1)37 : result.map((item, i) =>38 index === i39 ? { ...item, text: text.substr(0, text.length - 1) }40 : item41 );42 return [matchingText, newResult];43 }44 return [matchingText, result];45};46const ansiparse = str => {47 let matchingControl = null;48 let matchingData = null;49 let matchingText = '';50 let ansiState = [];51 let result = [];52 let state = {};53 for (let i = 0; i < str.length; i++) {54 if (matchingControl !== null) {55 if (matchingControl === '\x1b' && str[i] === '[') {56 if (matchingText) {57 state.text = matchingText;58 result.push(state);59 state = {};60 matchingText = '';61 }62 matchingControl = null;63 matchingData = '';64 } else {65 matchingText += matchingControl + str[i];66 matchingControl = null;67 }68 continue;69 } else if (matchingData !== null) {70 if (str[i] === ';') {71 ansiState.push(matchingData);72 matchingData = '';73 } else if (str[i] === 'm') {74 ansiState.push(matchingData);75 matchingData = null;76 matchingText = '';77 for (let a = 0; a < ansiState.length; a++) {78 const ansiCode = ansiState[a];79 if (foregroundColors[ansiCode]) {80 state.foreground = foregroundColors[ansiCode];81 } else if (backgroundColors[ansiCode]) {82 state.background = backgroundColors[ansiCode];83 } else if (ansiCode === 39) {84 delete state.foreground;85 } else if (ansiCode === 49) {86 delete state.background;87 } else if (styles[ansiCode]) {88 state[styles[ansiCode]] = true;89 } else if (ansiCode === 22) {90 state.bold = false;91 } else if (ansiCode === 23) {92 state.italic = false;93 } else if (ansiCode === 24) {94 state.underline = false;95 }96 }97 ansiState = [];98 } else {99 matchingData += str[i];100 }101 continue;102 }103 if (str[i] === '\x1b') {104 matchingControl = str[i];105 } else if (str[i] === '\u0008') {106 [matchingText, result] = eraseChar(matchingText, result);107 } else {108 matchingText += str[i];109 }110 }111 if (matchingText) {112 state.text = matchingText + (matchingControl || '');113 result.push(state);114 }115 return result;116};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestGlobals = require('bestglobals');2var ansiState = BestGlobals.ansiState;3var ansi = BestGlobals.ansi;4var ansiState1 = ansiState();5ansiState1.fg = 'red';6ansiState1.bg = 'blue';7ansiState1.bold = true;8ansiState1.italic = true;9ansiState1.underline = true;10ansiState1.blink = true;11ansiState1.inverse = true;12ansiState1.concealed = true;13ansiState1.crossedOut = true;14ansiState1.reset = true;15ansiState1.fg256 = 1;16ansiState1.bg256 = 2;17ansiState1.fgRGB = [3,4,5];18ansiState1.bgRGB = [6,7,8];19ansiState1.fg24bit = [9,10,11];20ansiState1.bg24bit = [12,13,14];21ansiState1.fg8bit = [15,16,17];22ansiState1.bg8bit = [18,19,20];23var ansiState2 = ansiState();24ansiState2.fg = 'red';25ansiState2.bg = 'blue';26ansiState2.bold = true;27ansiState2.italic = true;28ansiState2.underline = true;29ansiState2.blink = true;30ansiState2.inverse = true;31ansiState2.concealed = true;32ansiState2.crossedOut = true;33ansiState2.reset = true;34ansiState2.fg256 = 1;35ansiState2.bg256 = 2;36ansiState2.fgRGB = [3,4,5];37ansiState2.bgRGB = [6,7,8];38ansiState2.fg24bit = [9,10,11];39ansiState2.bg24bit = [12,13,14];40ansiState2.fg8bit = [15,16,17];41ansiState2.bg8bit = [18,19,20];42var ansiState3 = ansiState();43ansiState3.fg = 'red';44ansiState3.bg = 'blue';45ansiState3.bold = true;46ansiState3.italic = true;47ansiState3.underline = true;48ansiState3.blink = true;49ansiState3.inverse = true;50ansiState3.concealed = true;

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestLine = require('bestline');2var bl = new BestLine();3var state = bl.ansiState();4console.log('state = ' + state);5var BestLine = require('bestline');6var bl = new BestLine();7var state = bl.ansiState();8console.log('state = ' + state);9var BestLine = require('bestline');10var bl = new BestLine();11var state = bl.ansiState();12console.log('state = ' + state);13var BestLine = require('bestline');14var bl = new BestLine();15var state = bl.ansiState();16console.log('state = ' + state);17var BestLine = require('bestline');18var bl = new BestLine();19var state = bl.ansiState();20console.log('state = ' + state);21var BestLine = require('bestline');22var bl = new BestLine();23var state = bl.ansiState();24console.log('state = ' + state);25var BestLine = require('bestline');26var bl = new BestLine();27var state = bl.ansiState();28console.log('state = ' + state);29var BestLine = require('bestline');30var bl = new BestLine();31var state = bl.ansiState();32console.log('state = ' + state);33var BestLine = require('bestline');34var bl = new BestLine();35var state = bl.ansiState();36console.log('state = ' + state);37var BestLine = require('bestline');38var bl = new BestLine();39var state = bl.ansiState();40console.log('state =

Full Screen

Using AI Code Generation

copy

Full Screen

1var bg = require('bestGlobals');2var ansiState = bg.ansiState;3var ansi = new ansiState();4ansi.reset();5ansi.fg('red');6console.log('red');7ansi.reset();8ansi.fg('green');9console.log('green');10ansi.reset();11ansi.fg('blue');12console.log('blue');13ansi.reset();14ansi.fg('cyan');15console.log('cyan');16ansi.reset();17ansi.fg('magenta');18console.log('magenta');19ansi.reset();20ansi.fg('yellow');21console.log('yellow');22ansi.reset();23ansi.fg('white');24console.log('white');25ansi.reset();26ansi.fg('black');27console.log('black');28ansi.reset();29ansi.bg('red');30console.log('red');31ansi.reset();32ansi.bg('green');33console.log('green');34ansi.reset();35ansi.bg('blue');36console.log('blue');37ansi.reset();38ansi.bg('cyan');39console.log('cyan');40ansi.reset();41ansi.bg('magenta');42console.log('magenta');43ansi.reset();44ansi.bg('yellow');45console.log('yellow');46ansi.reset();47ansi.bg('white');48console.log('white');49ansi.reset();50ansi.bg('black');51console.log('black');52ansi.reset();53ansi.fg('white');54ansi.bg('black');55console.log('white on black');56ansi.reset();57ansi.fg('black');58ansi.bg('white');59console.log('black on white');60ansi.reset();61ansi.fg('red');62ansi.bg('green');63console.log('red on green');64ansi.reset();65ansi.fg('green');66ansi.bg('red');67console.log('green on red');68ansi.reset();69ansi.fg('cyan');70ansi.bg('yellow');71console.log('cyan on yellow');72ansi.reset();73ansi.fg('yellow');74ansi.bg('cyan');75console.log('yellow on cyan');76ansi.reset();77ansi.fg('magenta');78ansi.bg('blue');79console.log('magenta on blue');80ansi.reset();81ansi.fg('blue');82ansi.bg('magenta');83console.log('blue on magenta');84ansi.reset();85ansi.fg('white');86ansi.bg('black');87console.log('white on black');88ansi.reset();89ansi.fg('black');90ansi.bg('white');91console.log('black on white');92ansi.reset();93ansi.fg('red');94ansi.bg('green');95console.log('red on green');96ansi.reset();97ansi.fg('green');98ansi.bg('red');

Full Screen

Using AI Code Generation

copy

Full Screen

1var bg = require('bestGlobals');2console.log(bg.ansiState('bold', 'underline', 'red'));3console.log('Hello World');4console.log(bg.ansiState('reset'));5console.log('Hello World');6var bg = require('bestGlobals');7bg.log('Hello World');8bg.log('Hello World', 'bold', 'underline', 'red');9bg.log('Hello World', 'reset');10bg.log('Hello World', 'bold', 'underline', 'red', 'reset');11bg.log('Hello World', 'underline', 'red', 'reset', 'bold');12var bg = require('bestGlobals');13var state = bg.ansiState('bold', 'underline', 'red');14bg.log('Hello World', state);15bg.log('Hello World', 'reset');16bg.log('Hello World', 'bold', 'underline', 'red');17bg.log('Hello World', 'reset');18var bg = require('bestGlobals');19var state = bg.ansiState('bold', 'underline', 'red');20bg.log('Hello World', state);21bg.log('Hello World', 'reset');22bg.log('Hello World', 'bold', 'underline', 'red');23bg.log('Hello World', 'reset');24var bg = require('bestGlobals');25var state = bg.ansiState('bold', 'underline', 'red');26bg.log('Hello World', state);27bg.log('Hello World', 'reset');28bg.log('Hello World', 'bold', 'underline', 'red');29bg.log('Hello World', 'reset');30var bg = require('bestGlobals');31var state = bg.ansiState('bold', 'underline', 'red');

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestGlobals = require('../BestGlobals.js');2var ansiState = BestGlobals.ansiState;3var ansi = BestGlobals.ansi;4var ansiReset = BestGlobals.ansiReset;5var ansiMove = BestGlobals.ansiMove;6var ansiClear = BestGlobals.ansiClear;7var ansiClearLine = BestGlobals.ansiClearLine;8var ansiClearScreen = BestGlobals.ansiClearScreen;9var ansiClearScreenDown = BestGlobals.ansiClearScreenDown;10var ansiClearScreenUp = BestGlobals.ansiClearScreenUp;11var ansiClearScreenDown = BestGlobals.ansiClearScreenDown;12var ansiClearScreenUp = BestGlobals.ansiClearScreenUp;13var ansiClearLine = BestGlobals.ansiClearLine;14var ansiClearLineLeft = BestGlobals.ansiClearLineLeft;15var ansiClearLineRight = BestGlobals.ansiClearLineRight;16var ansiSaveCursor = BestGlobals.ansiSaveCursor;17var ansiRestoreCursor = BestGlobals.ansiRestoreCursor;18var ansiHideCursor = BestGlobals.ansiHideCursor;19var ansiShowCursor = BestGlobals.ansiShowCursor;20var ansiCursor = BestGlobals.ansiCursor;21var ansiCursorUp = BestGlobals.ansiCursorUp;22var ansiCursorDown = BestGlobals.ansiCursorDown;23var ansiCursorForward = BestGlobals.ansiCursorForward;24var ansiCursorBackward = BestGlobals.ansiCursorBackward;25var ansiCursorNextLine = BestGlobals.ansiCursorNextLine;26var ansiCursorPreviousLine = BestGlobals.ansiCursorPreviousLine;27var ansiCursorHorizontalAbsolute = BestGlobals.ansiCursorHorizontalAbsolute;28var ansiCursorPosition = BestGlobals.ansiCursorPosition;29var ansiEraseCharacters = BestGlobals.ansiEraseCharacters;30var ansiEraseInDisplay = BestGlobals.ansiEraseInDisplay;31var ansiEraseInLine = BestGlobals.ansiEraseInLine;32var ansiScrollUp = BestGlobals.ansiScrollUp;33var ansiScrollDown = BestGlobals.ansiScrollDown;34var ansiInsertLines = BestGlobals.ansiInsertLines;35var ansiDeleteLines = BestGlobals.ansiDeleteLines;36var ansiDeleteCharacters = BestGlobals.ansiDeleteCharacters;

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestLine = require('bestline');2var bl = new BestLine();3var state = bl.ansiState();4console.log(state);5### bl.ansiState()6[MIT](

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestConsole = require('best-console');2var bc = new BestConsole();3bc.ansiState("40;37", "1;33", 0, 0);4bc.log("This is a test of the ansiState method");5bc.ansiState("40;37", "1;33", 0, 1);6bc.log("This is a test of the ansiState method");7bc.ansiState("40;37", "1;33", 0, 2);8bc.log("This is a test of the ansiState method");9bc.ansiState("40;37", "1;33", 0, 3);10bc.log("This is a test of the ansiState method");11bc.ansiState("40;37", "1;33", 0, 4);12bc.log("This is a test of the ansiState method");13bc.ansiState("40;37", "1;33", 0, 5);14bc.log("This is a test of the ansiState method");15bc.ansiState("40;37", "1;33", 0, 6);16bc.log("This is a test of the ansiState method");17bc.ansiState("40;37", "1;33", 0, 7);18bc.log("This is a test of the ansiState method");19bc.ansiState("40;37", "1;33", 0, 8);20bc.log("This is a test of the ansiState method");21bc.ansiState("40;37", "1;33", 0, 9);22bc.log("This is a test of the ansiState method");23bc.ansiState("40;37", "1;33", 0, 10);24bc.log("This is a test of the ansiState method");25bc.ansiState("40;37", "1;33", 0, 11);26bc.log("This is a test of the ansiState method");27bc.ansiState("40;37", "1;33", 0, 12);28bc.log("This is a test of the ansiState method");29bc.ansiState("40;37", "1;33", 0

Full Screen

Using AI Code Generation

copy

Full Screen

1var bg = require('./bestGlobals.js');2var term = new bg.BestGlobals(0, 0);3var ansi = new bg.AnsiState();4ansi.reset();5ansi.setBold(true);6ansi.setUnderline(true);7ansi.setFgColor(1);8ansi.setBgColor(1);9ansi.setFgColor(2);10ansi.setBgColor(2);11ansi.setFgColor(3);12ansi.setBgColor(3);13ansi.setFgColor(4);14ansi.setBgColor(4);15ansi.setFgColor(5);16ansi.setBgColor(5);17ansi.setFgColor(6);18ansi.setBgColor(6);19ansi.setFgColor(7);20ansi.setBgColor(7);21ansi.setFgColor(8);22ansi.setBgColor(8);23ansi.setFgColor(9);24ansi.setBgColor(9);25ansi.setFgColor(10);26ansi.setBgColor(10);27ansi.setFgColor(11);28ansi.setBgColor(11);29ansi.setFgColor(12);30ansi.setBgColor(12);31ansi.setFgColor(13);32ansi.setBgColor(13);33ansi.setFgColor(14);34ansi.setBgColor(14);35ansi.setFgColor(15);36ansi.setBgColor(15);37ansi.setFgColor(16);38ansi.setBgColor(16);39ansi.setFgColor(17);40ansi.setBgColor(17);41ansi.setFgColor(18);42ansi.setBgColor(18);43ansi.setFgColor(19);44ansi.setBgColor(19);45ansi.setFgColor(20);46ansi.setBgColor(20);47ansi.setFgColor(21);48ansi.setBgColor(21);49ansi.setFgColor(22);50ansi.setBgColor(22);51ansi.setFgColor(23);52ansi.setBgColor(23);53ansi.setFgColor(24);54ansi.setBgColor(24);55ansi.setFgColor(25);56ansi.setBgColor(25);57ansi.setFgColor(26);58ansi.setBgColor(26);59ansi.setFgColor(27);60ansi.setBgColor(27);61ansi.setFgColor(28);62ansi.setBgColor(28);63ansi.setFgColor(29);64ansi.setBgColor(29);65ansi.setFgColor(30

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful