From cd21033196e06b9d3b8e06f6fd0b6597c4cf592f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=A6=E5=87=8C=E6=B1=90?= Date: Fri, 20 Dec 2024 16:35:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86=E9=80=80=E5=87=BA?= =?UTF-8?q?=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 097a352..a025122 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,7 +45,7 @@ int main(int argc, char* argv[]) { } file.close(); content = content.substr(0, content.size() - 1); // remove last newline - infoBar.setText(RichText("File loaded: " + std::to_string(content.size()) + " characters. Press 'i' to enter insert mode, 'm' for menu.", COLOR_GREEN)); + infoBar.setText(RichText("File loaded: " + std::to_string(content.size()) + " characters. Press 'i' to enter insert mode.", COLOR_GREEN)); mainEditor.setRuleName(getRuleByFileName(argv[1])); mainEditor.setContent(content, true); @@ -67,9 +67,9 @@ int main(int argc, char* argv[]) { if(opt == 27) { mainEditor.setFocus(false); if(mainEditor.isChanged()) { - infoBar.setText(RichText("[MODIFIED] ", COLOR_YELLOW) + RichText(std::to_string(mainEditor.getContent().size()) + " characters. Press 'i' to enter insert mode, 'm' for menu.")); + infoBar.setText(RichText("[MODIFIED] ", COLOR_YELLOW) + RichText(std::to_string(mainEditor.getContent().size()) + " characters. Press 'i' to enter insert mode.")); } else { - infoBar.setText(RichText(std::to_string(mainEditor.getContent().size()) + " characters. Press 'i' to enter insert mode, 'm' for menu.")); + infoBar.setText(RichText(std::to_string(mainEditor.getContent().size()) + " characters. Press 'i' to enter insert mode.")); } } else { mainEditor.onKeyPress(opt); @@ -91,8 +91,6 @@ int main(int argc, char* argv[]) { mainEditor.moveViewLeft(); } else if(opt == 256 + 77) { mainEditor.moveViewRight(); - } else if(opt == 'm') { - //TODO: menu } else if(opt == 27) { if(mainEditor.isChanged()) { infoBar.setText(RichText("[MODIFIED] ", COLOR_YELLOW) + RichText("Exiting...")); @@ -128,7 +126,37 @@ int main(int argc, char* argv[]) { infoBar.setText(RichText("Exiting...", COLOR_GREEN)); return 0; } else if(menu.getChoice() == "cancel") { - infoBar.setText(RichText("[MODIFIED] ", COLOR_YELLOW) + RichText("Canceled. Press 'i' to enter insert mode, 'm' for menu.")); + infoBar.setText(RichText("[MODIFIED] ", COLOR_YELLOW) + RichText("Canceled. Press 'i' to enter insert mode.")); + } + infoBar.draw(); + } else { + infoBar.setText(RichText("Exiting...")); + infoBar.draw(); + MyVector ops; + ops.push_back(MenuOption("confirm", "Yes")); + ops.push_back(MenuOption("cancel", "Cancel")); + Menu menu = Menu(-1, -1, std::string("Are you sure to exit?"), ops, 1); + menu.draw(); + menu.setFocus(true); + while(menu.getChoice() == "") { + if(_kbhit()) { + int scan = _getch(), opt; + if(scan == 224) { + opt = _getch() + 256; + } else if(scan == 26 || scan == 25) { + opt = scan + 512; + } else { + opt = scan; + } + menu.onKeyPress(opt); + menu.draw(); + } + } + if(menu.getChoice() == "confirm") { + infoBar.setText(RichText("Exiting...", COLOR_GREEN)); + return 0; + } else if(menu.getChoice() == "cancel") { + infoBar.setText(RichText("Canceled. Press 'i' to enter insert mode.")); } infoBar.draw(); }