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
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
+80 -63
View File
@@ -1,17 +1,24 @@
#include <unistd.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <unistd.h>
#include <Alepha/ProgramOptions.h>
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,66 +83,46 @@ 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 << "| |";
}
int
main()
for( int i= 0; i < 7; ++i )
{
std::cout << " |";
}
}
}
void
program()
{
using namespace std::literals::string_literals;
/* */
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();
auto header= "| Time | Mon | Tue | Wed | Thu | Fri | Sat | Sun |";
std::cout << "" << header;
std::cout << "" << example;
if( false )
for( int hour= C::startHour; hour < C::startHour + 6; ++hour )
{
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 << " ";
printHourGrid( hour );
}
for( auto &appt: appointments )
@@ -121,10 +130,18 @@ main()
std::cout << appt;
}
std::cout << "[?25l" << std::flush;
sleep( 20 );
std::cout << "[?25h" << std::flush;
std::cout << "[?25h" << std::flush;
}
}
int
main( const int argcnt, const char *const argvec[])
{
std::ignore= Alepha::handleOptions( argcnt, argvec );
::program();
return EXIT_SUCCESS;
}