diff --git a/README.md b/README.md index 4a7ad0b..592a682 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,11 @@ ## 特性   你可以将控制台窗口分割为若干个**窗格**,窗格之间可创建**分割线**来区别它们。每个窗格拥有一个行缓存,包含若干**行**。你可以改变行缓存的大小。 -  你可以动态地为**窗格**增加**行**,仅需要向窗格添加文本,窗格将自动把文本分割为适应的行,改变窗格大小它也将自动更新。 +  你可以动态地为**窗格**增加**行**,仅需要向窗格添加文本,窗格将自动把文本分割为适应的行,改变窗格大小它也将自动更新。支持ANSI和UTF-8两种编码格式。   你可以为每一**行**设定字符格式,字符格式由Windows的一些常量定义。 +  这不是一个设计严谨的库,使用需谨慎。 ## 开发环境   Windows,Visual Studio 2017 @@ -109,7 +110,9 @@ * 对用户输入的控制比较无力 * 只能对整行设定字符样式 * 分割线的交点没有做特殊处理很难看 +* 不支持Unicode * **功能没有全部测试** +* 由于未知原因,g++编译测试示例时失败,仅VS编译成功(不是get_s的原因==) * 其他 @@ -139,6 +142,23 @@ int main() { } ``` +## 文件列表 +
+README.md
+conctrl
+|----coding.cpp         //编码转换
+|----coding.h
+|----conctrl.cpp        //定义导出函数
+|----conctrl.def        //导出定义文件
+|----conctrl.h          //声明导出函数,提供给用户
+|----console-window.cpp //定义控制台窗口控制器
+|----console-window.h
+|----pannel.cpp         //定义窗格
+|----pannel.h
+|----spliter.cpp        //定义分割线
+|----spliter.h
+
+ ## 辅助资料 diff --git a/conctrl/conctrl.vcxproj b/conctrl/conctrl.vcxproj index f9f67dc..9f35470 100644 --- a/conctrl/conctrl.vcxproj +++ b/conctrl/conctrl.vcxproj @@ -22,7 +22,6 @@ - diff --git a/conctrl/conctrl.vcxproj.filters b/conctrl/conctrl.vcxproj.filters index dcf0c4e..6f8ab97 100644 --- a/conctrl/conctrl.vcxproj.filters +++ b/conctrl/conctrl.vcxproj.filters @@ -30,9 +30,6 @@ Source Files - - Source Files - diff --git a/test/test.vcxproj b/test/test.vcxproj deleted file mode 100644 index f7e7a8e..0000000 --- a/test/test.vcxproj +++ /dev/null @@ -1,120 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 15.0 - {629BA97E-AE88-4F62-8ABB-EDBC575D5284} - test - 10.0.17134.0 - - - - Application - true - v141 - MultiByte - - - Application - false - v141 - true - MultiByte - - - Application - true - v141 - MultiByte - - - Application - false - v141 - true - MultiByte - - - - - - - - - - - - - - - - - - - - - - - Level3 - MaxSpeed - true - true - true - true - - - true - true - - - - - Level3 - Disabled - true - true - - - - - Level3 - Disabled - true - true - - - - - Level3 - MaxSpeed - true - true - true - true - - - true - true - - - - - - \ No newline at end of file diff --git a/test/test.vcxproj.filters b/test/test.vcxproj.filters deleted file mode 100644 index 4863ddb..0000000 --- a/test/test.vcxproj.filters +++ /dev/null @@ -1,17 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - \ No newline at end of file diff --git a/test_x64/conctrl.cpp b/test_x64/conctrl.cpp new file mode 100644 index 0000000..450a0b0 --- /dev/null +++ b/test_x64/conctrl.cpp @@ -0,0 +1,114 @@ +#define _CRT_SECURE_NO_WARNINGS +#include "console_window.h" +#include "pannel.h" +#include "spliter.h" +#include "coding.h" +#include "conctrl.h" + +//ǰ̨ڶӦĿƴ +ConsoleWindow* CreateConsoleWindow(int width, int height) { + if (width <= 5 || height <= 5 || width > 32767 || height > 32767) + return new(std::nothrow) ConsoleWindow(); + else { + return new(std::nothrow) ConsoleWindow(width, height); + } +} + +void DestroyConsoleWindow(ConsoleWindow* window) { + delete window; +} + +//ôںͻС +bool ResizeScreenBuffer(ConsoleWindow* window, int width, int height) { + if (width <= 5 || height <= 5 || width > 32767 || height > 32767) + return false; + return window->Resize({ (SHORT)width, (SHORT)height }); +} +//ÿ̨ڱ +bool SetConsoleWindowTitle(char* _title, bool utf8) { + if (utf8) { + std::string title; + title = UTF8ToANSI(_title); + return SetConsoleTitle(title.c_str()); + } + return SetConsoleTitle(_title); +} +//һ +Pannel* CreatePannel(ConsoleWindow* window, int left, int top, int width, int height) { + if (left < 0 || top < 0 + || left > 32767 || top > 32767 || width > 32767 || height > 32767 + ) return NULL; + return window->NewPannel({ (SHORT)left, (SHORT)top, (SHORT)(left + width - 1), (SHORT)(top + height - 1) }); +} +//ɾ +void DestroyPannel(ConsoleWindow* window, Pannel* pannel) { + window->RemovePannel(pannel); +} +//PannelлС +bool SetMaxLineCache(Pannel* pannel, int lineCount) { + if (lineCount < 0) return false; + pannel->maxLineCount = lineCount; + return true; +} +//Pannelı +void AddPannelText(Pannel* pannel, const char* _text, bool focus, bool utf8, int attribute) { + std::string text; + if (utf8) text = UTF8ToANSI(_text); + else text = _text; + pannel->AddText(text, focus, attribute); +} +//Pannel +void AddPannelLine(Pannel* pannel, const char* _text, bool focus, bool utf8, int attribute) { + std::string text; + if (utf8) text = UTF8ToANSI(_text); + else text = _text; + pannel->AddLine(text, focus, attribute); +} +//Pannel +void ClearPannel(Pannel* pannel) { + pannel->Clear(); +} +//ƶıPannelС +bool MovePannel(Pannel* pannel, int left, int top, int width, int height) { + if(left > 32767 || top > 32767 || width > 32767 || height > 32767) return false; + if (left < 0) left = pannel->area.Left; + if (top < 0) top = pannel->area.Top; + if (width <= 5) width = pannel->area.Right - pannel->area.Left + 1; + if (height <= 5) height = pannel->area.Bottom - pannel->area.Top+ 1; + pannel->Move({ (SHORT)left, (SHORT)top, (SHORT)(left + width - 1), (SHORT)(top + height - 1)}); + return true; +} +//ǰ +bool ScrollPannelBackward(Pannel* pannel, int lineCount) { + return pannel->ScrollBackward(lineCount); +} +// +bool ScrollPannelForward(Pannel* pannel, int lineCount) { + return pannel->ScrollForward(lineCount); +} +//ض +bool ScrollPannelTo(Pannel* pannel, int lineTo) { + return pannel->ScrollTo(lineTo); +} +//õضλ +bool FocusOnPannel(Pannel* pannel, int offsetLeft, int offsetTop) { + return pannel->Focus({ (SHORT)offsetLeft, (SHORT)offsetTop }); +} +//һָߡ +Spliter* CreateSpliter(ConsoleWindow* window, int left, int top, int length, bool verticle, int attribute) { + if (length <= 0 + || left < 0 || left >= window->bufferSize.X + || top < 0 || top >= window->bufferSize.Y + ) return NULL; + return window->NewSpliter({ (SHORT)left, (SHORT)top}, length, verticle, attribute); +} +//ɾָ +void DestroySpliter(ConsoleWindow* window, Spliter* spliter) { + window->RemoveSpliter(spliter); +} +//ƶ趨ָ߳ +bool MoveSpliter(Spliter* spliter, int left, int top, int len) { + if (left < 0 || left > 32767 || top < 0 || top > 32767 || len < 0) return false; + spliter->Move({ (SHORT)left, (SHORT)top }, len); + return true; +} diff --git a/test_x64/conctrl.dll b/test_x64/conctrl.dll new file mode 100644 index 0000000..2fae2ce Binary files /dev/null and b/test_x64/conctrl.dll differ diff --git a/test_x64/conctrl.h b/test_x64/conctrl.h new file mode 100644 index 0000000..b215540 --- /dev/null +++ b/test_x64/conctrl.h @@ -0,0 +1,106 @@ +// ConsoleController +// 2018-11-28 +// By Mattuy +#ifndef _HEAD_CONSOLE_CONTROLLER_ +#define _HEAD_CONSOLE_CONTROLLER_ +#ifdef __cplusplus //cpp +class ConsoleWindow; +class Pannel; +class Spliter; +#else //C +typedef void ConsoleWindow; +typedef void Pannel; +typedef void Spliter; +#endif +extern "C" { + /** + * ̨ + * @return value, ָǰ̨Ŀָ̨룬ΪIJͨ + * ̨ʧܷ0 + * @param width, ĻȣЧΧ(5, 32767)Ĭ80 + * @param height, Ļ߶ȣЧΧ(5, 32767)Ĭ40 + */ + ConsoleWindow* CreateConsoleWindow(int width = 80, int height = 40); + //ԭ̨ٿ + void DestroyConsoleWindow(ConsoleWindow* window); + //ôںͻС + bool ResizeScreenBuffer(ConsoleWindow* window, int width, int height); + /** + * ÿ̨ڱ + * @param window, ҪñĴ + * @param title, Ҫõı + * @param utf8, Ƿutf8롣UTF-8Ϊ0ANSI + */ + bool SetConsoleWindowTitle(char* title, bool utf8 = false); + /** + * һ + * @return value, ָһָ + * @param window, + * @param left, ԴڵˮƽƫƣЧΧ(5, 32767) + * @param top, ԴڵֱƫƣЧΧ(5, 32767) + * @param width, ĿȣЧΧ(5, 32767) + * @param height, ĸ߶ȣЧΧ(5, 32767) + */ + Pannel* CreatePannel(ConsoleWindow* window, int left, int top, int width, int height); + //ɾ + void DestroyPannel(ConsoleWindow* window, Pannel* pannel); + //ôлС + bool SetMaxLineCache(Pannel* pannel, int lineCount); + /** + * PannelıлһвǻзβáAddPannelLineӵģ + * ıϲһСԭıҲᱻǡ + * @param window, + * @param text, Ҫӵַ + * @param focus, Ƿ񽫹ƶӵı + * @param utf8, Ƿutf8롣֧ANSIUTF-8룬UTF-8ҲתΪANSI + * 롣ĬΪfalse + * @param attribute, ıԣWindowsĿ̨ĬϺڵװ + */ + void AddPannelText(Pannel* pannel, const char* text, bool focus, bool utf8 = false, int attribute = 7); + //AddTextΨһIJͬǣַԻзβԶ뻻з + void AddPannelLine(Pannel* pannel, const char* text, bool focus, bool utf8 = false, int attribute = 7); + //Pannel⽫ͬʱpannelл + void ClearPannel(Pannel* pannel); + //ƶıPannelСͬCreatePannelЧ÷ı + bool MovePannel(Pannel* pannel, int left, int top, int width, int height); + /** + * ǰ + * @return value, ǰѴfalse򷵻true + * @param pannel, ҪĴ + * @param lineCount, ҪС0һԴ + */ + bool ScrollPannelBackward(Pannel* pannel, int lineCount); + // + bool ScrollPannelForward(Pannel* pannel, int lineCount); + //ضСкС0󣬷кЧfalse + bool ScrollPannelTo(Pannel* pannel, int lineTo); + /** + * õضλá + * @return value, offsetΧʧ + * @param pannel, ҪùڵĴ + * @param offsetLeft, ԴϽǵˮƽƫƣĬΪ0 + * @param offsetTop, ԴϽǵĴֱƫƣĬΪ0 + */ + bool FocusOnPannel(Pannel* pannel, int offsetLeft = 0, int offsetTop = 0); + /** + * һָߡ + * @return value, ָһָߵָ + * @param window, Ĵ + * @param left, ָԴڵˮƽƫƣЧΧ(5, 32767) + * @param top, ָԴڵֱƫƣЧΧ(5, 32767) + * @param length, ָߵijȻȡǰ߻Ǻȡ@param verticle + * @param verticle, ˮƽָ߻ֱָߡ0Ϊˮƽ0Ϊֱ + * @param attribute, ָߵıԣWindowsĿ̨ĬϺڵװ + */ + Spliter* CreateSpliter(ConsoleWindow* window, int left, int top, int length, bool verticle, int attribute = 7); + //ɾָ + void DestroySpliter(ConsoleWindow* window, Spliter* spliter); + /** + * ƶ趨ָߵij + * @param left, ԴˮƽƫƣС0򲻸ı + * @param top, ԴڵĴֱƫƣС0򲻸ı + * @param len, µij/߶ȡС0򲻸ı + */ + bool MoveSpliter(Spliter* spliter, int left, int top, int len); +} +#endif // !_HEAD_CONSOLE_CONTROLLER_ diff --git a/test_x64/conctrl.lib b/test_x64/conctrl.lib new file mode 100644 index 0000000..9f1234a Binary files /dev/null and b/test_x64/conctrl.lib differ diff --git a/conctrl/main.cpp b/test_x64/main.cpp similarity index 81% rename from conctrl/main.cpp rename to test_x64/main.cpp index ca631b8..d994ad0 100644 --- a/conctrl/main.cpp +++ b/test_x64/main.cpp @@ -2,16 +2,17 @@ #include #include #include "conctrl.h" +#pragma comment(lib, "conctrl.lib") int main() { ConsoleWindow* window = CreateConsoleWindow(80, 40); Pannel* messagePannel = CreatePannel(window, 0, 0, 78, 25); Pannel* writePannel = CreatePannel(window, 0, 26, 80, 40); Spliter* spliter = CreateSpliter(window, 0, 25, 80, false, FOREGROUND_GREEN); - AddPannelText(messagePannel, "ݣس", true, true, 7); + AddPannelText(messagePannel, "请在下方输入任意内容", true, true, 7); FocusOnPannel(writePannel, 0, 0); while (true) { char text[1024]; - gets_s(text, 1024); + gets(text); AddPannelText(messagePannel, text, false, false, FOREGROUND_RED | FOREGROUND_GREEN); ClearPannel(writePannel); FocusOnPannel(writePannel, 0, 0);