diff --git a/tools/supported/attachtest.cpp b/tools/supported/attachtest.cpp index 83cf426a0..e1b1bc639 100644 --- a/tools/supported/attachtest.cpp +++ b/tools/supported/attachtest.cpp @@ -7,9 +7,11 @@ #include using namespace std; #include +#include "termutil.h" int main (void) { + bool temporary_terminal = TemporaryTerminal(); time_t start, end; double time_diff; DFHack::ContextManager DFMgr("Memory.xml"); @@ -23,9 +25,8 @@ int main (void) catch (exception& e) { cerr << e.what() << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } /* @@ -79,10 +80,11 @@ int main (void) DF->Detach(); time_diff = difftime(end, start); cout << "suspend tests done in " << time_diff << " seconds." << endl; - - #ifndef LINUX_BUILD + + if(temporary_terminal) + { cout << "Done. Press any key to continue" << endl; cin.ignore(); - #endif + } return 0; } diff --git a/tools/supported/autodump.cpp b/tools/supported/autodump.cpp index 05f9a5670..bc8d6e16c 100644 --- a/tools/supported/autodump.cpp +++ b/tools/supported/autodump.cpp @@ -11,6 +11,7 @@ using namespace std; #include #include #include // map cache for the win. +#include "termutil.h" using namespace DFHack; using MapExtras::Block; using MapExtras::MapCache; @@ -19,6 +20,7 @@ typedef std::map coordmap; int main (int argc, char * argv[]) { + bool temporary_terminal = TemporaryTerminal(); // Command line options bool destroy = false; if(argc > 1 && strcmp(argv[1],"-d") == 0) @@ -53,9 +55,8 @@ int main (int argc, char * argv[]) catch (exception& e) { cerr << e.what() << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } @@ -67,9 +68,8 @@ int main (int argc, char * argv[]) if(!Maps->Start()) { cerr << "Can't initialize map." << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } MapCache MC (Maps); @@ -84,9 +84,8 @@ int main (int argc, char * argv[]) if (!Gui->getCursorCoords(cx,cy,cz)) { cerr << "Cursor position not found. Please enabled the cursor." << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } pos_cursor = DFCoord(cx,cy,cz); @@ -95,18 +94,16 @@ int main (int argc, char * argv[]) if(!b) { cerr << "Cursor is in an invalid area. Place it over something save first." << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } uint16_t ttype = MC.tiletypeAt(pos_cursor); if(!DFHack::isFloorTerrain(ttype)) { cerr << "Cursor should be placed over a floor." << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } } @@ -209,9 +206,10 @@ int main (int argc, char * argv[]) { cout << "Done. " << dumped_total << " items marked for destruction." << endl; } -#ifndef LINUX_BUILD - cout << "Press any key to continue" << endl; - cin.ignore(); -#endif + if(temporary_terminal) + { + cout << "Press any key to continue" << endl; + cin.ignore(); + } return 0; } \ No newline at end of file diff --git a/tools/supported/cleanmap.cpp b/tools/supported/cleanmap.cpp index 095f8eaee..0c095afa0 100644 --- a/tools/supported/cleanmap.cpp +++ b/tools/supported/cleanmap.cpp @@ -7,10 +7,11 @@ using namespace std; #include +#include "termutil.h" int main (int argc, char** argv) { - + bool temporary_terminal = TemporaryTerminal(); bool quiet = false; for(int i = 1; i < argc; i++) { @@ -33,9 +34,8 @@ int main (int argc, char** argv) catch (exception& e) { cerr << e.what() << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } DFHack::Maps *Mapz = DF->getMaps(); @@ -44,9 +44,8 @@ int main (int argc, char** argv) if(!Mapz->Start()) { cerr << "Can't init map." << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } @@ -91,12 +90,10 @@ int main (int argc, char** argv) } } DF->Detach(); - #ifndef LINUX_BUILD - if (!quiet) - { - cout << "Done. Press any key to continue" << endl; - cin.ignore(); - } - #endif + if (!quiet && temporary_terminal) + { + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + } return 0; } diff --git a/tools/supported/cleanowned.cpp b/tools/supported/cleanowned.cpp index d26ae5c99..5740d7ed8 100644 --- a/tools/supported/cleanowned.cpp +++ b/tools/supported/cleanowned.cpp @@ -13,9 +13,11 @@ using namespace std; #include #include #include +#include "termutil.h" int main (int argc, char *argv[]) { + bool temporary_terminal = TemporaryTerminal(); bool dump_scattered = false; bool confiscate_all = false; bool dry_run = false; @@ -60,9 +62,8 @@ int main (int argc, char *argv[]) catch (exception& e) { cerr << e.what() << endl; -#ifndef LINUX_BUILD - cin.ignore(); -#endif + if(temporary_terminal) + cin.ignore(); return 1; } @@ -175,10 +176,10 @@ int main (int argc, char *argv[]) */ } } - -#ifndef LINUX_BUILD - cout << "Done. Press any key to continue" << endl; - cin.ignore(); -#endif + if(temporary_terminal) + { + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + } return 0; } diff --git a/tools/supported/cleartask.cpp b/tools/supported/cleartask.cpp index da9bd6119..d6ef80f37 100644 --- a/tools/supported/cleartask.cpp +++ b/tools/supported/cleartask.cpp @@ -11,9 +11,11 @@ using namespace std; #include #include #include +#include "termutil.h" int main () { + bool temporary_terminal = TemporaryTerminal(); DFHack::Process * p; unsigned int i; DFHack::ContextManager DFMgr("Memory.xml"); @@ -27,9 +29,8 @@ int main () catch (exception& e) { cerr << e.what() << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } @@ -44,9 +45,8 @@ int main () catch(DFHack::Error::All & e) { cerr << "Fatal error, exiting :(" << endl << e.what() << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } @@ -68,9 +68,10 @@ int main () } cout << "Found and untasked " << numtasked << " items." << endl; -#ifndef LINUX_BUILD - cout << "Done. Press any key to continue" << endl; - cin.ignore(); -#endif + if(temporary_terminal) + { + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + } return 0; } diff --git a/tools/supported/deramp.cpp b/tools/supported/deramp.cpp index 2619a03c8..e112ac90c 100644 --- a/tools/supported/deramp.cpp +++ b/tools/supported/deramp.cpp @@ -10,10 +10,11 @@ using namespace std; #include #include - +#include "termutil.h" int main (void) { + bool temporary_terminal = TemporaryTerminal(); uint32_t x_max,y_max,z_max; uint32_t num_blocks = 0; uint32_t bytes_read = 0; @@ -42,9 +43,8 @@ int main (void) catch (exception& e) { cerr << e.what() << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } DFHack::Maps *Mapz = DF->getMaps(); @@ -53,9 +53,8 @@ int main (void) if (!Mapz->Start()) { cerr << "Can't init map." << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } @@ -138,9 +137,10 @@ int main (void) DF->Detach(); cout << "Found and changed " << count << " tiles." << endl; cout << "Fixed " << countbad << " bad down ramps." << endl; -#ifndef LINUX_BUILD - cout << "Done. Press any key to continue" << endl; - cin.ignore(); -#endif + if(temporary_terminal) + { + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + } return 0; } diff --git a/tools/supported/dftubefill.cpp b/tools/supported/dftubefill.cpp index 89bc51d04..14a39e736 100644 --- a/tools/supported/dftubefill.cpp +++ b/tools/supported/dftubefill.cpp @@ -10,10 +10,11 @@ using namespace std; #include #include - +#include "termutil.h" int main (void) { + bool temporary_terminal = TemporaryTerminal(); uint32_t x_max,y_max,z_max; DFHack::designations40d designations; DFHack::tiletypes40d tiles; @@ -35,9 +36,8 @@ int main (void) catch (exception& e) { cerr << e.what() << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } DFHack::Maps *Mapz = DF->getMaps(); @@ -46,9 +46,8 @@ int main (void) if (!Mapz->Start()) { cerr << "Can't init map." << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } @@ -56,9 +55,8 @@ int main (void) if(!Mapz->StartFeatures()) { cerr << "Can't get features." << endl; - #ifndef LINUX_BUILD - cin.ignore(); - #endif + if(temporary_terminal) + cin.ignore(); return 1; } @@ -114,9 +112,10 @@ int main (void) } DF->Detach(); cout << "Found and changed " << count << " tiles." << endl; -#ifndef LINUX_BUILD - cout << "Done. Press any key to continue" << endl; - cin.ignore(); -#endif + if(temporary_terminal) + { + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + } return 0; } diff --git a/tools/supported/dumpoffsets.cpp b/tools/supported/dumpoffsets.cpp index be5861bf1..bcd4be91a 100644 --- a/tools/supported/dumpoffsets.cpp +++ b/tools/supported/dumpoffsets.cpp @@ -10,9 +10,11 @@ using namespace std; #include #include using namespace DFHack; +#include "termutil.h" int main (int numargs, const char ** args) { + bool temporary_terminal = TemporaryTerminal(); /* DFHack::VersionInfoFactory * VIF = new DFHack::VersionInfoFactory("Memory.xml"); for(int i = 0; i < VIF->versions.size(); i++) @@ -29,16 +31,16 @@ int main (int numargs, const char ** args) catch (exception& e) { cerr << e.what() << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } cout << DF->getMemoryInfo()->PrintOffsets(); - #ifndef LINUX_BUILD + if(temporary_terminal) + { cout << "Done. Press any key to continue" << endl; cin.ignore(); - #endif + } //delete VIF; return 0; } diff --git a/tools/supported/expbench.cpp b/tools/supported/expbench.cpp index 9141e83f3..bc7644fd4 100644 --- a/tools/supported/expbench.cpp +++ b/tools/supported/expbench.cpp @@ -9,7 +9,7 @@ using namespace std; #include - +#include "termutil.h" void print_progress (int current, int total) { if(total < 100) @@ -29,10 +29,10 @@ void print_progress (int current, int total) int main (int numargs, char** args) { + bool temporary_terminal = TemporaryTerminal(); time_t start, end; double time_diff; - - + unsigned int iterations = 0; if (numargs == 2) { @@ -41,7 +41,7 @@ int main (int numargs, char** args) } if(iterations == 0) iterations = 1000; - + uint32_t x_max,y_max,z_max; uint32_t num_blocks = 0; uint64_t bytes_read = 0; @@ -58,19 +58,17 @@ int main (int numargs, char** args) catch (exception& e) { cerr << e.what() << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } - + time(&start); - + cout << "doing " << iterations << " iterations" << endl; for(uint32_t i = 0; i< iterations;i++) { print_progress (i, iterations); - if(!Maps->Start()) break; Maps->getSize(x_max,y_max,z_max); @@ -97,9 +95,10 @@ int main (int numargs, char** args) cout << num_blocks << " blocks read" << endl; cout << bytes_read / (1024 * 1024) << " MB" << endl; cout << "map export tests done in " << time_diff << " seconds." << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) + { cout << "Done. Press any key to continue" << endl; cin.ignore(); - #endif + } return 0; } diff --git a/tools/supported/flows.cpp b/tools/supported/flows.cpp index 989cae319..f07496b55 100644 --- a/tools/supported/flows.cpp +++ b/tools/supported/flows.cpp @@ -5,12 +5,13 @@ using namespace std; #include - +#include "termutil.h" int main (void) { + bool temporary_terminal = TemporaryTerminal(); uint32_t x_max,y_max,z_max; DFHack::designations40d designations; - + DFHack::ContextManager DFMgr("Memory.xml"); DFHack::Context * DF; DFHack::Maps *Maps; @@ -23,18 +24,16 @@ int main (void) catch (exception& e) { cerr << e.what() << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } // init the map if(!Maps->Start()) { cerr << "Can't init map." << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } DFHack::t_blockflags bflags; @@ -76,8 +75,7 @@ int main (void) cout << "Magma tiles: " << magma << endl; cout << endl << "Done." << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 0; } diff --git a/tools/supported/forcepause.cpp b/tools/supported/forcepause.cpp index c038690e6..b2dcf62ce 100644 --- a/tools/supported/forcepause.cpp +++ b/tools/supported/forcepause.cpp @@ -7,9 +7,11 @@ using namespace std; #include #include +#include "termutil.h" int main (int argc, char** argv) { + bool temporary_terminal = TemporaryTerminal(); bool quiet = false; for(int i = 1; i < argc; i++) { @@ -30,9 +32,8 @@ int main (int argc, char** argv) catch (exception& e) { cerr << e.what() << endl; - #ifndef LINUX_BUILD - if(!quiet) cin.ignore(); - #endif + if(!quiet && temporary_terminal) + cin.ignore(); return 1; } @@ -41,9 +42,8 @@ int main (int argc, char** argv) World->SetPauseState(true); DF->Resume(); - #ifndef LINUX_BUILD - cout << "Done. The current game frame will have to finish first. This can take some time on bugged maps." << endl; - if (!quiet) cin.ignore(); - #endif + cout << "Done. The current game frame will have to finish first. This can take some time on bugged maps." << endl; + if(!quiet && temporary_terminal) + cin.ignore(); return 0; } diff --git a/tools/supported/lair.cpp b/tools/supported/lair.cpp index 592ec977b..ae4974321 100644 --- a/tools/supported/lair.cpp +++ b/tools/supported/lair.cpp @@ -5,14 +5,13 @@ #include using namespace std; #include -//#include -//#include +#include "termutil.h" int main (void) { + bool temporary_terminal = TemporaryTerminal(); uint32_t x_max,y_max,z_max; DFHack::occupancies40d occupancies; - //DFHack::tiletypes40d tiles; DFHack::ContextManager DFMgr("Memory.xml"); DFHack::Context *DF; @@ -24,9 +23,8 @@ int main (void) catch (exception& e) { cerr << e.what() << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } @@ -36,9 +34,8 @@ int main (void) if(!Maps->Start()) { cerr << "Can't init map." << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } @@ -68,9 +65,10 @@ int main (void) } } } - #ifndef LINUX_BUILD - cout << "The map has been marked as a creature lair. Items shouldn't scatter." << endl; - cin.ignore(); - #endif + if(temporary_terminal) + { + cout << "The map has been marked as a creature lair. Items shouldn't scatter." << endl; + cin.ignore(); + } return 0; } diff --git a/tools/supported/liquids.cpp b/tools/supported/liquids.cpp index 0be65e031..67ed9a9ed 100644 --- a/tools/supported/liquids.cpp +++ b/tools/supported/liquids.cpp @@ -9,6 +9,8 @@ using namespace std; #include using namespace MapExtras; +#include "termutil.h" + typedef vector coord_vec; class Brush @@ -130,6 +132,7 @@ public: int main (int argc, char** argv) { + bool temporary_terminal = TemporaryTerminal(); bool quiet = false; for(int i = 1; i < argc; i++) { @@ -140,11 +143,7 @@ int main (int argc, char** argv) } } int32_t x,y,z; - /* - DFHack::designations40d designations; - DFHack::tiletypes40d tiles; - DFHack::t_temperatures temp1,temp2; - */ + uint32_t x_max,y_max,z_max; DFHack::ContextManager DFMgr("Memory.xml"); @@ -165,9 +164,8 @@ int main (int argc, char** argv) catch (exception& e) { cerr << e.what() << endl; - #ifndef LINUX_BUILD - cin.ignore(); - #endif + if(temporary_terminal) + cin.ignore(); return 1; } bool end = false; @@ -496,12 +494,10 @@ int main (int argc, char** argv) } } DF->Detach(); - #ifndef LINUX_BUILD - if(!quiet) + if(temporary_terminal && !quiet) { cout << "Done. Press any key to continue" << endl; cin.ignore(); } - #endif return 0; } diff --git a/tools/supported/position.cpp b/tools/supported/position.cpp index d5d088670..5b0367e7b 100644 --- a/tools/supported/position.cpp +++ b/tools/supported/position.cpp @@ -7,7 +7,7 @@ using namespace std; #include - +#include "termutil.h" std::ostream &operator<<(std::ostream &stream, DFHack::t_gamemodes funzies) { const char * gm[]= @@ -37,6 +37,7 @@ std::ostream &operator<<(std::ostream &stream, DFHack::t_gamemodes funzies) int main (int argc, char** argv) { + bool temporary_terminal = TemporaryTerminal(); bool quiet = false; for(int i = 1; i < argc; i++) { @@ -65,9 +66,8 @@ int main (int argc, char** argv) catch (exception& e) { cerr << e.what() << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } DFHack::t_gamemodes gmm; @@ -117,12 +117,10 @@ int main (int argc, char** argv) cerr << "Can't detach from DF" << endl; } - #ifndef LINUX_BUILD - if(!quiet) - { - cout << "Done. Press any key to continue" << endl; - cin.ignore(); - } - #endif + if(!quiet && temporary_terminal) + { + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + } return 0; } diff --git a/tools/supported/probe.cpp b/tools/supported/probe.cpp index 167f9398d..a4483fbe5 100644 --- a/tools/supported/probe.cpp +++ b/tools/supported/probe.cpp @@ -13,16 +13,16 @@ using namespace std; #define DFHACK_WANT_TILETYPES 1 #include #include +#include "termutil.h" using namespace DFHack; int main (int numargs, const char ** args) { + bool temporary_terminal = TemporaryTerminal(); DFHack::ContextManager DFMgr("Memory.xml"); DFHack::Context *DF = DFMgr.getSingleContext(); - #ifndef LINUX_BUILD - BEGIN_PROBE: - #endif + BEGIN_PROBE: try { DF->Attach(); @@ -30,9 +30,8 @@ int main (int numargs, const char ** args) catch (std::exception& e) { std::cerr << e.what() << std::endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } @@ -206,10 +205,11 @@ int main (int numargs, const char ** args) } } DF->Detach(); - #ifndef LINUX_BUILD + if(temporary_terminal) + { std::cout << "Press any key to refresh..." << std::endl; cin.ignore(); goto BEGIN_PROBE; - #endif + } return 0; } diff --git a/tools/supported/reveal.cpp b/tools/supported/reveal.cpp index 38c431ab0..125cb1522 100644 --- a/tools/supported/reveal.cpp +++ b/tools/supported/reveal.cpp @@ -21,6 +21,7 @@ void waitmsec (int delay) Sleep(delay); } #endif +#include "termutil.h" struct hideblock { @@ -32,9 +33,9 @@ struct hideblock int main (void) { + bool temporary_terminal = TemporaryTerminal(); uint32_t x_max,y_max,z_max; DFHack::designations40d designations; - DFHack::ContextManager DFMgr("Memory.xml"); DFHack::Context *DF; try @@ -45,12 +46,10 @@ int main (void) catch (exception& e) { cerr << e.what() << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } - DFHack::Maps *Maps =DF->getMaps(); DFHack::World *World =DF->getWorld(); // walk the map, save the hide bits, reveal. @@ -69,9 +68,8 @@ int main (void) if(!Maps->Start()) { cerr << "Can't init map." << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } @@ -129,9 +127,10 @@ int main (void) } Maps->WriteDesignations(hb.x,hb.y,hb.z, &designations); } - #ifndef LINUX_BUILD - cout << "Done. Press any key to continue" << endl; - cin.ignore(); - #endif + if(temporary_terminal) + { + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + } return 0; } diff --git a/tools/supported/suspendtest.cpp b/tools/supported/suspendtest.cpp index ea29de7eb..5dd58fa9f 100644 --- a/tools/supported/suspendtest.cpp +++ b/tools/supported/suspendtest.cpp @@ -8,8 +8,11 @@ using namespace std; #include +#include "termutil.h" + int main (void) { + bool temporary_terminal = TemporaryTerminal(); string blah; DFHack::ContextManager DFMgr("Memory.xml"); DFHack::Context * DF; @@ -21,9 +24,8 @@ int main (void) catch (exception& e) { cerr << e.what() << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } cout << "Attached, DF should be suspended now" << endl; @@ -48,10 +50,12 @@ int main (void) if(!DF->Detach()) { cerr << "Can't detach from DF" << endl; + if(temporary_terminal) + cin.ignore(); return 1; } cout << "Detached, DF should be running again" << endl; - getline(cin, blah); - + if(temporary_terminal) + getline(cin, blah); return 0; } diff --git a/tools/supported/termutil.h b/tools/supported/termutil.h new file mode 100644 index 000000000..2055152f1 --- /dev/null +++ b/tools/supported/termutil.h @@ -0,0 +1,29 @@ +#ifndef TERMUTIL_H +#define TERMUTIL_H + +#ifdef LINUX_BUILD +// FIXME: is this ever false? +bool TemporaryTerminal () +{ + return false; +} +#else +#include +#include +#include +bool TemporaryTerminal () +{ + CONSOLE_SCREEN_BUFFER_INFO csbi; + HANDLE hStdOutput; + hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); + if (!GetConsoleScreenBufferInfo(hStdOutput, &csbi)) + { + printf("GetConsoleScreenBufferInfo failed: %d\n", GetLastError()); + return false; + } + return ((!csbi.dwCursorPosition.X) && (!csbi.dwCursorPosition.Y)); +}; + +#endif // LINUX_BUILD + +#endif \ No newline at end of file diff --git a/tools/supported/tiletypes.cpp b/tools/supported/tiletypes.cpp index 2b7cc0047..c3fa87c67 100644 --- a/tools/supported/tiletypes.cpp +++ b/tools/supported/tiletypes.cpp @@ -9,6 +9,7 @@ using namespace std; #include #include +#include "termutil.h" void tolower(std::string &str) { @@ -389,6 +390,7 @@ public: int main(int argc, char *argv[]) { + bool temporary_terminal = TemporaryTerminal(); uint32_t x_max = 0, y_max = 0, z_max = 0; int32_t x = 0, y = 0, z = 0; DFHack::ContextManager manager("Memory.xml"); @@ -397,9 +399,8 @@ int main(int argc, char *argv[]) if (!context->Attach()) { std::cerr << "Unable to attach to DF!" << std::endl; - #ifndef LINUX_BUILD - std::cin.ignore(); - #endif + if(temporary_terminal) + std::cin.ignore(); return 1; } @@ -513,9 +514,8 @@ int main(int argc, char *argv[]) { std::cerr << "Cannot get map info!" << std::endl; context->Detach(); - #ifndef LINUX_BUILD - std::cin.ignore(); - #endif + if(temporary_terminal) + std::cin.ignore(); return 1; } maps->getSize(x_max, y_max, z_max); @@ -587,10 +587,11 @@ int main(int argc, char *argv[]) } context->Detach(); - #ifndef LINUX_BUILD - std::cout << "Press any key to finish."; - std::cin.ignore(); - #endif + if(temporary_terminal) + { + std::cout << "Press any key to finish."; + std::cin.ignore(); + } std::cout << std::endl; return 0; } diff --git a/tools/supported/unreveal.cpp b/tools/supported/unreveal.cpp index af98beb87..33e20a2cd 100644 --- a/tools/supported/unreveal.cpp +++ b/tools/supported/unreveal.cpp @@ -12,9 +12,11 @@ using namespace std; #include using namespace MapExtras; using namespace DFHack; +#include "termutil.h" int main (int argc, char* argv[]) { + bool temporary_terminal = TemporaryTerminal(); ContextManager DFMgr("Memory.xml"); Context * DF; try @@ -25,9 +27,8 @@ int main (int argc, char* argv[]) catch (exception& e) { cerr << e.what() << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } @@ -40,9 +41,8 @@ int main (int argc, char* argv[]) { cerr << "Can't init map. Make sure you have a map loaded in DF." << endl; DF->Detach(); - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } @@ -55,9 +55,8 @@ int main (int argc, char* argv[]) if(cx == -30000) { cerr << "Cursor is not active. Point the cursor at some empty space you want to be unhidden." << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz); @@ -66,9 +65,8 @@ int main (int argc, char* argv[]) if(isWallTerrain(tt)) { cerr << "Point the cursor at some empty space you want to be unhidden." << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } // hide all tiles, flush cache @@ -194,10 +192,11 @@ int main (int argc, char* argv[]) MCache->WriteAll(); delete MCache; DF->Detach(); - #ifndef LINUX_BUILD + if(temporary_terminal) + { cout << "Done. Press any key to continue" << endl; cin.ignore(); - #endif + } return 0; } diff --git a/tools/supported/unstuck.cpp b/tools/supported/unstuck.cpp index 2a74c3f0f..93d6f3efc 100644 --- a/tools/supported/unstuck.cpp +++ b/tools/supported/unstuck.cpp @@ -8,8 +8,10 @@ using namespace std; #include +#include "termutil.h" int main (void) { + bool temporary_terminal = TemporaryTerminal(); string blah; DFHack::ContextManager DFMgr("Memory.xml"); DFHack::Context *DF; @@ -21,9 +23,8 @@ int main (void) catch (exception& e) { cerr << e.what() << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } diff --git a/tools/supported/vdig.cpp b/tools/supported/vdig.cpp index 3f2255fdd..f415508e2 100644 --- a/tools/supported/vdig.cpp +++ b/tools/supported/vdig.cpp @@ -10,10 +10,12 @@ using namespace std; #include #include +#include "termutil.h" using namespace MapExtras; int main (int argc, char* argv[]) { + bool temporary_terminal = TemporaryTerminal(); // Command line options bool updown = false; if(argc > 1 && strcmp(argv[1],"-x") == 0) @@ -29,9 +31,8 @@ int main (int argc, char* argv[]) catch (exception& e) { cerr << e.what() << endl; - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } @@ -44,9 +45,8 @@ int main (int argc, char* argv[]) { cerr << "Can't init map. Make sure you have a map loaded in DF." << endl; DF->Detach(); - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } @@ -69,9 +69,8 @@ int main (int argc, char* argv[]) { cerr << "I won't dig the borders. That would be cheating!" << endl; DF->Detach(); - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } MapCache * MCache = new MapCache(Maps); @@ -85,9 +84,8 @@ int main (int argc, char* argv[]) cerr << "This tile is non-vein. Bye :)" << endl; delete MCache; DF->Detach(); - #ifndef LINUX_BUILD + if(temporary_terminal) cin.ignore(); - #endif return 1; } printf("%d/%d/%d tiletype: %d, veinmat: %d, designation: 0x%x ... DIGGING!\n", cx,cy,cz, tt, veinmat, des.whole); @@ -200,10 +198,11 @@ int main (int argc, char* argv[]) MCache->WriteAll(); delete MCache; DF->Detach(); - #ifndef LINUX_BUILD + if(temporary_terminal) + { cout << "Done. Press any key to continue" << endl; cin.ignore(); - #endif + } return 0; }