Dynamically read appointments and start using Alepha
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
|
||||
#include <Alepha/Enum.h>
|
||||
#include <Alepha/ProgramOptions.h>
|
||||
|
||||
#include <Alepha/IOStreams/IStreamable.h>
|
||||
|
||||
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[1000000A["
|
||||
<< 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 << "[m[H";
|
||||
}
|
||||
|
||||
if( skippedTop and not skippedBottom )
|
||||
{
|
||||
os << "[" << 10 * appointment.day
|
||||
<< "G[1000000A[B[4" << appointment.color
|
||||
<< ";1m^^^^^^^^^[m";
|
||||
}
|
||||
|
||||
if( skippedBottom and not skippedTop )
|
||||
{
|
||||
os << "[" << 10 * appointment.day
|
||||
<< "G[1000000A[24B[4" << appointment.color
|
||||
<< ";1mvvvvvvvvv[m";
|
||||
}
|
||||
|
||||
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[1000000A["
|
||||
<< 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 << "[m[H";
|
||||
}
|
||||
|
||||
if( skippedTop and not skippedBottom )
|
||||
{
|
||||
os << "[" << 10 * appointment.day
|
||||
<< "G[1000000A[B[4" << appointment.color
|
||||
<< ";1m^^^^^^^^^[m";
|
||||
}
|
||||
|
||||
if( skippedBottom and not skippedTop )
|
||||
{
|
||||
os << "[" << 10 * appointment.day
|
||||
<< "G[1000000A[24B[4" << appointment.color
|
||||
<< ";1mvvvvvvvvv[m";
|
||||
}
|
||||
|
||||
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 << "[m[H[2J" << header;
|
||||
@@ -127,7 +147,7 @@ namespace
|
||||
|
||||
for( auto &appt: appointments )
|
||||
{
|
||||
std::cout << appt;
|
||||
std::cout << appt << std::endl;;
|
||||
}
|
||||
|
||||
std::cout << "[?25l" << std::flush;
|
||||
|
||||
Reference in New Issue
Block a user