Skip to content
Snippets Groups Projects
con_out.cpp 31.2 KiB
Newer Older
rswindell's avatar
rswindell committed
				bputs(text[LongLineContinuationPrefix]);
		case '?':	/* Conditional blank-line */
			if(column > 0)
rswindell's avatar
rswindell committed
				newline();
rswindell's avatar
rswindell committed
				newline();
		case '[':   /* Carriage return */
rswindell's avatar
rswindell committed
			carriage_return();
			break;
		case ']':   /* Line feed */
rswindell's avatar
rswindell committed
			line_feed();
			break;
		case 'A':   /* Ctrl-A */
			outchar(CTRL_A);
		case 'Z':	/* Ctrl-Z */
			outchar(CTRL_Z);
			break;
		case 'H': 	/* High intensity */
			atr|=HIGH;
			attr(atr);
			break;
		case 'I':
 			if((term_supports()&(ICE_COLOR|PETSCII)) != ICE_COLOR)
				attr(atr|BLINK);
			break;
		case 'E': /* Bright Background */
 			if(term_supports()&(ICE_COLOR|PETSCII))
				attr(atr|BG_BRIGHT);
		case 'F':	/* Blink, only if alt Blink Font is loaded */
			if(((atr&HIGH) && (console&CON_HBLINK_FONT)) || (!(atr&HIGH) && (console&CON_BLINK_FONT)))
				attr(atr|BLINK);
			else if(x == 'F' && !(atr&HIGH))	/* otherwise, set HIGH attribute (only if capital 'F') */
				attr(atr|HIGH);
			break;
		case 'N': 	/* Normal */
			attr(LIGHTGRAY);
			break;
		case 'R':
			atr=(atr&0xf8)|RED;
			attr(atr);
			break;
		case 'G':
			atr=(atr&0xf8)|GREEN;
			attr(atr);
			break;
		case 'B':
			atr=(atr&0xf8)|BLUE;
			attr(atr);
			break;
		case 'W':	/* White */
			atr=(atr&0xf8)|LIGHTGRAY;
			attr(atr);
			break;
		case 'C':
			atr=(atr&0xf8)|CYAN;
			attr(atr);
			break;
		case 'M':
			atr=(atr&0xf8)|MAGENTA;
			attr(atr);
			break;
		case 'Y':   /* Yellow */
			atr=(atr&0xf8)|BROWN;
			attr(atr);
			break;
		case 'K':	/* Black */
			atr=(atr&0xf8)|BLACK;
			attr(atr);
			break;
		case '0':	/* Black Background */
			attr(atr);
			break;
		case '1':	/* Red Background */
			attr(atr | BG_RED);
			break;
		case '2':	/* Green Background */
			attr(atr | BG_GREEN);
			break;
		case '3':	/* Yellow Background */
			attr(atr | BG_BROWN);
			break;
		case '4':	/* Blue Background */
			attr(atr | BG_BLUE);
			break;
		case '5':	/* Magenta Background */
			attr(atr |BG_MAGENTA);
			break;
		case '6':	/* Cyan Background */
			attr(atr | BG_CYAN);
			break;
		case '7':	/* White Background */
			attr(atr | BG_LIGHTGRAY);
}

