mirror of
https://github.com/MeowLynxSea/ceditor.git
synced 2025-07-09 10:54:37 +00:00
56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
#include "BaseComponent.h"
|
|
#include "Editor.h"
|
|
#include "../utils/RichText.h"
|
|
#include <conio.h>
|
|
#include <fstream>
|
|
|
|
int main() {
|
|
Editor editor(2, 2, 80, 20);
|
|
editor.setTitle("Editor Demo");
|
|
|
|
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
CONSOLE_CURSOR_INFO cci;
|
|
cci.bVisible = false;
|
|
cci.dwSize = 1;
|
|
SetConsoleCursorInfo(hConsole, &cci);
|
|
|
|
std::ifstream file("Editor_test.cpp");
|
|
std::string content;
|
|
std::string line;
|
|
while (std::getline(file, line)) {
|
|
content += line + "\n";
|
|
}
|
|
file.close();
|
|
content = content.substr(0, content.size() - 1); // remove last newline
|
|
|
|
editor.setRuleName("cpp");
|
|
editor.setContent(content, true);
|
|
|
|
editor.draw();
|
|
|
|
while(true) {
|
|
if (_kbhit()) {
|
|
int scan = _getch(), opt;
|
|
if(scan == 224) {
|
|
opt = _getch() + 256;
|
|
} else if(scan == 26 || scan == 25) {
|
|
opt = scan + 512;
|
|
} else {
|
|
opt = scan;
|
|
}
|
|
if(editor.isFocused()) {
|
|
if(opt == 27) {
|
|
editor.setFocus(false);
|
|
} else {
|
|
editor.onKeyPress(opt);
|
|
}
|
|
} else {
|
|
if(opt == 'i') {
|
|
editor.setFocus(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
} |