Files

168 lines
3.7 KiB
C++

#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
{
int startHour= 6;
}
using namespace Alepha::literals;
auto init= Alepha::Utility::enroll <=[]
{
--"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 };
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;
int startQuarter;
int duration; // Quarter hours
int day;
Color color;
};
using Appointment= Appointment_core<>;
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.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 )
{
for( int line= 0; line < 4; ++line )
{
std::cout << '\n';
if( line == 0 )
{
std::cout << "| " << std::setw( 2 ) << std::setfill( '0' ) << hour << std::setfill( ' ' ) << ":00 |";
}
else if( line == 3 )
{
std::cout << "|-------|";
}
else
{
std::cout << "| |";
}
for( int i= 0; i < 7; ++i )
{
std::cout << " |";
}
}
}
void
program()
{
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;
for( int hour= C::startHour; hour < C::startHour + 6; ++hour )
{
printHourGrid( hour );
}
for( auto &appt: appointments )
{
std::cout << appt << std::endl;;
}
std::cout << "[?25l" << std::flush;
sleep( 20 );
std::cout << "[?25h" << std::flush;
}
}
int
main( const int argcnt, const char *const argvec[])
{
std::ignore= Alepha::handleOptions( argcnt, argvec );
::program();
return EXIT_SUCCESS;
}