From 99ba998dd2bb2fc29a1f52b408dc6117907cfe6f Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Thu, 13 Apr 2017 15:09:04 +0800 Subject: [PATCH] Initial commit --- main.cpp | 266 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ readme.md | 2 + 2 files changed, 268 insertions(+) create mode 100644 main.cpp create mode 100644 readme.md diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..b546bb6 --- /dev/null +++ b/main.cpp @@ -0,0 +1,266 @@ +#include +#include +#include +#include +#include +#include +#include +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 contextline; +}; + +vector 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("请输入新的标题...\n"); + string newtitle=GetUserLine(); + if(newtitle.empty()) + { + printf("你输入了空内容,这表明:\n" + "Q 清空标题\n" + "W 不改变标题\n"); + switch(GetUserInput()) + { +CASE_Q: + p->title.clear(); + break; +CASE_W: + return; + } + } + else + { + p->title=newtitle; + } +} + +void EditorSetPageContext(PageInfo* p) +{ + ClearScreen(); + printf("请输入页面内容,将#放在单独一行表示输入结束.\n"); + vector newcontextline; + string temp; + while(1) + { + temp=GetUserLine(); + if(temp.size()==1&&temp.at(0)=='#') break; + newcontextline.push_back(temp); + } + if(newcontextline.empty()) + { + printf("你输入了空内容,这表明:\n" + "Q 清空内容\n" + "W 不改变内容\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("按下任意键返回\n"); + GetUserInput(); +} + +void EditorEditPage(PageInfo* p) +{ + while(1) + { + + ClearScreen(); + printf("项目 - %s - 创建新页面\n",projectname.c_str()); + printf("选项\n" + "Q 设置标题\n" + "W 设置内容\n" + "E 添加按钮\n" + "A 查看按钮列表\n" + "S 删除此页面\n" + "D 浏览此页面\n" + "Z 返回\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页面序号 标题\n======\n"); + + size_t sz=pagevec.size(); + for(size_t i=0;ititle.empty()) + { + printf("(无标题)\n"); + } + else + { + printf("%s\n",pagevec.at(i)->title.c_str()); + } + } + + printf("-------\n"); + printf("Q 删除页面 W 返回\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("请输入项目标题,留空返回...\n"); + string name=GetUserLine(); + if(name.empty()) return; + projectname=name; + + while(1) + { + ClearScreen(); + printf("项目 - %s \n",projectname.c_str()); + printf("选项\n" + "Q 创建新的页面\n" + "W 浏览已有页面\n" + "E 关闭项目\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("选项\n" + "Q 新建工程\n" + "W 退出Editor\n" + ); + char c=GetUserInput(); + switch(c) + { + case 'Q': + case 'q': + EditorNewProject(); + break; + case 'W': + case 'w': + running=false; + break; + + } + } +} + +int main() +{ + printf("启动ConsoleUI Editor...\n"); + EditorMain(); + printf("关闭ConsoleUI Editor...\n"); + return 0; +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..a52aea6 --- /dev/null +++ b/readme.md @@ -0,0 +1,2 @@ +# ConsoleUI Editor +涓篊onsoleUI缂栧啓鐨勭紪杈戝櫒,杩愯涓庡懡浠よ涓.