Don't exit if TERM is not set and color is enabled; setupterm is strange..
This commit is contained in:
parent
097d240feb
commit
3036697004
@ -129,15 +129,20 @@ const char *mpw_hex_l(uint32_t number) {
|
|||||||
#ifdef COLOR
|
#ifdef COLOR
|
||||||
static int putvari;
|
static int putvari;
|
||||||
static char *putvarc = NULL;
|
static char *putvarc = NULL;
|
||||||
static int istermsetup = 0;
|
static int termsetup = ERR;
|
||||||
static void initputvar() {
|
static int initputvar() {
|
||||||
|
if (!isatty(STDERR_FILENO))
|
||||||
|
return 0;
|
||||||
if (putvarc)
|
if (putvarc)
|
||||||
free(putvarc);
|
free(putvarc);
|
||||||
|
if (termsetup != OK)
|
||||||
|
setupterm(NULL, STDERR_FILENO, &termsetup);
|
||||||
|
if (termsetup != OK)
|
||||||
|
return 0;
|
||||||
|
|
||||||
putvarc=(char *)calloc(256, sizeof(char));
|
putvarc=(char *)calloc(256, sizeof(char));
|
||||||
putvari=0;
|
putvari=0;
|
||||||
|
return 1;
|
||||||
if (!istermsetup)
|
|
||||||
istermsetup = (OK == setupterm(NULL, STDERR_FILENO, NULL));
|
|
||||||
}
|
}
|
||||||
static int putvar(int c) {
|
static int putvar(int c) {
|
||||||
putvarc[putvari++]=c;
|
putvarc[putvari++]=c;
|
||||||
@ -161,9 +166,8 @@ const char *mpw_identicon(const char *fullName, const char *masterPassword) {
|
|||||||
|
|
||||||
char *colorString, *resetString;
|
char *colorString, *resetString;
|
||||||
#ifdef COLOR
|
#ifdef COLOR
|
||||||
if (isatty( STDERR_FILENO )) {
|
if (initputvar()) {
|
||||||
uint8_t colorIdentifier = (uint8_t)(identiconSeed[4] % 7 + 1);
|
uint8_t colorIdentifier = (uint8_t)(identiconSeed[4] % 7 + 1);
|
||||||
initputvar();
|
|
||||||
tputs(tparm(tgetstr("AF", NULL), colorIdentifier), 1, putvar);
|
tputs(tparm(tgetstr("AF", NULL), colorIdentifier), 1, putvar);
|
||||||
colorString = calloc(strlen(putvarc) + 1, sizeof(char));
|
colorString = calloc(strlen(putvarc) + 1, sizeof(char));
|
||||||
strcpy(colorString, putvarc);
|
strcpy(colorString, putvarc);
|
||||||
|
Loading…
Reference in New Issue
Block a user