Add statustime.

This commit is contained in:
tastytea 2021-08-05 16:08:40 +02:00
commit 235c09b511
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
4 changed files with 92 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build/

19
CMakeLists.txt Normal file
View File

@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.20...3.20)
# Global build options.
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "The type of build.")
project(cppscripts
DESCRIPTION "Various single file scripts."
LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(fmt 7 REQUIRED CONFIG)
# find_package(termcolor CONFIG)
# find_package(Threads REQUIRED)
add_executable(statustime "statustime.cpp")
target_link_libraries(statustime PUBLIC fmt::fmt)

34
CMakePresets.json Normal file
View File

@ -0,0 +1,34 @@
{
"version": 2,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"patch": 0
},
"configurePresets": [
{
"name": "common",
"hidden": true,
"binaryDir": "build",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": true
}
},
{
"name": "release",
"displayName": "Release config",
"description": "Build without debug symbols or tests",
"inherits": "common",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
}
],
"buildPresets": [
{
"name": "parallel",
"configurePreset": "release",
"jobs": 3
}
]
}

38
statustime.cpp Executable file
View File

@ -0,0 +1,38 @@
// 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;
}
}