cppscripts/statustime.cpp

39 lines
983 B
C++
Executable File

// Print date and time for i3 status bar.
#include <fmt/chrono.h>
#include <fmt/core.h>
#include <chrono>
#include <exception>
#include <iostream>
#include <locale>
#include <thread>
int main()
{
using fmt::format;
using std::cout;
using namespace std::chrono_literals;
// Set explicitly, because LC_TIME is en_DK.UTF-8.
std::locale::global(std::locale("de_DE.UTF-8"));
try
{
while (true)
{
cout << format(R"(<b><span color="orange">{0:%A}</span></b>, )"
R"({0:%Y-%m-%d} )"
R"(<span color="lightcyan">{0:%H:%M}</span>)",
std::chrono::system_clock::now())
<< std::endl; // NOTE: Don't forget that we need to flush! 😊
std::this_thread::sleep_for(1s);
}
}
catch (const std::exception &)
{
cout << "\n<span color='red'>Error: Time script crashed.</span>\n";
return 33;
}
}