⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tconsole.cpp

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
///////////////////////////////////////////////////////////////////////////////
//Telnet Win32 : an ANSI telnet client.
//Copyright (C) 1998-2000 Paul Brannan
//Copyright (C) 1998 I.Ioannou
//Copyright (C) 1997 Brad Johnson
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2
//of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//I.Ioannou
//roryt@hol.gr
//
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
//
// Module:		tconsole.cpp
//
// Contents:	screen functions
//
// Product:		telnet
//
//
// Revisions: Mar. 29, 2000 pbranna@clemson (Paul Brannan)
//            June 15, 1998 pbranna@clemson.edu
//            May 16, 1998	pbranna@clemson.edu
//            05. Sep.1997  roryt@hol.gr (I.Ioannou)
//            11.May,1997   roryt@hol.gr
//            06.April,1997 roryt@hol.gr
//            30.M剅z.1997  Titus_Boxberg@public.uni-hamburg.de
//		      5.Dec.1996    jbj@nounname.com
//            Version 2.0
//            02.Apr.1995	igor.milavec@uni-lj.si
//					  Original code
//
///////////////////////////////////////////////////////////////////////////////

#include <windows.h>
#include "tconsole.h"

// argsused doesn't work on MSVC++
#ifdef __BORLANDC__
#pragma argsused
#endif

TConsole::TConsole(HANDLE h) {
	hConsole = h;

	GetConsoleScreenBufferInfo(hConsole, &ConsoleInfo);

	// Start with correct colors
	int color_fg = ini.get_normal_fg();
	int color_bg = ini.get_normal_bg();
	if(color_fg == -1)
		color_fg = defaultfg = origfg = ConsoleInfo.wAttributes & 0xF;
	else
		defaultfg = origfg = color_fg;
	if(color_bg == -1)
		color_bg = defaultbg = origbg = (ConsoleInfo.wAttributes >> 4) & 0xF;
	else
		defaultbg = origbg = color_bg;
	wAttributes = color_fg | (color_bg << 4);
	reverse = blink = underline = false;
	SetConsoleTextAttribute(hConsole, wAttributes);

	insert_mode = 0;
	
	// Set the screen size
	SetWindowSize(ini.get_term_width(), ini.get_term_height());

	iScrollStart = -1;
	iScrollEnd = -1;
}

TConsole::~TConsole() {
	wAttributes = origfg | (origbg << 4);
	SetCursorPosition(0, CON_HEIGHT);
	SetConsoleTextAttribute(hConsole, wAttributes);
	WriteCtrlChar('\x0a');
}

// Paul Brannan 8/2/98
void TConsole::SetWindowSize(int width, int height) {
	SMALL_RECT sr = {
		CON_LEFT,
		CON_TOP,
		(width == -1) ? CON_RIGHT : CON_LEFT + width - 1,
		(height == -1) ? CON_BOTTOM : CON_TOP + height - 1
	};
	ConsoleInfo.dwSize.X = width;
	if(ConsoleInfo.dwSize.Y < height) ConsoleInfo.dwSize.Y = height;
	SetConsoleScreenBufferSize(hConsole, ConsoleInfo.dwSize);
	SetConsoleWindowInfo(hConsole, TRUE, &sr);
	SetConsoleScreenBufferSize(hConsole, ConsoleInfo.dwSize);
	sync();
}

// Paul Brannan 5/15/98
void TConsole::sync() {
	GetConsoleScreenBufferInfo(hConsole, &ConsoleInfo);
}

void TConsole::HighVideo() {
	wAttributes = wAttributes | (unsigned char) 8;
}

void TConsole::LowVideo() {
	wAttributes = wAttributes & (unsigned char) (0xff-8);
}

void TConsole::Normal() {
	// I.Ioannou 11 May 1997
	// Color 7 is correct on some systems (for example Linux)
	// but not with others (for example SCO)
	// we must preserve the colors :
	// 06/04/98 thanks to Paul a .ini parameter from now on
	
	BlinkOff();
	UnderlineOff();
	if(ini.get_preserve_colors()) {
		ReverseOff();
		LowVideo();
	} else {
		fg = defaultfg;
		bg = defaultbg;
		wAttributes = (unsigned char)fg | (bg << 4);
		reverse = false;
	}
}

void TConsole::SetForeground(unsigned char wAttrib) {
	if(reverse) bg = wAttrib; else fg = wAttrib;
	wAttributes = (wAttributes & (unsigned char)0x88) | 
		(unsigned char)fg | (bg << 4);
}

void TConsole::SetBackground(unsigned char wAttrib) {
	if(reverse) fg = wAttrib; else bg = wAttrib;
	wAttributes = (wAttributes & (unsigned char)0x88) | 
		(unsigned char)fg | (bg << 4);
}

// As far as I can tell, there's no such thing as blink in Windows Console.
// I tried using some inline asm to turn off high-intensity backgrounds,
// but I got a BSOD.  Perhaps there is an undocumented function?
// (Paul Brannan 6/27/98)
void TConsole::BlinkOn() {
	blink = 1;
	if(underline) {
		UlBlinkOn();
	} else {
		if(ini.get_blink_bg() != -1) {
			wAttributes &= 0x8f;					// turn off bg
			wAttributes |= ini.get_blink_bg() << 4;
		}
		if(ini.get_blink_fg() != -1) {
			wAttributes &= 0xf8;					// turn off fg
			wAttributes |= ini.get_blink_fg();
		}
		if(ini.get_blink_bg() == -1 && ini.get_blink_fg() == -1)
			wAttributes |= 0x80;
	}
}

