Refactoring ASCCI-Art image printing

This commit is contained in:
Andreas Eversberg 2021-09-24 16:09:19 +02:00
parent f7d4eb961e
commit 5bdc4d2f18
5 changed files with 86 additions and 5 deletions

7
libaaimage/Makefile.am Normal file
View File

@ -0,0 +1,7 @@
AM_CPPFLAGS = -Wall -Wextra -g $(all_includes)
noinst_LIBRARIES = libaaimage.a
libaaimage_a_SOURCES = \
aaimage.c

74
libaaimage/aaimage.c Normal file
View File

@ -0,0 +1,74 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "aaimage.h"
extern const char *aaimage[];
void print_aaimage(void)
{
int i, j;
for (i = 0; aaimage[i]; i++) {
for (j = 0; j < (int)strlen(aaimage[i]); j++) {
if (aaimage[i][j] == '@') {
j++;
switch(aaimage[i][j]) {
case 'k': /* black */
printf("\033[0;30m");
break;
case 'r': /* red */
printf("\033[0;31m");
break;
case 'g': /* green */
printf("\033[0;32m");
break;
case 'y': /* yellow */
printf("\033[0;33m");
break;
case 'b': /* blue */
printf("\033[0;34m");
break;
case 'm': /* magenta */
printf("\033[0;35m");
break;
case 'c': /* cyan */
printf("\033[0;36m");
break;
case 'w': /* white */
printf("\033[0;37m");
break;
case 'K': /* bright black */
printf("This will not work on some terminals, please use 'w'\n");
abort();
case 'R': /* bright red */
printf("\033[1;31m");
break;
case 'G': /* bright green */
printf("\033[1;32m");
break;
case 'Y': /* bright yellow */
printf("\033[1;33m");
break;
case 'B': /* bright blue */
printf("\033[1;34m");
break;
case 'M': /* bright magenta */
printf("\033[1;35m");
break;
case 'C': /* bright cyan */
printf("\033[1;36m");
break;
case 'W': /* bright white */
printf("\033[1;37m");
break;
}
} else
printf("%c", aaimage[i][j]);
}
printf("\n");
}
printf("\033[0;39m");
}

3
libaaimage/aaimage.h Normal file
View File

@ -0,0 +1,3 @@
void print_aaimage(void);

View File

@ -1,3 +0,0 @@
void print_image(void);

View File

@ -41,7 +41,7 @@
#endif
#include "../liboptions/options.h"
#include "../libfm/fm.h"
#include "image.h"
#include "../libaaimage/aaimage.h"
#define DEFAULT_LO_OFFSET -1000000.0
@ -519,7 +519,7 @@ void main_mobile(const char *name, int *quit, void (*myhandler)(void), const cha
return;
if (!loopback)
print_image();
print_aaimage();
/* real time priority */
if (rt_prio > 0) {