267 lines
4.9 KiB
C++
267 lines
4.9 KiB
C++
|
#include <cstdio>
|
|||
|
#include <cstring>
|
|||
|
#include <cstdlib>
|
|||
|
#include <string>
|
|||
|
#include <vector>
|
|||
|
#include <algorithm>
|
|||
|
#include <conio.h>
|
|||
|
using namespace std;
|
|||
|
|
|||
|
void ClearScreen()
|
|||
|
{
|
|||
|
system("cls");
|
|||
|
}
|
|||
|
|
|||
|
char GetUserInput()
|
|||
|
{
|
|||
|
fflush(stdin);
|
|||
|
return getch();
|
|||
|
}
|
|||
|
|
|||
|
string GetUserLine()
|
|||
|
{
|
|||
|
char buff[1024];
|
|||
|
memset(buff,0,1024);
|
|||
|
fflush(stdin);
|
|||
|
gets(buff);
|
|||
|
return string(buff);
|
|||
|
}
|
|||
|
|
|||
|
string projectname;
|
|||
|
|
|||
|
struct SelectionInfo
|
|||
|
{
|
|||
|
|
|||
|
};
|
|||
|
|
|||
|
struct PageInfo
|
|||
|
{
|
|||
|
string title;
|
|||
|
vector<string> contextline;
|
|||
|
};
|
|||
|
|
|||
|
vector<PageInfo*> pagevec;
|
|||
|
|
|||
|
#define CASE_Q case 'Q':case 'q'
|
|||
|
#define CASE_W case 'W':case 'w'
|
|||
|
#define CASE_E case 'E':case 'e'
|
|||
|
#define CASE_A case 'A':case 'a'
|
|||
|
#define CASE_S case 'S':case 's'
|
|||
|
#define CASE_D case 'D':case 'd'
|
|||
|
#define CASE_Z case 'Z':case 'z'
|
|||
|
#define CASE_X case 'X':case 'x'
|
|||
|
#define CASE_C case 'C':case 'c'
|
|||
|
|
|||
|
void EditorSetPageTitle(PageInfo* p)
|
|||
|
{
|
|||
|
ClearScreen();
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µı<EFBFBD><EFBFBD><EFBFBD>...\n");
|
|||
|
string newtitle=GetUserLine();
|
|||
|
if(newtitle.empty())
|
|||
|
{
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n"
|
|||
|
"Q <20><><EFBFBD>ձ<EFBFBD><D5B1><EFBFBD>\n"
|
|||
|
"W <20><><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
switch(GetUserInput())
|
|||
|
{
|
|||
|
CASE_Q:
|
|||
|
p->title.clear();
|
|||
|
break;
|
|||
|
CASE_W:
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
p->title=newtitle;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void EditorSetPageContext(PageInfo* p)
|
|||
|
{
|
|||
|
ClearScreen();
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>#<23><><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>һ<EFBFBD>б<EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.\n");
|
|||
|
vector<string> newcontextline;
|
|||
|
string temp;
|
|||
|
while(1)
|
|||
|
{
|
|||
|
temp=GetUserLine();
|
|||
|
if(temp.size()==1&&temp.at(0)=='#') break;
|
|||
|
newcontextline.push_back(temp);
|
|||
|
}
|
|||
|
if(newcontextline.empty())
|
|||
|
{
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n"
|
|||
|
"Q <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n"
|
|||
|
"W <20><><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
switch(GetUserInput())
|
|||
|
{
|
|||
|
CASE_Q:
|
|||
|
p->contextline.clear();
|
|||
|
break;
|
|||
|
CASE_W:
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
p->contextline=newcontextline;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void EditorPagePreview(PageInfo* p)
|
|||
|
{
|
|||
|
ClearScreen();
|
|||
|
printf("%s\n",p->title.c_str());
|
|||
|
for(auto& str:p->contextline)
|
|||
|
{
|
|||
|
printf("%s\n",str.c_str());
|
|||
|
}
|
|||
|
|
|||
|
printf("\n\n=====================\n");
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
GetUserInput();
|
|||
|
}
|
|||
|
|
|||
|
void EditorEditPage(PageInfo* p)
|
|||
|
{
|
|||
|
while(1)
|
|||
|
{
|
|||
|
|
|||
|
ClearScreen();
|
|||
|
printf("<EFBFBD><EFBFBD>Ŀ - %s - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>\n",projectname.c_str());
|
|||
|
printf("ѡ<EFBFBD><EFBFBD>\n"
|
|||
|
"Q <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>\n"
|
|||
|
"W <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n"
|
|||
|
"E <20><><EFBFBD>Ӱ<EFBFBD>ť\n"
|
|||
|
"A <20>鿴<EFBFBD><E9BFB4>ť<EFBFBD>б<EFBFBD>\n"
|
|||
|
"S ɾ<><C9BE><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>\n"
|
|||
|
"D <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>\n"
|
|||
|
"Z <20><><EFBFBD><EFBFBD>\n"
|
|||
|
);
|
|||
|
switch(GetUserInput())
|
|||
|
{
|
|||
|
CASE_Q:
|
|||
|
EditorSetPageTitle(p);
|
|||
|
break;
|
|||
|
CASE_W:
|
|||
|
EditorSetPageContext(p);
|
|||
|
break;
|
|||
|
CASE_D:
|
|||
|
EditorPagePreview(p);
|
|||
|
break;
|
|||
|
CASE_Z:
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void EditorViewPages()
|
|||
|
{
|
|||
|
while(1)
|
|||
|
{
|
|||
|
ClearScreen();
|
|||
|
printf("======\nҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>\n======\n");
|
|||
|
|
|||
|
size_t sz=pagevec.size();
|
|||
|
for(size_t i=0;i<sz;i++)
|
|||
|
{
|
|||
|
printf("%u ",i);
|
|||
|
if(pagevec.at(i)->title.empty())
|
|||
|
{
|
|||
|
printf("(<28>ޱ<EFBFBD><DEB1><EFBFBD>)\n");
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
printf("%s\n",pagevec.at(i)->title.c_str());
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
printf("-------\n");
|
|||
|
printf("Q ɾ<><C9BE>ҳ<EFBFBD><D2B3> W <20><><EFBFBD><EFBFBD>\n");
|
|||
|
switch(GetUserInput())
|
|||
|
{
|
|||
|
CASE_Q:
|
|||
|
break;
|
|||
|
CASE_W:
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
PageInfo* EditorCreateNewPage()
|
|||
|
{
|
|||
|
PageInfo* pinfo=new PageInfo;
|
|||
|
pagevec.push_back(pinfo);
|
|||
|
return pinfo;
|
|||
|
}
|
|||
|
|
|||
|
void EditorNewProject()
|
|||
|
{
|
|||
|
ClearScreen();
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD>շ<EFBFBD><D5B7><EFBFBD>...\n");
|
|||
|
string name=GetUserLine();
|
|||
|
if(name.empty()) return;
|
|||
|
projectname=name;
|
|||
|
|
|||
|
while(1)
|
|||
|
{
|
|||
|
ClearScreen();
|
|||
|
printf("<EFBFBD><EFBFBD>Ŀ - %s \n",projectname.c_str());
|
|||
|
printf("ѡ<EFBFBD><EFBFBD>\n"
|
|||
|
"Q <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ҳ<EFBFBD><D2B3>\n"
|
|||
|
"W <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>\n"
|
|||
|
"E <20>ر<EFBFBD><D8B1><EFBFBD>Ŀ\n"
|
|||
|
);
|
|||
|
switch(GetUserInput())
|
|||
|
{
|
|||
|
case 'Q':
|
|||
|
case 'q':
|
|||
|
EditorEditPage(EditorCreateNewPage());
|
|||
|
break;
|
|||
|
case 'W':
|
|||
|
case 'w':
|
|||
|
EditorViewPages();
|
|||
|
break;
|
|||
|
case 'E':
|
|||
|
case 'e':
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void EditorMain()
|
|||
|
{
|
|||
|
bool running=true;
|
|||
|
while(running)
|
|||
|
{
|
|||
|
ClearScreen();
|
|||
|
printf("ѡ<EFBFBD><EFBFBD>\n"
|
|||
|
"Q <20>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD>\n"
|
|||
|
"W <20>˳<EFBFBD>Editor\n"
|
|||
|
);
|
|||
|
char c=GetUserInput();
|
|||
|
switch(c)
|
|||
|
{
|
|||
|
case 'Q':
|
|||
|
case 'q':
|
|||
|
EditorNewProject();
|
|||
|
break;
|
|||
|
case 'W':
|
|||
|
case 'w':
|
|||
|
running=false;
|
|||
|
break;
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
int main()
|
|||
|
{
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ConsoleUI Editor...\n");
|
|||
|
EditorMain();
|
|||
|
printf("<EFBFBD>ر<EFBFBD>ConsoleUI Editor...\n");
|
|||
|
return 0;
|
|||
|
}
|