feat: implement stopwatch timer

Replace Hello World with a live stopwatch that prints elapsed time
in HH:MM:SS.mmm format, updating every 10ms with color output.
This commit is contained in:
2026-05-05 21:31:10 +02:00
parent a13105a591
commit 237f446c6e
+27 -6
View File
@@ -1,6 +1,27 @@
#include <fmt/core.h>
auto main(int argc, char const* argv[]) -> int {
fmt::print("Hello, World!\n");
return 0;
}
#include <chrono>
#include <thread>
#include "fmt/std.h"
auto main(int argc, char const* argv[]) -> int {
using namespace std::chrono;
using namespace std::literals;
auto start = steady_clock::now();
while (true) {
auto elapsed = steady_clock::now() - start;
auto totalSec = duration_cast<seconds>(elapsed).count();
auto h = totalSec / 3600;
auto m = (totalSec % 3600) / 60;
auto s = totalSec % 60;
auto ms = duration_cast<milliseconds>(elapsed % 1s).count();
fmt::print("\033[32m{:02}:{:02}:{:02}\033[0m.\033[90m{:03}\033[0m\r",
h, m, s, ms);
std::this_thread::sleep_for(10ms);
}
return 0;
}