Study Dungeon  1.0.0
A group project for COSC345
Functions | Variables
util.cpp File Reference

Utilities and helpers for the program. More...

#include "util.h"

Functions

bool enableVirtualTerminal ()
 enables the virtual terminal processing mode More...
 
std::filesystem::path getAppPath ()
 
bool timeComplete (const std::chrono::time_point< std::chrono::steady_clock > &start_time, const int &duration_secs)
 Determines if the number of seconds has elapased since a start time. More...
 
int timeRemainingMins (const std::chrono::time_point< std::chrono::steady_clock > &start_time, const int &duration_mins)
 Used to display the time remaining to users. To determine the actual end the session use timeComplete() More...
 
std::string steadyClockToString (const std::chrono::steady_clock::time_point &start_time)
 Gives the number of seconds past since the time point as "X seconds since start". More...
 
void pause ()
 An alternative to system('pause') More...
 
void clearScreen ()
 Clears the screen. More...
 
bool yesNoPrompt ()
 Prompts the user to enter [Yy] for yes and [Nn] for no. More...
 
bool isValidDeckFileName (const std::string &name)
 Checks if name for deckfile meets naming requirements. More...
 
void ShowConsoleCursor (bool showFlag)
 hides or shows the cursor icon in the console
 
std::vector< std::vector< int > > readInANSICodes (std::string filename)
 reads a file of integers (0-255) that will be used to create ANSI colours More...
 
std::vector< std::string > convertAsciiArtToLines (const std::string &asciiArt)
 Vectorises a string on the newline character. More...
 
std::string getFirstPhrase (const std::vector< std::pair< std::string, int >> &phrases)
 
std::string getRandomPositiveQuote ()
 Get a Random Positive Quote. More...
 
std::string getRandomEncouragingQuote ()
 Get a Random Encouraging Quote. More...
 
std::string getRandomPhrase ()
 Get a Random Phrase. More...
 

Variables

bool isTestMode = false
 

Detailed Description

Utilities and helpers for the program.

Author
Green Alligators
Version
1.0.0
Date
2024-09-19

Function Documentation

◆ clearScreen()

void clearScreen ( )

Clears the screen.

Credit: SirEnder125 on cplusplus.com

◆ convertAsciiArtToLines()

std::vector<std::string> convertAsciiArtToLines ( const std::string &  asciiArt)

Vectorises a string on the newline character.

Parameters
asciiArtString of an ASCII artwork to be vectorised
Returns
std::vector<std::string>

◆ enableVirtualTerminal()

bool enableVirtualTerminal ( )

enables the virtual terminal processing mode

sets the ENABLE_VIRTUAL_TERMINAL_PROCESSING flag so that virtual terminal sequences will be interpreted by the console to display colour and formatting

◆ getRandomEncouragingQuote()

std::string getRandomEncouragingQuote ( )

Get a Random Encouraging Quote.

Returns
std::string

◆ getRandomPhrase()

std::string getRandomPhrase ( )

Get a Random Phrase.

Returns
std::string

◆ getRandomPositiveQuote()

std::string getRandomPositiveQuote ( )

Get a Random Positive Quote.

Returns
std::string

◆ isValidDeckFileName()

bool isValidDeckFileName ( const std::string &  name)

Checks if name for deckfile meets naming requirements.

Deck filenames should only contain [A-Za-z0-9] characters

Parameters
name
Returns
true is a valid file name for a deck
false is not a valid file name a deck

◆ pause()

void pause ( )

An alternative to system('pause')

implementation based on from https://thelinuxcode.com/system-pause-c/

◆ readInANSICodes()

std::vector<std::vector<int> > readInANSICodes ( std::string  filename)

reads a file of integers (0-255) that will be used to create ANSI colours

Parameters
filenamethe file containing whitespace separated integers representing ANSI colours
Returns
std::vector<std::vector<int>>

◆ steadyClockToString()

std::string steadyClockToString ( const std::chrono::steady_clock::time_point &  start_time)

Gives the number of seconds past since the time point as "X seconds since start".

Parameters
start_timea timepoint to turn into a string
Returns
std::string

◆ timeComplete()

bool timeComplete ( const std::chrono::time_point< std::chrono::steady_clock > &  start_time,
const int &  duration_secs 
)

Determines if the number of seconds has elapased since a start time.

Parameters
start_timethe time to count number of seconds from
duration_secstime period to check has elapsed
Returns
true for the duration having passed since the start time, otherwise false.

◆ timeRemainingMins()

int timeRemainingMins ( const std::chrono::time_point< std::chrono::steady_clock > &  start_time,
const int &  duration_mins 
)

Used to display the time remaining to users. To determine the actual end the session use timeComplete()

Parameters
start_timeThe time the timer started
duration_minsthe period in minutes to check how much from the start time is remaining
Returns
int

◆ yesNoPrompt()

bool yesNoPrompt ( )

Prompts the user to enter [Yy] for yes and [Nn] for no.

Returns
true for [Yy]
false for [Nn]

Variable Documentation

◆ isTestMode

bool isTestMode = false

used to toggle between simulated input (true) and user input (false)