Skip to content

Commit 38d3fdd

Browse files
### Quality Control Improvements for Update v0.9.0:
- QC: Improved formatting and representation of different units in the converter commands. - QC: Fixed issue where in the Horsepower to Kilowatts converter, the inputted horsepower value would be the same as the outputted kilowatts value. - QC: In a couple of converters in the Converter command, an issue was fixed where inputted values would be converted to whole numbers instead of being accepted as a floating-point number. Fixed by using NumInputld() instead of NumInputll(). - QC: Fixed an issue in the RandNum command, where when the -f argument is specified, a whole number is still calculated instead of a floating-point. - QC: Improved formatting of the help page of the Title command. - QC: Changed max character limit from 256 characters to 254 characters in the Title command, to comply with the Window Title ANSI Escape Sequence limit. - QC: Fixed a bug where supplying no data string arguments to a ToFile-enabled command would cause UB across the entire program. - QC: When the ToFile feature is enabled, the std::cerr stream will redirect to the set file now, along with std::cout.
1 parent d6a48ad commit 38d3fdd

File tree

6 files changed

+56
-46
lines changed

6 files changed

+56
-46
lines changed

CommandFiles/CommandHelpMessages.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,12 @@ namespace helpmsgs
218218
colourSubheading();
219219
std::cout << "What this command does:" << NOULINE_STR;
220220
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
221-
std::cout << wordWrap("\n- This command allows you to set the title of this window, which is the window running ZeeTerminal.\n- The title can only be a maximum of 256 characters.\n\n");
221+
std::cout << wordWrap("\n- This command allows you to set the title of this window, which is the window running ZeeTerminal.\n- The title can only be a maximum of 254 characters.\n\n");
222222

223223
colourSubheading();
224224
std::cout << "Possible arguments for this command:" << NOULINE_STR;
225225
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
226-
std::cout << wordWrap("\n -h\tDisplays this help message.\n <title>\tThe title to set. Put the title in place of <title>.\n\nExample: title \"Test Title\"\n\nNOTE: If the title contains spaces, use quotes like the example.\n\n");
226+
std::cout << wordWrap("\n -h\t\tDisplays this help message.\n <title>\tThe title to set. Put the title in place of <title>.\n\nExample: title \"Test Title\"\n\nNOTE: If the title contains spaces, use quotes like the example.\n\n");
227227

228228
return;
229229
}

CommandFiles/CommandsFiles/CommandsFile_1to10.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ bool commands::Commands1To10(const std::string sCommand, char* cCommandArgs, con
965965
std::cout << "\n";
966966

967967
// Take title input
968-
sTitle = StrInput("Please input your desired title (256 characters max): > ");
968+
sTitle = StrInput("Please input your desired title (254 characters max): > ");
969969
}
970970

971971
// Set the window title
@@ -976,7 +976,7 @@ bool commands::Commands1To10(const std::string sCommand, char* cCommandArgs, con
976976
}
977977
else {
978978
// Failed - too long of a string
979-
UserErrorDisplay("Setting console window title failed!\nPlease check if your title is too long. It cannot be longer than 256 characters.\n");
979+
UserErrorDisplay("Setting console window title failed!\nPlease check if your title is too long. It cannot be longer than 254 characters.\n");
980980
}
981981

982982
return true;

