Add statustime.
This commit is contained in:
commit
235c09b511
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/build/
|
19
CMakeLists.txt
Normal file
19
CMakeLists.txt
Normal 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
34
CMakePresets.json
Normal 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
38
statustime.cpp
Executable 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user