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
+34 -14
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,8 +47,10 @@ namespace
int duration; // Quarter hours int duration; // Quarter hours
int day; int day;
Color color; Color color;
};
using Appointment= Appointment_core<>;
friend std::ostream & std::ostream &
operator << ( std::ostream &os, const Appointment &appointment ) operator << ( std::ostream &os, const Appointment &appointment )
{ {
const int baseLine= 1 + ( appointment.startHour - C::startHour ) * 4 + appointment.startQuarter; const int baseLine= 1 + ( appointment.startHour - C::startHour ) * 4 + appointment.startQuarter;
@@ -47,7 +68,7 @@ namespace
os << "[" << 10 * appointment.day << "G[" os << "[" << 10 * appointment.day << "G["
<< line << line
<< "B[4" << appointment.color << "B[4" << appointment.color.get_index()
<< ";1m"; << ";1m";
if( i == 0 ) if( i == 0 )
{ {
@@ -74,15 +95,8 @@ namespace
return os; return os;
} }
};
Appointment appointments[]= std::vector< Appointment > appointments;
{
{ "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 },
};
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;