CommandFiles/CommandsFiles/CommandsFile_61to70.cpp

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ bool commands::Commands61To70(const std::string sCommand, char* cCommandArgs, co
272272
// RandNum
273273
else if (sCommand == "randnum" || sCommand == "62") {
274274
bool bCalculateFloatingPoint = false;
275-
int64_t nMaxNumber = 0;
276-
int64_t nMinNumber = 0;
275+
long double nMaxNumber = 0;
276+
long double nMinNumber = 0;
277277
bool bFromArgument = false;
278278

279279
// Arguments Interface
@@ -285,16 +285,16 @@ bool commands::Commands61To70(const std::string sCommand, char* cCommandArgs, co
285285
else if (cCommandArgs[i] == 'f') {
286286
bCalculateFloatingPoint = true;
287287
}
288-
288+
289289
// Max-min arguments
290290
if (sStringDataCommandArgs[0] != "") {
291291
if (sStringDataCommandArgs[1] != "") {
292292
// Convert min argument to 64-bit integer and check
293-
if (isNumberll(sStringDataCommandArgs[1])) {
294-
nMinNumber = std::stoll(sStringDataCommandArgs[1]);
293+
if (isNumberld(sStringDataCommandArgs[1])) {
294+
nMinNumber = std::stold(sStringDataCommandArgs[1]);
295295
}
296296
else {
297-
VerbosityDisplay("In Commands61To70() - ERROR: Could not detect numerical value in string-based number argument, due to isNumberll fail.\n");
297+
VerbosityDisplay("In Commands61To70() - ERROR: Could not detect numerical value in string-based number argument, due to isNumberld fail.\n");
298298
UserErrorDisplay("ERROR - Your minimum number generation boundary argument is invalid. Please try again.\nSee \"randnum -h\" for more info.\n");
299299

300300
return true;
@@ -306,13 +306,13 @@ bool commands::Commands61To70(const std::string sCommand, char* cCommandArgs, co
306306

307307
return true;
308308
}
309-
309+
310310
// Convert max argument to 64-bit integer and check
311-
if (isNumberll(sStringDataCommandArgs[0])) {
312-
nMaxNumber = std::stoll(sStringDataCommandArgs[0]);
311+
if (isNumberld(sStringDataCommandArgs[0])) {
312+
nMaxNumber = std::stold(sStringDataCommandArgs[0]);
313313
}
314314
else {
315-
VerbosityDisplay("In Commands61To70() - ERROR: Could not detect numerical value in string-based number argument, due to isNumberll fail.\n");
315+
VerbosityDisplay("In Commands61To70() - ERROR: Could not detect numerical value in string-based number argument, due to isNumberld fail.\n");
316316
UserErrorDisplay("ERROR - Your maximum number generation boundary argument is invalid. Please try again.\nSee \"randnum -h\" for more info.\n");
317317

318318
return true;
@@ -331,8 +331,8 @@ bool commands::Commands61To70(const std::string sCommand, char* cCommandArgs, co
331331
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
332332

333333
while (true) {
334-
nMaxNumber = NumInputll("Please input the maximum boundary for the generator: > ");
335-
nMinNumber = NumInputll("Please input the minimum boundary for the generator: > ");
334+
nMaxNumber = NumInputld("Please input the maximum boundary for the generator: > ");
335+
nMinNumber = NumInputld("Please input the minimum boundary for the generator: > ");
336336

337337
// Check if max boundary is less than minimum boundary
338338
if (nMaxNumber < nMinNumber) {
@@ -351,22 +351,20 @@ bool commands::Commands61To70(const std::string sCommand, char* cCommandArgs, co
351351
return true;
352352
}
353353

354-
// Calculate random number and output result
354+
long double dCalculatedNumber = 0.0;
355355
if (bCalculateFloatingPoint == true) {
356-
// Calculate using RandNumld (floating-point)
357-
std::cout << "Final Calculated Number: ";
358-
colour(LCYN, ConfigObjMain.sColourGlobalBack);
359-
std::cout << RandNumld(nMaxNumber, nMinNumber) << "\n";
360-
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
356+
dCalculatedNumber = RandNumld(nMaxNumber, nMinNumber);
361357
}
362358
else {
363-
// Calculate using RandNumll (integral)
364-
std::cout << "Final Calculated Number: ";
365-
colour(LCYN, ConfigObjMain.sColourGlobalBack);
366-
std::cout << RandNumll(nMaxNumber, nMinNumber) << "\n";
367-
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
359+
dCalculatedNumber = RandNumll(nMaxNumber, nMinNumber);
368360
}
369361

362+
// Display result for calculated number
363+
std::cout << "Final Calculated Number: ";
364+
colour(LCYN, ConfigObjMain.sColourGlobalBack);
365+
std::cout << dCalculatedNumber << "\n";
366+
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
367+
370368
return true;
371369
}
372370

CommandFiles/ConverterAssets/ConverterAssets.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ namespace converter
365365
slowcolourfn(ConfigObjMain.sColourSubheading, ConfigObjMain.sColourSubheadingBack, "Welcome to the Seconds to Other Time Types Converter!");
366366
std::cout << "\n\n";
367367
while (true) {
368-
dSeconds = NumInputll("Please input the seconds value that you want to convert: > ");
368+
dSeconds = NumInputld("Please input the seconds value that you want to convert: > ");
369369

370370
// Negative numbers are not allowed
371371
if (dSeconds < 0) {
@@ -413,7 +413,7 @@ namespace converter
413413
slowcolourfn(ConfigObjMain.sColourSubheading, ConfigObjMain.sColourSubheadingBack, "Welcome to the Kilowatts to Horsepower Converter!");
414414
std::cout << "\n\n";
415415
while (true) {
416-
dKilowatts = NumInputll("Please input the kilowatts value that you want to convert: > ");
416+
dKilowatts = NumInputld("Please input the kilowatts value that you want to convert: > ");
417417

418418
// Negative numbers are not allowed
419419
if (dKilowatts < 0) {
@@ -438,7 +438,7 @@ namespace converter
438438
colourSubheading();
439439
std::cout << "Results:" << NOULINE_STR;
440440
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
441-
std::cout << "\n\nInputted kilowatt value: " << dKilowatts << "\nConverted horsepower value: " << dHorsepower << "\n\n";
441+
std::cout << "\n\nInputted kilowatt value: " << dKilowatts << "kw\nConverted horsepower value: " << dHorsepower << "hp\n\n";
442442

443443
return;
444444
}
@@ -447,10 +447,10 @@ namespace converter
447447
void HorsepowerToKilowatts(long double dHorsepower, bool bFromArgument) {
448448
// Prompt
449449
if (!bFromArgument) {
450-
slowcolourfn(ConfigObjMain.sColourSubheading, ConfigObjMain.sColourSubheadingBack, "Welcome to Horsepower to Kilowatts Converter!");
450+
slowcolourfn(ConfigObjMain.sColourSubheading, ConfigObjMain.sColourSubheadingBack, "Welcome to the Horsepower to Kilowatts Converter!");
451451
std::cout << "\n\n";
452452
while (true) {
453-
dHorsepower = NumInputll("Please input the horsepower value that you want to convert: > ");
453+
dHorsepower = NumInputld("Please input the horsepower value that you want to convert: > ");
454454

455455
// Negative numbers are not allowed
456456
if (dHorsepower < 0) {
@@ -475,7 +475,7 @@ namespace converter
475475
colourSubheading();
476476
std::cout << "Results:" << NOULINE_STR;
477477
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
478-
std::cout << "\n\nInputted horsepower value: " << dKilowatts << "\nConverted kilowatt value: " << dKilowatts << "\n\n";
478+
std::cout << "\n\nInputted horsepower value: " << dHorsepower << "hp\nConverted kilowatt value: " << dKilowatts << "kw\n\n";
479479

480480
return;
481481
}
@@ -487,7 +487,7 @@ namespace converter
487487
slowcolourfn(ConfigObjMain.sColourSubheading, ConfigObjMain.sColourSubheadingBack, "Welcome to the Light-Years to Kilometres Converter!");
488488
std::cout << "\n\n";
489489
while (true) {
490-
dLightYears = NumInputll("Please input the light-years value that you want to convert: > ");
490+
dLightYears = NumInputld("Please input the light-years value that you want to convert: > ");
491491

492492
// Negative numbers are not allowed
493493
if (dLightYears < 0) {
@@ -512,7 +512,7 @@ namespace converter
512512
colourSubheading();
513513
std::cout << "Results:" << NOULINE_STR;
514514
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
515-
std::cout << "\n\nInputted light-years value: " << dLightYears << "\nConverted kilometres value: " << dKilometres << "\n\n";
515+
std::cout << "\n\nInputted light-years value: " << dLightYears << " light-years\nConverted kilometres value: " << dKilometres << "km\n\n";
516516

517517
return;
518518
}
@@ -524,7 +524,7 @@ namespace converter
524524
slowcolourfn(ConfigObjMain.sColourSubheading, ConfigObjMain.sColourSubheadingBack, "Welcome to the Kilometres to Light-Years Converter!");
525525
std::cout << "\n\n";
526526
while (true) {
527-
dKilometres = NumInputll("Please input the kilometres value that you want to convert: > ");
527+
dKilometres = NumInputld("Please input the kilometres value that you want to convert: > ");
528528

529529
// Negative numbers are not allowed
530530
if (dKilometres < 0) {
@@ -549,7 +549,7 @@ namespace converter
549549
colourSubheading();
550550
std::cout << "Results:" << NOULINE_STR;
551551
colour(ConfigObjMain.sColourGlobal, ConfigObjMain.sColourGlobalBack);
552-
std::cout << "\n\nInputted kilometres value: " << dKilometres << "\nConverted light-years value: " << dLightYears << "\n\n";
552+
std::cout << "\n\nInputted kilometres value: " << dKilometres << "km\nConverted light-years value: " << dLightYears << " light-years\n\n";
553553

554554
return;
555555
}

Core/ZeeTerminalCore.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ namespace zt {
212212
std::random_device rdRandNum;
213213

214214
// distribution in range [min, max]
215-
std::uniform_real_distribution<> dist(min, max);
215+
std::uniform_real_distribution<long double> dist(min, max);
216216

217217
return dist(rdRandNum);
218218
}
@@ -1104,8 +1104,9 @@ namespace zt {
11041104
// Parameters: sTitle for the title string.
11051105
bool SetWindowTitle(std::string sTitle) {
11061106
if (bAnsiVTSequences) {
1107-
if (sTitle.length() > 256) {
1108-
VerbosityDisplay("ERROR: In SetWindowTitle() - String argument incorrect due to ANSI 256 max string char limit for title.\n");
1107+
if (sTitle.length() > 254) {
1108+
VerbosityDisplay("ERROR: In SetWindowTitle() - String argument incorrect due to ANSI 254 max string char limit for title.\n");
1109+
return false;
11091110
}
11101111

11111112
// Use ANSI VT sequences if they work on current terminal
@@ -1117,7 +1118,7 @@ namespace zt {
11171118
return true;
11181119
}
11191120
else {
1120-
VerbosityDisplay("ERROR: In SetWindowTitle() - String argument incorrect due to WIN32 API 256 max string char limit for title.\n");
1121+
VerbosityDisplay("ERROR: In SetWindowTitle() - String argument incorrect due to WIN32 API 254 max string char limit for title.\n");
11211122
return false;
11221123
}
11231124
}

ZeeTerminal.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,9 @@ int main(int argc, char* argv[])
354354

355355
// Declare fileout stream for ToFile feature
356356
std::ofstream ToFile_Out{};
357-
// Declare std::streambuf variable so that just in case tofile feature is enabled, the previous stdout buffer can be saved
357+
// Declare std::streambuf variables so that just in case tofile feature is enabled, the previous stdout buffer can be saved
358358
std::streambuf* coutStreambufBuffer{};
359+
std::streambuf* cerrStreambufBuffer{};
359360

360361
/* The following will be based on parsing sCommandArgsBuffer for the actual arguments. */
361362
// Copy the string option arguments into sStringOptionCommandArgs with correct formatting
@@ -552,8 +553,11 @@ int main(int argc, char* argv[])
552553
if (bToFileFeatureActivated == true) {
553554
// Get index of last string in data string array by calculating its array size
554555
size_t nLastDataStringArrayMemberIndex = 0;
555-
for (nLastDataStringArrayMemberIndex = nArgArraySize - 1; nLastDataStringArrayMemberIndex >= 0 && sStringDataCommandArgs[nLastDataStringArrayMemberIndex] == ""; nLastDataStringArrayMemberIndex--) {}
556-
556+
for (nLastDataStringArrayMemberIndex = nArgArraySize - 1; sStringDataCommandArgs[nLastDataStringArrayMemberIndex] == ""; nLastDataStringArrayMemberIndex--) {
557+
if (sStringDataCommandArgs[nLastDataStringArrayMemberIndex] == "" && nLastDataStringArrayMemberIndex == 0) {
558+
break;
559+
}
560+
}
557561
// Open file using std::ofstream object and the filepath to be the last data string in the data string array
558562
ToFile_Out.open(sStringDataCommandArgs[nLastDataStringArrayMemberIndex]);
559563

@@ -568,11 +572,17 @@ int main(int argc, char* argv[])
568572
ToFile_Out.close();
569573
}
570574
else {
571-
// Save old buffer
575+
// Save old buffer for std::cout
572576
coutStreambufBuffer = std::cout.rdbuf();
573577

574-
// Redirect stdout to the new stream
578+
// Redirect std::cout to the new stream
575579
std::cout.rdbuf(ToFile_Out.rdbuf());
580+
581+
// Save old buffer for std::cerr
582+
cerrStreambufBuffer = std::cerr.rdbuf();
583+
584+
// Redirect std::cerr to the new stream
585+
std::cerr.rdbuf(ToFile_Out.rdbuf());
576586
}
577587
}
578588

@@ -588,6 +598,7 @@ int main(int argc, char* argv[])
588598

589599
// Undo the streambuf modifications
590600
std::cout.rdbuf(coutStreambufBuffer);
601+
std::cerr.rdbuf(cerrStreambufBuffer);
591602

592603
// Close the file stream
593604
ToFile_Out.close();

0 commit comments

Comments
 (0)