From 6167bf6fe8454097296b740ba677b2658dc877cc5b54d1fc49df576665d83d26 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Thu, 4 Jun 2026 23:49:38 -0400 Subject: [PATCH] Dynamically read appointments and start using Alepha --- appointments.csv | 5 ++ calx.cc | 132 +++++++++++++++++++++++++++-------------------- 2 files changed, 81 insertions(+), 56 deletions(-) create mode 100644 appointments.csv diff --git a/appointments.csv b/appointments.csv new file mode 100644 index 0000000..d17f0f4 --- /dev/null +++ b/appointments.csv @@ -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 diff --git a/calx.cc b/calx.cc index aa585e6..5ae7ec8 100644 --- a/calx.cc +++ b/calx.cc @@ -1,11 +1,17 @@ #include +#include #include +#include +#include #include #include +#include #include +#include + namespace { namespace C @@ -13,14 +19,27 @@ namespace int startHour= 6; } + using namespace Alepha::literals; 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."; }; - enum Color : int { red= 1, green= 2, yellow= 3, blue= 4, magenta= 5, cyan= 6, white= 7 }; - struct Appointment + //enum Color : int { red= 1, green= 2, yellow= 3, blue= 4, magenta= 5, cyan= 6, white= 7 }; + 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; int startHour; @@ -28,61 +47,56 @@ namespace int duration; // Quarter hours int day; 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 }, - { "Wakeup", 7, 1, 2, 2, red }, - { "Meeting", 9, 1, 5, 5, blue }, - { "Long Meeting Name", 8, 1, 8, 6, cyan }, - }; + 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.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 printHourGrid( int hour ) @@ -116,6 +130,12 @@ namespace { 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 |"; std::cout << "" << header; @@ -127,7 +147,7 @@ namespace for( auto &appt: appointments ) { - std::cout << appt; + std::cout << appt << std::endl;; } std::cout << "[?25l" << std::flush;