A thread function... for the interactive console.
| 961 | |
| 962 | // A thread function... for the interactive console. |
| 963 | static void fIOthread(IODATA * iod) |
| 964 | { |
| 965 | static const std::filesystem::path HISTORY_FILE = getConfigPath() / "dfhack.history"; |
| 966 | |
| 967 | Core * core = iod->core; |
| 968 | PluginManager * plug_mgr = iod->plug_mgr; |
| 969 | |
| 970 | CommandHistory main_history; |
| 971 | main_history.load(HISTORY_FILE.c_str()); |
| 972 | |
| 973 | Console & con = core->getConsole(); |
| 974 | if (plug_mgr == nullptr) |
| 975 | { |
| 976 | con.printerr("Something horrible happened in Core's constructor...\n"); |
| 977 | return; |
| 978 | } |
| 979 | |
| 980 | run_dfhack_init(con, core); |
| 981 | |
| 982 | con.print("DFHack is ready. Have a nice day!\n" |
| 983 | "DFHack version {}\n" |
| 984 | "Type in '?' or 'help' for general help, 'ls' to see all commands.\n", |
| 985 | dfhack_version_desc()); |
| 986 | |
| 987 | int clueless_counter = 0; |
| 988 | |
| 989 | if (getenv("DFHACK_DISABLE_CONSOLE")) |
| 990 | return; |
| 991 | |
| 992 | while (true) |
| 993 | { |
| 994 | std::string command; |
| 995 | int ret; |
| 996 | while ((ret = con.lineedit("[DFHack]# ",command, main_history)) |
| 997 | == Console::RETRY); |
| 998 | if(ret == Console::SHUTDOWN) |
| 999 | { |
| 1000 | std::cerr << "Console is shutting down properly." << std::endl; |
| 1001 | return; |
| 1002 | } |
| 1003 | else if(ret == Console::FAILURE) |
| 1004 | { |
| 1005 | std::cerr << "Console caught an unspecified error." << std::endl; |
| 1006 | continue; |
| 1007 | } |
| 1008 | else if(ret) |
| 1009 | { |
| 1010 | // a proper, non-empty command was entered |
| 1011 | main_history.add(command); |
| 1012 | main_history.save(HISTORY_FILE); |
| 1013 | } |
| 1014 | |
| 1015 | auto rv = core->runCommand(con, command); |
| 1016 | |
| 1017 | if (rv == CR_NOT_IMPLEMENTED) |
| 1018 | clueless_counter++; |
| 1019 | |
| 1020 | if(clueless_counter == 3) |
nothing calls this directly
no test coverage detected