// Added by I.Ioannou 06 April, 1997
void TConsole::BlinkOff() {
	blink = 0;
	if(underline) {
		UlBlinkOff();
	} else {
		if(ini.get_blink_bg() != -1) {
			wAttributes &= 0x8f;					// turn off bg
			wAttributes |= defaultbg << 4;
		}
		if(ini.get_blink_fg() != -1) {
			wAttributes &= 0xf8;					// turn off fg
			wAttributes |= defaultfg;
		}
		if(ini.get_blink_bg() == -1 && ini.get_blink_fg() == -1)
			wAttributes &= 0x7f;
	}
}

// Paul Brannan 6/27/98
void TConsole::UnderlineOn() {
	underline = 1;
	if(blink) {
		UlBlinkOn();
	} else {
		if(ini.get_underline_bg() != -1) {
			wAttributes &= 0x8f;					// turn off bg
			wAttributes |= ini.get_underline_bg() << 4;
		}
		if(ini.get_underline_fg() != -1) {
			wAttributes &= 0xf8;					// turn off fg
			wAttributes |= ini.get_underline_fg();
		}
		if(ini.get_underline_bg() == -1 && ini.get_underline_fg() == -1)
			wAttributes |= 0x80;
	}
}

// Paul Brannan 6/27/98
void TConsole::UnderlineOff() {
	underline = 0;
	if(blink) {
		UlBlinkOff();
	} else {
		if(ini.get_blink_bg() != -1) {
			wAttributes &= 0x8f;					// turn off bg
			wAttributes |= defaultbg << 4;
		}
		if(ini.get_blink_fg() != -1) {
			wAttributes &= 0xf8;					// turn off fg
			wAttributes |= defaultfg;
		}
		if(ini.get_blink_bg() == -1 && ini.get_blink_fg() == -1)
			wAttributes &= 0x7f;
	}
}

// Paul Brannan 6/27/98
void TConsole::UlBlinkOn() {
	if(ini.get_ulblink_bg() != -1) {
		wAttributes &= 0x8f;					// turn off bg
		wAttributes |= ini.get_ulblink_bg() << 4;
	}
	if(ini.get_ulblink_fg() != -1) {
		wAttributes &= 0xf8;					// turn off fg
		wAttributes |= ini.get_ulblink_fg();
	}
	if(ini.get_ulblink_bg() == -1 && ini.get_ulblink_fg() == -1)
		wAttributes |= 0x80;
}

// Paul Brannan 6/27/98
void TConsole::UlBlinkOff() {
	if(blink) {
		BlinkOn();
	} else if(underline) {
		UnderlineOn();
	} else {
		Normal();
	}
}

// Paul Brannan 6/26/98
void TConsole::Lightbg() {
	WORD *pAttributes = new WORD[CON_COLS];
	DWORD Result;

	// Paul Brannan 8/5/98
	// Correction: processing more than one line at a time causes a segfault
	// if the screen width != 80
	for(int i = CON_TOP; i <= CON_BOTTOM; i++) {
		COORD Coord = {CON_LEFT, i};

		ReadConsoleOutputAttribute(hConsole, pAttributes, (DWORD)(CON_COLS),
			Coord, &Result);
	
		for(DWORD j = 0; j < Result; j++) pAttributes[j] |= 0x80;

		WriteConsoleOutputAttribute(hConsole, pAttributes, Result, Coord,
			&Result);
	}

	delete[] pAttributes; // clean up

	wAttributes |= (unsigned char)0x80;
	bg |= 8;
}

// Paul Brannan 6/26/98
void TConsole::Darkbg() {
	WORD *pAttributes = new WORD[CON_COLS];
	DWORD Result;

	// Paul Brannan 8/5/98
	// Correction: processing more than one line at a time causes a segfault
	// if the screen width != 80
	for(int i = CON_TOP; i <= CON_BOTTOM; i++) {
		COORD Coord = {CON_LEFT, i};

		ReadConsoleOutputAttribute(hConsole, pAttributes, (DWORD)(CON_COLS),
			Coord, &Result);
	
		for(DWORD j = 0; j < Result; j++) pAttributes[j] &= 0x7f;

		WriteConsoleOutputAttribute(hConsole, pAttributes, Result, Coord,
			&Result);
	}

	delete[] pAttributes; // clean up


	wAttributes &= (unsigned char)0x7f;
	bg &= 7;
}

// Added by I.Ioannou 11.May,1997
void TConsole::ReverseOn() {
	if (!reverse) {
		reverse = true;

		// atl  : forground attributes without the intensity
		// ath  : backgound attributes without the blink
		// bl   : the blink state
		// ints : the intensity
		unsigned char atl   = wAttributes & (unsigned char) 0x07;
		unsigned char ath   = wAttributes & (unsigned char) 0x70;
		unsigned char bl    = wAttributes & (unsigned char) 0x80;
		unsigned char ints  = wAttributes & (unsigned char) 0x08;
		wAttributes = bl | (atl << 4) | ints | (ath >> 4);
	}
}

// Added by I.Ioannou 11.May,1997
void TConsole::ReverseOff() {
	if (reverse) {
		reverse = false;
		wAttributes = fg | (bg << 4);
	}
}

unsigned long TConsole::WriteText(const char *pszString, unsigned long cbString) {
	DWORD Result;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -