Add Alepha and dynamically generate much of the view.

This commit is contained in:
2026-06-04 17:13:29 -04:00
parent 80a3742fc5
commit 28fb94a674
2 changed files with 113 additions and 78 deletions
+20 -2
View File
@@ -1,2 +1,20 @@
all: calx CXXFLAGS+= -std=c++26 -Oz
CXXFLAGS+= -std=c++26 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
+93 -76
View File
@@ -1,17 +1,24 @@
#include <unistd.h>
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <string> #include <string>
#include <unistd.h> #include <Alepha/ProgramOptions.h>
namespace namespace
{ {
namespace C 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 }; enum Color : int { red= 1, green= 2, yellow= 3, blue= 4, magenta= 5, cyan= 6, white= 7 };
struct Appointment struct Appointment
{ {
@@ -25,14 +32,21 @@ namespace
friend std::ostream & friend std::ostream &
operator << ( std::ostream &os, const Appointment &appointment ) operator << ( std::ostream &os, const Appointment &appointment )
{ {
if( false ) const int baseLine= 1 + ( appointment.startHour - C::startHour ) * 4 + appointment.startQuarter;
{ bool skippedTop= false;
std::cout << " Wakeup "; 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 ) 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[" os << "[" << 10 * appointment.day << "G["
<< ( 1 + ( appointment.startHour - 6 ) * 4 + appointment.startQuarter + i ) << line
<< "B[4" << appointment.color << "B[4" << appointment.color
<< ";1m"; << ";1m";
if( i == 0 ) if( i == 0 )
@@ -43,6 +57,21 @@ namespace
else os << std::setw( 9 ) << ""; else os << std::setw( 9 ) << "";
os << ""; 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; return os;
} }
}; };
@@ -54,77 +83,65 @@ namespace
{ "Meeting", 9, 1, 5, 5, blue }, { "Meeting", 9, 1, 5, 5, blue },
{ "Long Meeting Name", 8, 1, 8, 6, cyan }, { "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 int
main() main( const int argcnt, const char *const argvec[])
{ {
using namespace std::literals::string_literals; std::ignore= Alepha::handleOptions( argcnt, argvec );
::program();
return EXIT_SUCCESS;
/* */
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;
} }