2021-08-15 18:42:37 +00:00
|
|
|
// texteffects.c: Implementation of text effect library for SilverMUD.
|
|
|
|
// Barry Kane, 2021.
|
|
|
|
#include <stdio.h>
|
2022-10-16 15:13:33 +00:00
|
|
|
#include <ctype.h>
|
2021-08-15 18:42:37 +00:00
|
|
|
#include <unistd.h>
|
2021-09-03 17:47:11 +00:00
|
|
|
#include <ncurses.h>
|
2021-08-15 18:42:37 +00:00
|
|
|
|
2021-08-19 22:07:58 +00:00
|
|
|
void slowPrint(char * stringToPrint, int delay)
|
2021-08-15 18:42:37 +00:00
|
|
|
{
|
|
|
|
int characterIndex = 0;
|
|
|
|
while(stringToPrint[characterIndex] != '\0')
|
|
|
|
{
|
|
|
|
putchar(stringToPrint[characterIndex]);
|
|
|
|
// Flush the buffer so there's no line buffering.
|
|
|
|
fflush(stdout);
|
|
|
|
usleep(delay);
|
|
|
|
characterIndex++;
|
|
|
|
}
|
|
|
|
}
|
2021-09-03 17:47:11 +00:00
|
|
|
|
2022-03-15 14:52:49 +00:00
|
|
|
void slowPrintNcurses(char * stringToPrint, int delay, WINDOW * window, bool bolded)
|
2021-09-03 17:47:11 +00:00
|
|
|
{
|
|
|
|
int characterIndex = 0;
|
2022-03-15 14:52:49 +00:00
|
|
|
if(bolded)
|
|
|
|
{
|
|
|
|
wattron(window, A_BOLD);
|
|
|
|
}
|
2021-09-03 17:47:11 +00:00
|
|
|
while(stringToPrint[characterIndex] != '\0')
|
|
|
|
{
|
2021-09-10 14:03:02 +00:00
|
|
|
waddch(window, stringToPrint[characterIndex]);
|
2021-09-03 17:47:11 +00:00
|
|
|
// Refresh the ncurses screen.
|
2021-09-10 14:03:02 +00:00
|
|
|
wrefresh(window);
|
2021-09-03 17:47:11 +00:00
|
|
|
usleep(delay);
|
|
|
|
characterIndex++;
|
|
|
|
}
|
2022-03-15 14:52:49 +00:00
|
|
|
if(bolded)
|
|
|
|
{
|
|
|
|
wattroff(window, A_BOLD);
|
|
|
|
}
|
2021-09-10 14:03:02 +00:00
|
|
|
wrefresh(window);
|
2021-09-03 17:47:11 +00:00
|
|
|
}
|
2022-10-16 15:13:33 +00:00
|
|
|
|
2022-10-18 20:00:57 +00:00
|
|
|
void bruteforcePrint(char * stringToPrint, int delay)
|
|
|
|
{
|
|
|
|
unsigned int characterIndex = 0;
|
|
|
|
while(stringToPrint[characterIndex] != '\0')
|
|
|
|
{
|
|
|
|
for(unsigned char currentCharacter = 32; currentCharacter <= stringToPrint[characterIndex]; currentCharacter++)
|
|
|
|
{
|
|
|
|
putchar(stringToPrint[currentCharacter]);
|
|
|
|
fflush(stdout);
|
|
|
|
usleep(delay);
|
|
|
|
putchar(8);
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
putchar(stringToPrint[characterIndex]);
|
|
|
|
characterIndex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bruteforcePrintNcurses(char * stringToPrint, int delay, WINDOW * window, bool bolded)
|
2022-10-16 15:13:33 +00:00
|
|
|
{
|
|
|
|
int characterIndex = 0;
|
|
|
|
if(bolded)
|
|
|
|
{
|
|
|
|
wattron(window, A_BOLD);
|
|
|
|
}
|
|
|
|
while(stringToPrint[characterIndex] != '\0')
|
|
|
|
{
|
|
|
|
for(char currentCharacter = 32; currentCharacter <= stringToPrint[characterIndex]; currentCharacter++)
|
|
|
|
{
|
|
|
|
waddch(window, currentCharacter);
|
|
|
|
wrefresh(window);
|
|
|
|
usleep(delay);
|
|
|
|
waddch(window, 8);
|
|
|
|
wrefresh(window);
|
|
|
|
}
|
|
|
|
waddch(window, stringToPrint[characterIndex]);
|
|
|
|
characterIndex++;
|
|
|
|
}
|
|
|
|
if(bolded)
|
|
|
|
{
|
|
|
|
wattroff(window, A_BOLD);
|
|
|
|
}
|
|
|
|
wrefresh(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
void wrapString(char * stringToWrap, int stringLength, int screenWidth)
|
|
|
|
{
|
|
|
|
int characterCount = 0;
|
|
|
|
for(int index = 0; index < stringLength; index++)
|
|
|
|
{
|
|
|
|
if(stringToWrap[index] == '\n')
|
|
|
|
{
|
|
|
|
characterCount = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
characterCount++;
|
|
|
|
}
|
|
|
|
if(characterCount == screenWidth)
|
|
|
|
{
|
|
|
|
while(!isspace(stringToWrap[index]) && index > 0)
|
|
|
|
{
|
|
|
|
index--;
|
|
|
|
}
|
|
|
|
if(index == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
stringToWrap[index] = '\n';
|
|
|
|
index++;
|
|
|
|
characterCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|