void MainWindow::on_button_enter() { std::thread( [this](int dummy) { std::string query = m_entry.get_text(); m_entry.set_sensitive(false); m_entry.set_text("計算中です..."); CrTrimString(query); auto result = ChJustDoIt(query); ChFixResultForDisplay(result); std::string contents("にゅうりょく:"); contents += query; contents += '\n'; contents += result; contents += '\n'; add_output(contents); if (result.find("しゅうりょうします") != std::string::npos) { m_entry.set_text("終了中です..."); hide(); } m_entry.set_text(""); m_entry.set_sensitive(true); set_focus(m_entry); }, 0 ).detach(); }
int main(int argc, char **argv) { std::string query; // interactive mode if (argc <= 1) { ChShowVersion(); std::cerr << "「exit」か「おわる」でしゅうりょうできます。" << std::endl << std::endl; for (;;) { std::cout << "にゅうりょく:"; if (!std::getline(std::cin, query)) break; std::string result = ChJustDoIt(query); std::cout << result << std::endl; if (result.find("しゅうりょうします") != std::string::npos) break; } return 0; } // one-liner mode if (argc == 3 && (strcmp(argv[1], "-e") == 0 || strcmp(argv[1], "-E") == 0)) { query = argv[2]; std::string result = ChJustDoIt(query); std::cout << result << std::endl; return 0; } // show help if (argc == 2 && (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "--HELP") == 0 || strcmp(argv[1], "/?") == 0)) { ChShowHelp(); return 0; } // show version if (argc == 2 && (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "--VERSION") == 0 || strcmp(argv[1], "-V") == 0)) { ChShowVersion(); return 0; } if (argc != 2) { std::cout << "エラー:引数の指定が間違っています。" << std::endl; ChShowHelp(); return 1; } // file input mode std::fstream fin(argv[1], std::ios_base::in); if (fin.is_open()) { for (;;) { if (!std::getline(fin, query)) break; std::string input = query; std::string result = ChJustDoIt(query); if (!result.empty()) { std::cout << "にゅうりょく:" << input << std::endl; std::cout << result << std::endl; } if (result.find("しゅうりょうします") != std::string::npos) break; } } else { std::cerr << "ファイル「" << argv[1] << "」が開けませんでした。" << std::endl; } return 0; }