From c1c4e74666a5f145889e9a6c610b55a1952877a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabricio=20Fern=C3=A1ndez?= Date: Fri, 13 Sep 2024 14:53:11 -0300 Subject: [PATCH] correction in terminal outputs --- src/Output.cpp | 40 ++++++------ tests/console-terminal/console-test.json | 78 ++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 20 deletions(-) create mode 100644 tests/console-terminal/console-test.json diff --git a/src/Output.cpp b/src/Output.cpp index 32f2a29..b941c4f 100644 --- a/src/Output.cpp +++ b/src/Output.cpp @@ -11,6 +11,7 @@ #if defined (_WIN64) || defined(_WIN32) #include +#include #endif #include "Output.h" @@ -520,13 +521,14 @@ namespace Output{ serieFile <<"\t\n"; serieFile <<"\n"; } - - void moveCursor(int row, int col) { - std::cout << "\033[" << row << ";" << col << "H"; - } void clearScreen() { - std::cout << "\033[2J\033[1;1H"; + + #ifdef _WIN32 + system("cls"); + #else + std::cout << "\033[2J\033[1;1H" << std::flush; // Clear screen for Unix systems + #endif } void showProgressBar(double progress, int width = 47) { @@ -543,8 +545,6 @@ namespace Output{ void welcomeScreen() { - clearScreen(); - // common format int width = 55; @@ -567,7 +567,6 @@ namespace Output{ } void farewellScreen() { - int width = 55; string hLines(width,'-'); cout<<"\n"<* bodies, double itime) { + clearScreen(); + + welcomeScreen(); + // get total kinetic energy double ienergy = DynamicRelaxation::computeKineticEnergy(bodies); @@ -583,21 +586,20 @@ namespace Output{ auto hours = std::chrono::duration_cast(elapsed_seconds); auto minutes = std::chrono::duration_cast(elapsed_seconds) - hours; double seconds = elapsed_seconds.count() - (hours.count() * 3600 + minutes.count() * 60); - - // move cursor to write header - moveCursor(9, 1); - std::cout << "Time : " << std::setw(8) << std::fixed << std::setprecision(6) << itime << " s" << std::endl; - std::cout << "Energy : " << std::setw(8) << std::fixed << std::setprecision(2) << ienergy << " J" << std::endl; + + std::cout << "Time : " << std::setw(8) << std::fixed << std::setprecision(4) << itime << "s" << std::endl; + std::cout << "Energy : " << std::setw(8) << std::scientific << std::setprecision(2) << ienergy << "J" << std::endl; std::cout << "Particles : " << Particle::getTotalParticles() << std::endl; std::cout << "Threads : " << ModelSetup::getThreads() << std::endl; - std::cout << "Time Step : " << ModelSetup::getTimeStep() << " s" << std::endl; - std::cout << "Elapsed time : "<< hours.count() << " h : " << minutes.count() << " m, " << std::fixed << std::setprecision(2) << seconds << " s"<