Skip to content
Snippets Groups Projects
Select Git revision
  • dd_msg_reader_list_personal_email_in_reverse_choose_msg_fix
  • dailybuild_linux-x64
  • dailybuild_win32
  • master default protected
  • sqlite
  • rip_abstraction
  • dailybuild_macos-armv8
  • dd_file_lister_filanem_in_desc_color
  • mode7
  • dd_msg_reader_are_you_there_warning_improvement
  • c23-playing
  • syncterm-1.3
  • syncterm-1.2
  • test-build
  • hide_remote_connection_with_telgate
  • 638-can-t-control-c-during-a-file-search
  • add_body_to_pager_email
  • mingw32-build
  • cryptlib-3.4.7
  • ree/mastermind
  • sbbs320d
  • syncterm-1.6
  • syncterm-1.5
  • syncterm-1.4
  • sbbs320b
  • syncterm-1.3
  • syncterm-1.2
  • syncterm-1.2rc6
  • syncterm-1.2rc5
  • push
  • syncterm-1.2rc4
  • syncterm-1.2rc2
  • syncterm-1.2rc1
  • sbbs319b
  • sbbs318b
  • goodbuild_linux-x64_Sep-01-2020
  • goodbuild_win32_Sep-01-2020
  • goodbuild_linux-x64_Aug-31-2020
  • goodbuild_win32_Aug-31-2020
  • goodbuild_win32_Aug-30-2020
40 results

asc2htmlterm.js

Blame
  • asc2htmlterm.js 3.86 KiB
    // $Id$
    
    // Converts a ^A/@-code text to HTML for htmlterm usage.
    
    load("graphic.js");
    
    function asc2htmlterm(buf, dospin, partial, mode)
    {
    	var need_table=false;
    	var outbuf_table='';
    	var outbuf_text='';
    	var rows=console.screen_rows;
    	var cols=console.screen_columns;
    	var spinner = new Array('-','\\','|','/');
    	var spin=0;
    	var colour_vals=new Array(
    		"black",		/* black */
    		"#0000a8",		/* dark blue */
    		"#00a800",		/* dark green */
    		"#00a8a8",		/* cyan */
    		"#a80000",		/* dark red */
    		"#a800a8",		/* magenta */
    		"#a85400",		/* brown (dark yellow) */
    		"#a8a8a8",		/* white */
    
    		"#545454",		/* bright black (grey) */
    		"#5454fc",		/* bright blue */
    		"#54fc54",		/* bright green */
    		"#54fcfc",		/* bright cyan */
    		"#fc5454",		/* bright red */
    		"#fc54fc",		/* bright magenta */
    		"#fcfc54",		/* bright yellow */
    		"white"		/* bright white */
    	);
    
    	if(partial==undefined)
    		partial=false;
    
    	/* Remove "bad" at-codes */
    	buf=buf.replace(/@BEEP@/g,'');
    	buf=buf.replace(/@CLS@/g,'');
    	buf=buf.replace(/@MORE@/g,'');
    	buf=buf.replace(/@PAUSE@/g,'');
    
    	if(dospin) {
    		console.write("Converting to HTML  ");
    		console.write("\x08"+spinner[(spin++)%spinner.length]);
    	}
    
    	if(!partial) {
    		outbuf_table += "\2\2<html><head><title>"+title+"</title></head><body bgcolor=\"black\" text=\""+colour_vals[7]+"\">";
    		outbuf_text += "\2\2<html><head><title>"+title+"</title></head><body bgcolor=\"black\" text=\""+colour_vals[7]+"\">";
    	}
    	outbuf_table += "<font face=\"monospace\" color=\""+colour_vals[7]+"\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"black\">\n";
    	outbuf_text += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"black\"><tr><td nowrap><font face=\"monospace\" color=\""+colour_vals[7]+"\">\n";
    	while(buf.length) {
    		var screen=new Graphic(cols,rows,7,' ');
    		if(dospin)
    			console.write("\x08"+spinner[(spin++)%spinner.length]);
    		buf=screen.putmsg(1,1, buf, 7, true, true, mode);
    		if(dospin)
    			console.write("\x08"+spinner[(spin++)%spinner.length]);
    		var total_rows = rows;
    		/* Find blank rows at end and remove them */
    		for(total_rows=rows-1; total_rows >= 0; total_rows--) {
    			var i;
    			var differ=false;
    
    			for(i=cols-1; i>=0; i--) {
    				if(screen.data[i][total_rows].attr != screen.data[cols-1][rows-1].attr
    						|| screen.data[i][total_rows].ch != ' ') {
    					total_rows++;
    					differ=true;
    					break;
    				}
    			}
    			if(differ)
    				break;
    		}
    		for(row=0; row < total_rows; row++) {
    			if(dospin)
    				console.write("\x08"+spinner[(spin++)%spinner.length]);
    			outbuf_table += "<tr>";
    			for(col=0; col<cols; col++) {
    				var blinking=screen.data[col][row].attr & 0x80;
    				var celltext="";
    
    				/* Create cell... set background color */
    				if(screen.data[col][row].attr & 0x70) {
    					outbuf_table += "<td nowrap bgcolor=\""+colour_vals[(screen.data[col][row].attr & 0x70)>>4]+"\">";
    					need_table=true;
    					outbuf_text='';
    				}
    				else
    					outbuf_table += "<td nowrap>";
    
    				/* Set font (forground colour) */
    				if((screen.data[col][row].attr & 0x0f)!=7)
    					celltext += "<font color=\""+colour_vals[screen.data[col][row].attr & 0x0f]+"\">";
    				/* Blink? */
    				if(blinking)
    					celltext += "<blink>";
    				/* Transpate the char and put 'er in the cell */
    				var ch=html_encode(screen.data[col][row].ch, true, false, false, false);
    				if(ch==' ')
    					ch="&nbsp;";
    				celltext += ch;
    				if(blinking)
    					celltext += "</blink>";
    				if((screen.data[col][row].attr & 0x0f)!=7)
    					celltext += "</font>";
    				if(!need_table)
    					outbuf_text += celltext;
    				outbuf_table += celltext;
    				outbuf_table += "</td>";
    			}
    			outbuf_table += "</tr>\n";
    			if(!need_table)
    				outbuf_text += "<br>\n";
    		}
    	}
    	outbuf_table += "</table></font>";
    	if(!need_table) {
    		outbuf_table = outbuf_text + "</font></td></tr></table>";
    		outbuf_text="";
    	}
    
    	if(!partial)
    		outbuf_table += "<br><a href=\" \">Click here to continue...</a></body>\n\2";
    
    	return(outbuf_table);
    }