Dynamically read appointments and start using Alepha

This commit is contained in:
2026-06-04 23:49:38 -04:00
parent 7dcdfda182
commit 6167bf6fe8
2 changed files with 81 additions and 56 deletions
+5
View File
@@ -0,0 +1,5 @@
Wakeup 6 0 1 3 red
Wakeup 7 1 2 2 red
Meeting 9 1 5 5 blue
Long Meeting Name 8 1 8 6 cyan
XYZ Mtg Group 8 2 12 1 green
1 Wakeup 6 0 1 3 red
2 Wakeup 7 1 2 2 red
3 Meeting 9 1 5 5 blue
4 Long Meeting Name 8 1 8 6 cyan
5 XYZ Mtg Group 8 2 12 1 green
+76 -56
View File
@@ -1,11 +1,17 @@
#include <unistd.h> #include <unistd.h>
#include <fstream>
#include <iostream> #include <iostream>
#include <algorithm>
#include <iterator>
#include <iomanip> #include <iomanip>
#include <string> #include <string>
#include <Alepha/Enum.h>
#include <Alepha/ProgramOptions.h> #include <Alepha/ProgramOptions.h>
#include <Alepha/IOStreams/IStreamable.h>
namespace namespace
{ {
namespace C namespace C
@@ -13,14 +19,27 @@ namespace
int startHour= 6; int startHour= 6;
} }
using namespace Alepha::literals;
auto init= Alepha::Utility::enroll <=[] auto init= Alepha::Utility::enroll <=[]
{ {
using namespace Alepha::literals;
--"start-hour"_option << C::startHour << "Selects a starting hour other than 6AM. Times are 24H and errors are not checked."; --"start-hour"_option << C::startHour << "Selects a starting hour other than 6AM. Times are 24H and errors are not checked.";
}; };
enum Color : int { red= 1, green= 2, yellow= 3, blue= 4, magenta= 5, cyan= 6, white= 7 }; //enum Color : int { red= 1, green= 2, yellow= 3, blue= 4, magenta= 5, cyan= 6, white= 7 };
struct Appointment using Color= Alepha::Enum
<
"black"_value,
"red"_value,
"green"_value,
"yellow"_value,
"blue"_value,
"magenta"_value,
"cyan"_value,
"white"_value
>;
template< typename= Alepha::Capabilities< Alepha::IOStreams::IStreamable > >
struct Appointment_core
{ {
std::string name; std::string name;
int startHour; int startHour;
@@ -28,61 +47,56 @@ namespace
int duration; // Quarter hours int duration; // Quarter hours
int day; int day;
Color color; Color color;
friend std::ostream &
operator << ( std::ostream &os, const Appointment &appointment )
{
const int baseLine= 1 + ( appointment.startHour - C::startHour ) * 4 + appointment.startQuarter;
bool skippedTop= false;
bool skippedBottom= false;
if( appointment.startHour < C::startHour and appointment.duration <= 4 ) return os;
if( appointment.startHour > C::startHour + 6 ) return os;
for( int i= 0; i < appointment.duration; ++i )
{
const int line= baseLine + i;
if( line < 1 ) { skippedTop= true; continue; }
if( line > 24 ) { skippedBottom= true; continue; }
os << "[" << 10 * appointment.day << "G["
<< line
<< "B[4" << appointment.color
<< ";1m";
if( i == 0 )
{
if( appointment.name.size() <= 9 ) os << std::left << std::setw( 9 ) << appointment.name;
else os << std::setw( 6 ) << appointment.name.substr(0,6) << "...";
}
else os << std::setw( 9 ) << "";
os << "";
}
if( skippedTop and not skippedBottom )
{
os << "[" << 10 * appointment.day
<< "G[4" << appointment.color
<< ";1m^^^^^^^^^";
}
if( skippedBottom and not skippedTop )
{
os << "[" << 10 * appointment.day
<< "G[4" << appointment.color
<< ";1mvvvvvvvvv";
}
return os;
}
}; };
using Appointment= Appointment_core<>;
Appointment appointments[]= std::ostream &
operator << ( std::ostream &os, const Appointment &appointment )
{ {
{ "Wakeup", 6, 0, 1, 3, red }, const int baseLine= 1 + ( appointment.startHour - C::startHour ) * 4 + appointment.startQuarter;
{ "Wakeup", 7, 1, 2, 2, red }, bool skippedTop= false;
{ "Meeting", 9, 1, 5, 5, blue }, bool skippedBottom= false;
{ "Long Meeting Name", 8, 1, 8, 6, cyan },
}; if( appointment.startHour < C::startHour and appointment.duration <= 4 ) return os;
if( appointment.startHour > C::startHour + 6 ) return os;
for( int i= 0; i < appointment.duration; ++i )
{
const int line= baseLine + i;
if( line < 1 ) { skippedTop= true; continue; }
if( line > 24 ) { skippedBottom= true; continue; }
os << "[" << 10 * appointment.day << "G["
<< line
<< "B[4" << appointment.color.get_index()
<< ";1m";
if( i == 0 )
{
if( appointment.name.size() <= 9 ) os << std::left << std::setw( 9 ) << appointment.name;
else os << std::setw( 6 ) << appointment.name.substr(0,6) << "...";
}
else os << std::setw( 9 ) << "";
os << "";
}
if( skippedTop and not skippedBottom )
{
os << "[" << 10 * appointment.day
<< "G[4" << appointment.color
<< ";1m^^^^^^^^^";
}
if( skippedBottom and not skippedTop )
{
os << "[" << 10 * appointment.day
<< "G[4" << appointment.color
<< ";1mvvvvvvvvv";
}
return os;
}
std::vector< Appointment > appointments;
void void
printHourGrid( int hour ) printHourGrid( int hour )
@@ -116,6 +130,12 @@ namespace
{ {
using namespace std::literals::string_literals; using namespace std::literals::string_literals;
{
std::ifstream data{ "appointments.csv" };
std::copy( std::istream_iterator< Appointment >{ data }, std::istream_iterator< Appointment >{}, std::back_inserter( appointments ) );
}
/* */ /* */
auto header= "| Time | Mon | Tue | Wed | Thu | Fri | Sat | Sun |"; auto header= "| Time | Mon | Tue | Wed | Thu | Fri | Sat | Sun |";
std::cout << "" << header; std::cout << "" << header;
@@ -127,7 +147,7 @@ namespace
for( auto &appt: appointments ) for( auto &appt: appointments )
{ {
std::cout << appt; std::cout << appt << std::endl;;
} }
std::cout << "[?25l" << std::flush; std::cout << "[?25l" << std::flush;