Skip to content

Commit dded943

Browse files
ZeeTerminal 0.5.1 src commit
1 parent b43f6c0 commit dded943

10 files changed

+231
-68
lines changed

CommandFiles/CPUStress.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void CpuBenchmark(short int nSingleOrMulti, long long int nArgNum = -1) {
4343
std::chrono::time_point<std::chrono::steady_clock> start, end;
4444
std::chrono::duration<long double> ldElapsedTime; // Save the duration of the operation here
4545
long long int nInput = 0;
46+
bool bUserCursorVisibilitySetting = true;
4647

4748

4849
// Take input
@@ -87,6 +88,9 @@ void CpuBenchmark(short int nSingleOrMulti, long long int nArgNum = -1) {
8788
slowcolourfn(LGRN, ConfigObjMain.sColourGlobalBack, "Single-core benchmark has started...\n");
8889
ClearKeyboardBuffer();
8990

91+
// Disable cursor
92+
bUserCursorVisibilitySetting = DisableCursorVisibility();
93+
9094
start = std::chrono::steady_clock::now();
9195

9296
std::thread SingleCoreWorker(CpuBenchmarkWorker);
@@ -128,12 +132,6 @@ void CpuBenchmark(short int nSingleOrMulti, long long int nArgNum = -1) {
128132
Exiting();
129133
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
130134
}
131-
132-
// Reset values to default
133-
bCpuStressKeyboardTermination = false;
134-
nReiterationCount = 0;
135-
StopCpuStress = false;
136-
nCurrentReiterationNum = 0;
137135
}
138136

139137
// Multi Core
@@ -147,6 +145,9 @@ void CpuBenchmark(short int nSingleOrMulti, long long int nArgNum = -1) {
147145
slowcolourfn(LGRN, ConfigObjMain.sColourGlobalBack, "Multi-core benchmark has started...\n");
148146
ClearKeyboardBuffer();
149147

148+
// Disable cursor
149+
bUserCursorVisibilitySetting = DisableCursorVisibility();
150+
150151
start = std::chrono::steady_clock::now();
151152
for (int i = 0; i < nLogicalCoreCount; i++) {
152153
vThreads[i] = std::thread(CpuBenchmarkWorker);
@@ -198,6 +199,11 @@ void CpuBenchmark(short int nSingleOrMulti, long long int nArgNum = -1) {
198199
nReiterationCount = 0;
199200
StopCpuStress = false;
200201
nCurrentReiterationNum = 0;
202+
203+
// Reset cursor visibility
204+
ConfigObjMain.bShowCursor = bUserCursorVisibilitySetting;
205+
SetCursorAttributes();
206+
201207
return;
202208
}
203209

CommandFiles/CommandFileAssets.cpp

Lines changed: 110 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -523,46 +523,147 @@ std::string AnsiToWin32Colours(std::string sAnsiColour)
523523

524524
// Checks all ConfigObjMain.sColour colours to see if they don't exceed the WIN32 colour limit (8192)
525525
// Returns TRUE for all correct, FALSE for 1 or more variables incorrect.
526-
bool CheckColourWin32Validity() {
526+
bool ValidateColourStringsWin32() {
527527
bool bSuccess = true;
528528

529529
// Check validity of WIN32 values - They may not exceed 8192 (base 10).
530530
if (not (isNumberi(ConfigObjMain.sColourGlobal) && std::stoi(ConfigObjMain.sColourGlobal) < 8192)) {
531-
ConfigObjMain.sColourGlobal = LWHT;
531+
ConfigObjMain.sColourGlobal = LWHT_WIN32;
532532
bSuccess = false;
533533
}
534534
if (not (isNumberi(ConfigObjMain.sColourGlobalBack) && std::stoi(ConfigObjMain.sColourGlobalBack) < 8192)) {
535-
ConfigObjMain.sColourGlobalBack = BLK;
535+
ConfigObjMain.sColourGlobalBack = BLK_WIN32;
536536
bSuccess = false;
537537
}
538538
if (not (isNumberi(ConfigObjMain.sColourHighlight) && std::stoi(ConfigObjMain.sColourHighlight) < 8192)) {
539-
ConfigObjMain.sColourHighlight = LWHT;
539+
ConfigObjMain.sColourHighlight = LWHT_WIN32;
540540
bSuccess = false;
541541
}
542542
if (not (isNumberi(ConfigObjMain.sColourHighlightBack) && std::stoi(ConfigObjMain.sColourHighlightBack) < 8192)) {
543-
ConfigObjMain.sColourHighlightBack = BLU;
543+
ConfigObjMain.sColourHighlightBack = BLU_WIN32;
544544
bSuccess = false;
545545
}
546546
if (not (isNumberi(ConfigObjMain.sColourTitle) && std::stoi(ConfigObjMain.sColourTitle) < 8192)) {
547-
ConfigObjMain.sColourTitle = BLK;
547+
ConfigObjMain.sColourTitle = BLK_WIN32;
548548
bSuccess = false;
549549
}
550550
if (not (isNumberi(ConfigObjMain.sColourTitleBack) && std::stoi(ConfigObjMain.sColourTitleBack) < 8192)) {
551-
ConfigObjMain.sColourTitleBack = LCYN;
551+
ConfigObjMain.sColourTitleBack = LCYN_WIN32;
552552
bSuccess = false;
553553
}
554554
if (not (isNumberi(ConfigObjMain.sColourSubheading) && std::stoi(ConfigObjMain.sColourSubheading) < 8192)) {
555-
ConfigObjMain.sColourSubheading = LWHT;
555+
ConfigObjMain.sColourSubheading = LWHT_WIN32;
556556
bSuccess = false;
557557
}
558558
if (not (isNumberi(ConfigObjMain.sColourSubheadingBack) && std::stoi(ConfigObjMain.sColourSubheadingBack) < 8192)) {
559-
ConfigObjMain.sColourSubheadingBack = MAG;
559+
ConfigObjMain.sColourSubheadingBack = MAG_WIN32;
560560
bSuccess = false;
561561
}
562562

563563
return bSuccess;
564564
}
565565

566+
// VerifyANSIColourString - Verifies an ANSI colour string with the following rules:
567+
// - 1. It must only contain numbers and semicolons
568+
// - 2. The numbers in the colour string must be less than 256.
569+
// Parameters: sColourString - The colour string to check.
570+
// Return Values: TRUE or 1 for a valid colour string, FALSE or 0 for a bad colour string.
571+
//
572+
bool VerifyANSIColourString(std::string sColourString)
573+
{
574+
std::size_t nLastSemicolonPlus1 = 0;
575+
576+
// Check if sColourString contains nothing - if so, it's not valid
577+
if (sColourString.empty()) return false;
578+
579+
for (uint8_t i = 0; i < 3; i++)
580+
{
581+
// Parse up to first non-number
582+
std::string sBuffer = "";
583+
for (size_t j = nLastSemicolonPlus1; j < sColourString.length(); j++, nLastSemicolonPlus1 = j + 1) {
584+
if (sColourString[j] == ';') {
585+
break;
586+
}
587+
else sBuffer.push_back(sColourString[j]);
588+
}
589+
590+
// Check if buffer is empty - if so, it means that the colour string doesn't have enough colour values to make a colour
591+
if (sBuffer == "") {
592+
return false;
593+
}
594+
// Check if buffer is a number
595+
if (!isNumberi(sBuffer)) {
596+
return false;
597+
}
598+
// Check if number is below 256 (convert as well)
599+
if (std::stoi(sBuffer) > 255) {
600+
return false;
601+
}
602+
}
603+
604+
// Check if whole string checked - if not, it means that there's unwanted characters that are out of the scope of this algorithm,
605+
// and therefore the colour string is invalid
606+
if (nLastSemicolonPlus1 - 1 < sColourString.length()) return false;
607+
608+
return true;
609+
}
610+
611+
// Checks all ConfigObjMain.sColour colours to see if they are valid, in the 255;255;255 format.
612+
// Returns TRUE for all correct, FALSE for 1 or more variables incorrect.
613+
bool ValidateColourStringsANSI() {
614+
bool bSuccess = true;
615+
616+
// Check validity of ANSI string values
617+
if (!VerifyANSIColourString(ConfigObjMain.sColourGlobal)) {
618+
ConfigObjMain.sColourGlobal = LWHT_ANSI;
619+
bSuccess = false;
620+
}
621+
if (!VerifyANSIColourString(ConfigObjMain.sColourGlobalBack)) {
622+
ConfigObjMain.sColourGlobalBack = BLK_ANSI;
623+
bSuccess = false;
624+
}
625+
if (!VerifyANSIColourString(ConfigObjMain.sColourHighlight)) {
626+
ConfigObjMain.sColourHighlight = LWHT_ANSI;
627+
bSuccess = false;
628+
}
629+
if (!VerifyANSIColourString(ConfigObjMain.sColourHighlightBack)) {
630+
ConfigObjMain.sColourHighlightBack = BLU_ANSI;
631+
bSuccess = false;
632+
}
633+
if (!VerifyANSIColourString(ConfigObjMain.sColourTitle)) {
634+
ConfigObjMain.sColourTitle = BLK_ANSI;
635+
bSuccess = false;
636+
}
637+
if (!VerifyANSIColourString(ConfigObjMain.sColourTitleBack)) {
638+
ConfigObjMain.sColourTitleBack = LCYN_ANSI;
639+
bSuccess = false;
640+
}
641+
if (!VerifyANSIColourString(ConfigObjMain.sColourSubheading)) {
642+
ConfigObjMain.sColourSubheading = LWHT_ANSI;
643+
bSuccess = false;
644+
}
645+
if (!VerifyANSIColourString(ConfigObjMain.sColourSubheadingBack)) {
646+
ConfigObjMain.sColourSubheadingBack = MAG_ANSI;
647+
bSuccess = false;
648+
}
649+
650+
return bSuccess;
651+
}
652+
653+
// Function that hides console cursor and returns value of previous setting to set later.
654+
// Commonly used for progress bars to prevent cursor flickering
655+
//
656+
bool DisableCursorVisibility() {
657+
bool bPreviousSetting = ConfigObjMain.bShowCursor;
658+
659+
// Set to FALSE and write cursor attributes
660+
ConfigObjMain.bShowCursor = false;
661+
SetCursorAttributes();
662+
663+
// Return previous setting in case user wants to put back to normal
664+
return bPreviousSetting;
665+
}
666+
566667
// Mission Impossible Theme Song in Beeps
567668
//
568669
void MissionImpossibleTheme() {

CommandFiles/CommandsFile.cpp

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -616,12 +616,18 @@ void RGBColourPresets() {
616616
ConfigObjMain.sColourGlobal = RGBPreset[nOption - 1].sColourPresetForeground;
617617
ConfigObjMain.sColourGlobalBack = RGBPreset[nOption - 1].sColourPresetBackground;
618618

619-
// Check validity of colours (only works when using WIN32 for now, a parser function for ANSI colours is coming soon)
619+
// Check validity of colours
620620
if (RGBPreset[nOption - 1].CheckIfAnsiPreset() == false) {
621-
if (CheckColourWin32Validity() == false) {
621+
if (ValidateColourStringsWin32() == false) {
622622
bValidColours = false;
623623
}
624624
}
625+
else if (RGBPreset[nOption - 1].CheckIfAnsiPreset() == true) {
626+
if (ValidateColourStringsANSI() == false) {
627+
bValidColours = false;
628+
}
629+
}
630+
625631
}
626632

627633
// Set colours
@@ -640,7 +646,13 @@ void RGBColourPresets() {
640646
{
641647
// Should be safe to change colours as colours have been validated/reset
642648
colour(YLW, ConfigObjMain.sColourGlobalBack);
643-
std::cout << wordWrap("Warning: This preset contains invalid WIN32 values, so one or all of the colours will be set to default to prevent errors.") << std::endl;
649+
if (bAnsiVTSequences) {
650+
std::cout << wordWrap("Warning: This preset contains invalid ANSI string values, so one or all of the colours will be set to default to prevent errors.") << std::endl;
651+
}
652+
else {
653+
std::cout << wordWrap("Warning: This preset contains invalid WIN32 values, so one or all of the colours will be set to default to prevent errors.") << std::endl;
654+
}
655+
644656
}
645657

646658
// Write to config file immediately (for current global colours)
@@ -766,7 +778,7 @@ void help(bool bFromTutorial) {
766778
"This is an early alpha build of ZeeTerminal, with an entirely new engine and components.\nThis program is made in C++, with a few very small parts of C." +
767779
"\n\nThis program uses the DirectShow API in the MediaPlayer command, which is licensed by Microsoft Corporation. (c) Microsoft Corporation.\n\n" +
768780
"This program uses the BASS API in the AudioPlayer command, which is licensed by Un4Seen Developments. (c) Un4Seen Developments.\n\n" +
769-
"\n(c) Ryan Zorkot, 2023. ZeeTerminal is licensed under the MIT License. The license and credits can be viewed on Page 4.\n\n"
781+
"\n(c) Ryan Zorkot, 2024. ZeeTerminal is licensed under the MIT License. The license and credits can be viewed on Page 4.\n\n"
770782
" _____ _____ _ _ \n"
771783
" |__ /___ __|_ _|__ _ __ _ __ ___ (_)_ __ __ _| |\n"
772784
" / // _ \\/ _ \\| |/ _ \\ '__| '_ \\` _ \\| | '_ \\ / _\\` |\n"
@@ -776,7 +788,7 @@ void help(bool bFromTutorial) {
776788

777789
"___LICENSE AND CREDITS___\n\n"
778790
"Massive thank-you to my dad, Hazem Zorkot, for assisting with this project, including with the logo design, name, high-level component ideas, and lots of heads-up messages along the way.\n\n"
779-
"ZeeTerminal is licensed under the MIT License. Below is the license info:\n\nCopyright (c) 2023 Ryan Zorkot\n\n"
791+
"ZeeTerminal is licensed under the MIT License. Below is the license info:\n\nCopyright (c) 2024 Ryan Zorkot\n\n"
780792
"Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal"
781793
" in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell"
782794
" copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n"
@@ -2328,6 +2340,7 @@ void Commands(const std::string sCommand, char* cCommandArgs, const std::string
23282340
else if (sCommand == "stopwatch" || sCommand == "16") {
23292341

23302342
bool bSkipStartScreen = false;
2343+
bool bUserCursorVisibilitySetting = true;
23312344

23322345
// Arguments interface
23332346
for (int i = 0; i < nArgArraySize; i++) {
@@ -2361,6 +2374,10 @@ void Commands(const std::string sCommand, char* cCommandArgs, const std::string
23612374
// Start stopwatch
23622375
std::cout << '\n';
23632376
std::chrono::duration<long double> elapsedSeconds;
2377+
2378+
// Disable cursor visibility
2379+
bUserCursorVisibilitySetting = DisableCursorVisibility();
2380+
23642381
auto start = std::chrono::steady_clock::now();
23652382

23662383
while (!_kbhit()) { // exit on keypress
@@ -2386,6 +2403,10 @@ void Commands(const std::string sCommand, char* cCommandArgs, const std::string
23862403
std::cout << " seconds.\n\n";
23872404

23882405
ClearKeyboardBuffer();
2406+
// Reset cursor visibility to user settings
2407+
ConfigObjMain.bShowCursor = bUserCursorVisibilitySetting;
2408+
SetCursorAttributes();
2409+
23892410
return;
23902411
}
23912412

@@ -2497,8 +2518,8 @@ void Commands(const std::string sCommand, char* cCommandArgs, const std::string
24972518

24982519
// Timer
24992520
else if (sCommand == "timer" || sCommand == "18") {
2500-
25012521
long double dInput = 0;
2522+
bool bUserCursorVisibilitySetting = true;
25022523

25032524
CentreColouredText(" ___TIMER___ ", 1);
25042525
std::cout << '\n';
@@ -2540,6 +2561,9 @@ void Commands(const std::string sCommand, char* cCommandArgs, const std::string
25402561
std::cout << wordWrap("\nPress any key to exit the timer.\n\n");
25412562
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
25422563

2564+
// Disable cursor visibility
2565+
bUserCursorVisibilitySetting = DisableCursorVisibility();
2566+
25432567
std::chrono::duration<long double> elapsedTime{};
25442568
auto start = std::chrono::steady_clock::now();
25452569
auto time = std::chrono::steady_clock::now();
@@ -2584,6 +2608,10 @@ void Commands(const std::string sCommand, char* cCommandArgs, const std::string
25842608
MessageBeep(MB_OK);
25852609
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
25862610

2611+
// Reset cursor visibility to user settings
2612+
ConfigObjMain.bShowCursor = bUserCursorVisibilitySetting;
2613+
SetCursorAttributes();
2614+
25872615
return;
25882616

25892617
}

CommandFiles/Settings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ void AnsiSettings(short int nChoice = 0) {
389389

390390
// Set new colours
391391
ColourTypeSwitch(); // This will write to config file by default
392+
SetCursorAttributes(); // Set cursor attributes in case user was using non-ANSI setting - make cursor attributes correct
392393
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
393394
cls(); // Set colours to whole screen
394395

@@ -419,6 +420,7 @@ void AnsiSettings(short int nChoice = 0) {
419420

420421
// Set new colours
421422
ColourTypeSwitch(); // This will write to config file by default
423+
SetCursorAttributes(); // Set cursor attributes in case user was using ANSI setting - make cursor attributes correct
422424
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
423425
cls(); // Set to whole screen
424426

Definitions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ typedef void* LPVOID;
119119
//
120120
// Define wordWrap function with default arguments
121121
std::string wordWrap(std::string, long long int = -1, long long int = 0);
122+
123+
// Command Asset Function definition - widely used in other engines, so should be defined here
124+
bool DisableCursorVisibility();
125+
122126
//
123127
// The rest \|/
124128
//

Engine/FileOpenGUIEngine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class FileOpenGUIEngine {
7171
IFileOpenDialog* pFileOpen = NULL;
7272
IShellItem* pItem = NULL;
7373

74-
LPWSTR pwszFilePath = NULL;
74+
LPWSTR pwszFilePath = (LPWSTR)"";
7575

7676
// Initialise COM libraries
7777
hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);

Engine/LogFile-System.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class LogFileSystem {
361361
VerbosityDisplay("In LogFileSystem::CreateLogFile(): ERROR - Unknown error on std::ofstream init to log file. Failed to create log file.\n", nObjectID, false, true);
362362

363363
// Log to Windows Log Database
364-
std::vector<std::string> vsErrorInfo{
364+
std::vector<std::string> vsErrorInfo {
365365
"In LogFileSystem::CreateLogFile(): ERROR - Unknown error on std::ofstream init to log file. Failed to create log file.",
366366
"Context: Failed to create and write to new log file, due to out-stream failure.",
367367
"Object ID: " + std::to_string(nObjectID),
@@ -378,7 +378,7 @@ class LogFileSystem {
378378
UpdateProgramInfo();
379379

380380
// 3. Write global log title surrounded with "___", and system/program info
381-
CreateLogFileOut << "___" + sLogFileName + "___\n\n" << sSystemInfoString << "\n" << sProgramInfoString << "\n\n__LOG START__\n# FORMAT: <Time> <Time since program execution> <Object ID> <Message Type> <Info/Message>\n# If the Object ID of a line equates to 10000, there is no object associated with that line.\n# Anything higher than that means that the line is associated with an object.\n\n";
381+
CreateLogFileOut << "# ___" + sLogFileName + "___\n\n" << sSystemInfoString << "\n" << sProgramInfoString << "\n\n# __LOG START__\n# FORMAT: <Time> <Time since program execution> <Object ID> <Message Type> <Info/Message>\n# If the Object ID of a line equates to 10000, there is no object associated with that line.\n# Anything higher than that means that the line is associated with an object.\n\n";
382382

383383
// 4. Exit
384384
CreateLogFileOut.close();

0 commit comments

Comments
 (0)