diff --git a/Makefile b/Makefile index 9bed00c..8533b2d 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,20 @@ -all: calx -CXXFLAGS+= -std=c++26 +CXXFLAGS+= -std=c++26 -Oz +CPPFLAGS+= -I . + +LDFLAGS+= -Wl,-rpath,'$$ORIGIN/' + +PROGRAMS=calx + +all: ${PROGRAMS} + +${PROGRAMS}: libalepha.so + + +libalepha.so: + mkdir -p build_alepha + cd build_alepha; cmake -GNinja -DCMAKE_BUILD_TYPE=Release ../Alepha; cp ../Alepha/helpful-things/Makefile .; make + cp build_alepha/libalepha.so . + +clean: + rm -f ${PROGRAMS} + rm -fR build_alepha libalepha.so diff --git a/calx.cc b/calx.cc index 7f08d6d..aa585e6 100644 --- a/calx.cc +++ b/calx.cc @@ -1,17 +1,24 @@ +#include + #include #include #include -#include +#include namespace { - namespace C { - const int startHour= 6; + int startHour= 6; } + 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 { @@ -25,14 +32,21 @@ namespace friend std::ostream & operator << ( std::ostream &os, const Appointment &appointment ) { - if( false ) - { - std::cout << " Wakeup "; - } + 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[" - << ( 1 + ( appointment.startHour - 6 ) * 4 + appointment.startQuarter + i ) + << line << "B[4" << appointment.color << ";1m"; if( i == 0 ) @@ -43,6 +57,21 @@ namespace 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; } }; @@ -54,77 +83,65 @@ namespace { "Meeting", 9, 1, 5, 5, blue }, { "Long Meeting Name", 8, 1, 8, 6, cyan }, }; + + 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; + + /* */ + 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::cout << "[?25l" << std::flush; + + sleep( 20 ); + std::cout << "[?25h" << std::flush; + } } int -main() +main( const int argcnt, const char *const argvec[]) { - using namespace std::literals::string_literals; + std::ignore= Alepha::handleOptions( argcnt, argvec ); + ::program(); - - - - -/* */ - auto example= R"( -| Time | Mon | Tue | Wed | Thu | Fri | Sat | Sun | -| 06:00 | | | | | | | | -| | | | | | | | | -| | | | | | | | | -|_______| | | | | | | | -| 07:00 | | | | | | | | -| | | | | | | | | -| | | | | | | | | -|_______| | | | | | | | -| 08:00 | | | | | | | | -| | | | | | | | | -| | | | | | | | | -|_______| | | | | | | | -| 09:00 | | | | | | | | -| | | | | | | | | -| | | | | | | | | -|_______| | | | | | | | -| 10:00 | | | | | | | | -| | | | | | | | | -| | | | | | | | | -|_______| | | | | | | | -| 11:00 | | | | | | | | -| | | | | | | | | -| | | | | | | | | -|_______| | | | | | | | - )"s.substr( 1 ); - example.pop_back(); example.pop_back(); - - std::cout << "" << example; - - if( false ) - { - std::cout << " Wakeup "; - std::cout << " "; - std::cout << " "; - - - std::cout << " Wakeup "; - std::cout << " "; - std::cout << " "; - std::cout << " "; - - - std::cout << " Meeting "; - std::cout << " "; - std::cout << " "; - std::cout << " "; - } - - for( auto &appt: appointments ) - { - std::cout << appt; - } - - - std::cout << "[?25l" << std::flush; - - - sleep( 20 ); - std::cout << "[?25h" << std::flush; + return EXIT_SUCCESS; }