/****************************************************************************/
rswindell's avatar
rswindell committed
/* Sends terminal control codes to change remote terminal colors/attributes */
/****************************************************************************/
rswindell's avatar
rswindell committed
	int		newatr = atr;

	long term = term_supports();
	if(term&PETSCII) {
		if(atr&(0x70|BG_BRIGHT)) {	// background color (reverse video for PETSCII)
			if(atr&BG_BRIGHT)
				atr |= HIGH;
			else
				atr &= ~HIGH;
			atr = (atr&(BLINK|HIGH)) | ((atr&0x70)>>4);
rswindell's avatar
rswindell committed
			outcom(PETSCII_REVERSE_ON);
		} else
			outcom(PETSCII_REVERSE_OFF);
		if(atr&BLINK)
			outcom(PETSCII_FLASH_ON);
		else
			outcom(PETSCII_FLASH_OFF);
		switch(atr&0x0f) {
			case BLACK:
				outcom(PETSCII_BLACK);
				break;
			case WHITE:
				outcom(PETSCII_WHITE);
				break;
			case DARKGRAY:
				outcom(PETSCII_DARKGRAY);
				break;
			case LIGHTGRAY:
				outcom(PETSCII_LIGHTGRAY);
				break;
			case BLUE:
				outcom(PETSCII_BLUE);
				break;
			case LIGHTBLUE:
				outcom(PETSCII_LIGHTBLUE);
				break;
			case CYAN:
				outcom(PETSCII_MEDIUMGRAY);
				break;
			case LIGHTCYAN:
				outcom(PETSCII_CYAN);
				break;
			case YELLOW:
				outcom(PETSCII_YELLOW);
				break;
			case BROWN:
				outcom(PETSCII_BROWN);
				break;
			case RED:
				outcom(PETSCII_RED);
				break;
			case LIGHTRED:
				outcom(PETSCII_LIGHTRED);
				break;
			case GREEN:
				outcom(PETSCII_GREEN);
				break;
			case LIGHTGREEN:
				outcom(PETSCII_LIGHTGREEN);
				break;
			case MAGENTA:
				outcom(PETSCII_ORANGE);
				break;
			case LIGHTMAGENTA:
				outcom(PETSCII_PURPLE);
				break;
		}
	}
	else if(term&ANSI)
		rputs(ansi(newatr,curatr,str));
	curatr=newatr;
}

/****************************************************************************/
/* Checks to see if user has hit Pause or Abort. Returns 1 if user aborted. */
/* If the user hit Pause, waits for a key to be hit.                        */
/* Emulates remote XON/XOFF flow control on local console                   */
/* Preserves SS_ABORT flag state, if already set.                           */
/* Called from various listing procedures that wish to check for abort      */
/****************************************************************************/
bool sbbs_t::msgabort()
{
	if(sys_status&SS_SYSPAGE && !(++counter%100))
		sbbs_beep(sbbs_random(800),1);
	checkline();
	if(sys_status&SS_ABORT)
		return(true);
	if(!online)
		return(true);
	return(false);
}

int sbbs_t::backfill(const char* instr, float pct, int full_attr, int empty_attr)
	uint atr;
	uint save_atr = curatr;
	if(!term_supports(ANSI))
		bputs(str);
	else {
		for(int i=0; i<len; i++) {
			if(((float)(i+1) / len)*100.0 <= pct)
				atr = full_attr;
			else
				atr = empty_attr;
			if(curatr != atr) attr(atr);
			outchar(str[i]);
		}
		attr(save_atr);
void sbbs_t::progress(const char* text, int count, int total, int interval)
	if(cfg.node_num == 0)
		return;	// Don't output this for events
	if(text == NULL) text = "";
	float pct = ((float)count/total)*100.0F;
	SAFEPRINTF2(str, "[ %-8s  %4.1f%% ]", text, pct);
	cursor_left(backfill(str, pct, cfg.color[clr_progress_full], cfg.color[clr_progress_empty]));
}

struct savedline {
	char 	buf[LINE_BUFSIZE+1];	/* Line buffer (i.e. ANSI-encoded) */
	uint	beg_attr;				/* Starting attribute of each line */
	uint	end_attr;				/* Ending attribute of each line */
	long	column;					/* Current column number */
};

bool sbbs_t::saveline(void)
{
	struct savedline line;
	line.beg_attr = latr;
	line.end_attr = curatr;
	line.column = column;
	snprintf(line.buf, sizeof(line.buf), "%.*s", lbuflen, lbuf);
	TERMINATE(line.buf);
	lbuflen=0;
	return listPushNodeData(&savedlines, &line, sizeof(line)) != NULL;
}

bool sbbs_t::restoreline(void)
{
	struct savedline* line = (struct savedline*)listPopNode(&savedlines);
	if(line == NULL)
		return false;
	lbuflen=0;
	attr(line->beg_attr);
	rputs(line->buf);
	curatr = line->end_attr;
	column = line->column;
	free(line);
	return true;
}