commit 235c09b511218c2061e5ca3d78a51ff86be4ca2c Author: tastytea Date: Thu Aug 5 16:08:40 2021 +0200 Add statustime. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..7477dc6 --- /dev/null +++ b/CMakeLists.txt @@ -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) diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..cf593e7 --- /dev/null +++ b/CMakePresets.json @@ -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 + } + ] +} diff --git a/statustime.cpp b/statustime.cpp new file mode 100755 index 0000000..c835318 --- /dev/null +++ b/statustime.cpp @@ -0,0 +1,38 @@ +// Print date and time for i3 status bar. + +#include +#include + +#include +#include +#include +#include +#include + +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"({0:%A}, )" + R"({0:%Y-%m-%d} )" + R"({0:%H:%M})", + 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 << "\nError: Time script crashed.\n"; + return 33; + } +}