3 #include "../include/Display.hpp" 69 string clearscreen =
"\033[2J\033[H";
76 fast_print(clearscreen);
81 _currFont = _fonts.at(num-1);
83 ASCII_HEIGHT = _fontHeights.at(num-1);
85 if(ASCII_HEIGHT >= 8){
87 for(
int i=0; i< ASCII_HEIGHT/4; i++){
103 string setcursor =
"\033[" + to_string(row) +
";" + to_string(col) +
"H";
104 fast_print(setcursor);
113 string clearline =
"\033[K";
115 fast_print(clearline);
123 template <
typename char_type>
126 HANDLE
const output_handle = GetStdHandle(STD_OUTPUT_HANDLE);
127 const auto char_count =
static_cast<DWORD
>(sss.length());
128 if constexpr (std::is_same_v<char_type, char>)
129 WriteConsoleA(output_handle, sss.c_str(), char_count,
nullptr,
nullptr);
131 WriteConsoleW(output_handle, sss.c_str(), char_count,
nullptr,
nullptr);
139 _oldFormatting = _formatting;
141 fast_print(_formatting);
148 _oldFormatting = _formatting;
149 _formatting =
"\033[0m";
151 fast_print(_formatting);
164 _splash =
"<< " + str +
" >>";
188 string to_print =
"";
193 to_print += to_string(hours) +
":";
197 if (
int(minutes / 10) != 0)
199 to_print += to_string(minutes) +
":";
203 to_print +=
"0" + to_string(minutes) +
":";
207 if (
int(seconds / 10) != 0)
209 to_print += to_string(seconds);
213 to_print +=
"0" + to_string(seconds);
217 for (
int i = 0; i < ASCII_HEIGHT; i++)
220 for (
char ch : to_print)
224 line += _currFont.at(10)[i];
229 line += _currFont.at(11)[i];
234 line += _currFont.at(ch -
'0')[i];
238 _asciiWidth = line.length();
239 _asciiBuffer += (line +
"\n");
249 string to_print =
"";
251 int hours = stoi(time.substr(0,2));
252 int minutes = stoi(time.substr(3,2));
255 string period = (hours >= 12) ?
"pm" :
"am";
257 if (hours == 0) { hours = 12; }
259 to_print += to_string(hours) +
":";
262 if (
int(minutes / 10) != 0)
264 to_print += to_string(minutes);
268 to_print +=
"0" + to_string(minutes);
276 for (
int i = 0; i < ASCII_HEIGHT; i++)
279 for (
char ch : to_print)
283 line += _currFont.at(10)[i];
288 line += _currFont.at(12)[i];
293 line += _currFont.at(13)[i];
298 line += _currFont.at(14)[i];
303 line += _currFont.at(ch -
'0')[i];
307 _asciiWidth = line.length();
308 _asciiBuffer += (line +
"\n");
318 int width = _asciiWidth - 2;
319 int filled = (int)((percentage / 100) * width);
325 for (
int i = 0; i < width; ++i)
331 _barBuffer += border;
336 for (
int i = 0; i < width; ++i)
349 _barBuffer += border;
358 int width = _asciiWidth - 2;
359 int filled = (int)((percentage / 100) * width);
365 for (
int i = 0; i < width; ++i)
371 _barBuffer += border;
376 for (
int i = 0; i < width; ++i)
389 _barBuffer += border;
398 for(
int i=0; i<art.size(); ++i){
399 _controlBuffer += (art.at(i) +
"\n");
416 string to_print =
"";
421 to_print += to_string(hours) +
":";
427 if (
int(minutes / 10) != 0)
429 to_print += to_string(minutes) +
":";
433 to_print +=
"0" + to_string(minutes) +
":";
438 to_print += to_string(minutes) +
":";
442 if (hours || minutes)
444 if (
int(seconds / 10) != 0)
446 to_print += to_string(seconds);
450 to_print +=
"0" + to_string(seconds);
455 to_print += to_string(seconds);
462 if (
int(hundredths / 10) != 0)
464 to_print += to_string(hundredths);
468 to_print +=
"0" + to_string(hundredths);
473 for (
int i = 0; i < ASCII_HEIGHT; i++)
476 for (
char ch : to_print)
480 line += _currFont.at(10)[i];
485 line += _currFont.at(11)[i];
490 line += _currFont.at(ch -
'0')[i];
494 _asciiBuffer += (line +
"\n");
502 if (!splits.empty()) {
503 _splitBuffer +=
" SPLITS:\n\n";
504 int startIdx = (splits.size() > 10) ? splits.size() - 10 : 0;
505 for (
int i = startIdx; i < splits.size(); ++i) {
507 int milliseconds = splits.at(i);
508 int hours = milliseconds / 3600000;
509 milliseconds %= 3600000;
510 int minutes = milliseconds / 60000;
511 milliseconds %= 60000;
512 int seconds = milliseconds / 1000;
513 milliseconds %= 1000;
514 int hundredths = milliseconds / 10;
515 string to_print =
"";
519 to_print += to_string(hours) +
":";
524 if (
int(minutes / 10) != 0) {
525 to_print += to_string(minutes) +
":";
527 to_print +=
"0" + to_string(minutes) +
":";
529 }
else if (minutes) {
530 to_print += to_string(minutes) +
":";
534 if (hours || minutes) {
535 if (
int(seconds / 10) != 0) {
536 to_print += to_string(seconds);
538 to_print +=
"0" + to_string(seconds);
541 to_print += to_string(seconds);
547 if (
int(hundredths / 10) != 0) {
548 to_print += to_string(hundredths);
550 to_print +=
"0" + to_string(hundredths);
553 string fullprint =
"Split " + to_string(i + 1) +
": " + to_print +
"\n";
554 _splitBuffer += fullprint;
571 setFormat(formatting);
573 if (_asciiBuffer != _oldAscii || _formatting != _oldFormatting)
576 fast_print(_asciiBuffer);
577 _oldAscii = _asciiBuffer;
590 setFormat(formatting);
592 if (_controlBuffer != _oldControls || _formatting != _oldFormatting)
595 fast_print(_controlBuffer);
596 _oldControls = _controlBuffer;
609 setFormat(formatting);
611 if (_barBuffer != _oldBar || _formatting != _oldFormatting)
614 fast_print(_barBuffer);
615 _oldBar = _barBuffer;
628 setFormat(formatting);
630 if (_splash != _oldSplash || _formatting != _oldFormatting)
635 _oldSplash = _splash;
647 setFormat(formatting);
648 if (_splitBuffer != _oldSplits || _formatting != _oldFormatting)
651 fast_print(_splitBuffer);
652 _oldSplits = _splitBuffer;
665 auto now = std::chrono::steady_clock::now();
666 auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
668 bool showBar = ((millis / 500) % 2 == 0);
670 _asciiBuffer.clear();
672 for (
int i = 0; i < ASCII_HEIGHT; ++i)
675 for (
char ch : to_print)
679 line += _currFont.at(10)[i];
683 line += _currFont.at(ch -
'0')[i];
687 line += showBar ?
" |" :
" ";
688 _asciiWidth = line.length();
689 _asciiBuffer += (line +
"\n");
691 stageArt(_timerSetupControls);
693 printArt(1, BOLD_CYAN);
694 printAscii(5, BOLD_WHITE);
707 auto now = std::chrono::steady_clock::now();
708 auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
712 bool showBar = ((millis / 500) % 2 == 0);
713 if(ASCII_HEIGHT < 4){
717 tempHeight = ASCII_HEIGHT;
719 for (
int i = 0; i < tempHeight; i++)
723 for (
char ch : to_print)
727 line += _currFont.at(10)[i];
732 line += _currFont.at(ch -
'0')[i];
745 int linesLeft = tempHeight - i;
757 line += _alarmSetupAM[4-linesLeft];
770 line += _alarmSetupPM[4-linesLeft];
777 _asciiWidth = line.length();
778 _asciiBuffer += (line +
"\n");
782 stageArt(_alarmSetupControls);
784 printArt(1, BOLD_CYAN);
786 printAscii(5,BOLD_WHITE);
814 auto now = std::chrono::steady_clock::now();
815 auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
816 bool flash = ((millis / 500) % 2 == 0);
819 int hours = remaining / 3600000;
820 remaining %= 3600000;
821 int minutes = remaining / 60000;
823 int seconds = remaining / 1000;
825 int tenths = remaining / 100;
827 stageTimerDisplay(hours, minutes, seconds, tenths);
829 stageArt(_timerControls);
833 if(timer.
isDone() && flash){
845 printBar(ASCII_HEIGHT+2, temp);
846 printArt(ASCII_HEIGHT+5, BOLD_CYAN);
847 printSplash(ASCII_HEIGHT+8, WHITE);
860 int hours = milliseconds / 3600000;
861 milliseconds %= 3600000;
862 int minutes = milliseconds / 60000;
863 milliseconds %= 60000;
864 int seconds = milliseconds / 1000;
865 milliseconds %= 1000;
866 int hundredths = milliseconds / 10;
868 stageStopwatchDisplay(hours, minutes, seconds, hundredths);
869 stageArt(_stopwatchControls);
870 stageStopwatchSplits(stopwatch.
getSplits());
886 printArt(ASCII_HEIGHT+1, BOLD_CYAN);
887 printSplash(ASCII_HEIGHT+4, WHITE);
888 printSplits(ASCII_HEIGHT+6, WHITE);
901 auto now = std::chrono::steady_clock::now();
902 auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
903 bool flash = ((millis / 500) % 2 == 0);
907 stageAlarmDisplay(time);
909 stageArt(_alarmControls);
912 if(alarm.
isDone() && flash){
919 printBar(ASCII_HEIGHT+2, temp);
921 printArt(ASCII_HEIGHT+5, BOLD_CYAN);
922 printSplash(ASCII_HEIGHT+8, WHITE);
double percentElapsed()
Returns the percentage of time that has elapsed since the timer started.
A class to manage alarms with time-based triggers.
string timeToString(chrono::time_point< chrono::system_clock > t)
Converts a given time point to a string format (HH:MM).
The Timer class provides a countdown timer with start, pause, resume, reset, and time adjustment func...
void clearSplash()
Clears the splash screen.
The Stopwatch class provides a simple timer with start, pause, resume, and reset functionalities.
int remainingMilliseconds()
Returns the remaining time in milliseconds.
void tickTimerSetup(string to_print)
Updates the timer setup display, showing the current input with a blinking cursor.
chrono::time_point< chrono::system_clock > getEndTime()
Returns the alarm's end time.
double percentElapsed()
Calculates the percentage of time that has elapsed from start to end.
bool isDone()
Checks if the alarm has finished.
static const string BOLD_YELLOW
static const string BLACK
static const string BOLD_WHITE
void setCursor(int x, int y)
Sets the cursor position in the terminal.
void setFont(int num)
Sets the font style for the terminal.
vector< vector< string > > f3_ascii
void stageAlarmDisplay()
Stages the display for the alarm.
void setFormat(const string &code)
Sets the terminal text color.
void clearFormat()
Clears the terminal text color.
static const string BOLD_BLACK
static const string SELECTED
static const string BOLD_RED
static auto fast_print(const basic_string< char_type > &sss) -> void
Efficiently prints a string to the terminal.
static const string WHITE
void printSplits(int splitsIndex, string formatting)
Prints the stopwatch splits to the terminal.
void stageStopwatchSplits(vector< int > splits)
Stages the splits block to be displayed.
static const string YELLOW
static const string BOLD_GREEN
void printBar(int barIndex, string formatting)
Prints the progress bar to the terminal.
void stageTimerDisplay(int hours, int minutes, int seconds, int tenths)
Stages the timer display with provided time values.
void stageArt(vector< string > art)
Stages the controls for the timer.
void printSplash(int splashIndex, string formatting)
Prints the splash screen to the terminal.
static const string MAGENTA
void tickTimer(Timer &timer)
Updates the display based on the state of the provided Timer object.
void clearScreen()
Clears the terminal screen.
static const string BOLD_CYAN
bool isRunning()
Checks if the timer is currently running.
void tickStopwatch(Stopwatch &stopwatch)
Updates the display based on the state of the provided Stopwatch object.
int currentMilliseconds()
Returns the current elapsed time in milliseconds.
vector< int > getSplits()
Returns the splits vector.
void stageAlarmBar(double percentage)
Creates a visual progress bar for the alarm based on the percentage completed.
void tickAlarm(Alarm &alarm)
Updates the display based on the state of the provided Alarm object.
static const string BOLD_BLUE
Display()
Constructs a new Display object.
static const string BOLD_MAGENTA
vector< vector< string > > f4_ascii
void printArt(int controlIndex, string formatting)
Prints controls to the terminal.
void stageStopwatchDisplay(int hours, int minutes, int seconds, int hundredths)
Stages the stopwatch display with provided time values.
void tickAlarmSetup(string to_print, bool isAM)
Updates the alarm setup display, showing the current input with a blinking cursor.
vector< vector< string > > f2_ascii
static const string GREEN
void printAscii(int asciiIndex, string formatting)
Prints ASCII art to the terminal.
bool isRunning()
Checks if the stopwatch is currently running.
void clearLine(int lineIndex)
Clears a specific line in the terminal.
void stageTimerBar(double percentage)
Stages the progress bar for the timer.
vector< vector< string > > f1_ascii
void setSplash(string str)
Sets the splash screen text.