make ty* fail nicely when in tmux/screen

This commit is contained in:
Boris Faure 2016-07-30 16:31:56 +02:00
parent e549612ab2
commit 0e0105e559
9 changed files with 80 additions and 13 deletions

View File

@ -63,43 +63,48 @@ gravatar.c gravatar.h \
tty_keys.h
tybg_SOURCES = \
tycommon.c \
tybg.c
tybg_CPPFLAGS = -I. \
-DPACKAGE_BIN_DIR=\"$(bindir)\" -DPACKAGE_LIB_DIR=\"$(libdir)\" \
-DPACKAGE_DATA_DIR=\"$(pkgdatadir)\"
-DPACKAGE_DATA_DIR=\"$(pkgdatadir)\" @TERMINOLOGY_CFLAGS@
tybg_LDADD =
tyalpha_SOURCES = \
tycommon.c \
tyalpha.c
tyalpha_CPPFLAGS = -I. \
-DPACKAGE_BIN_DIR=\"$(bindir)\" -DPACKAGE_LIB_DIR=\"$(libdir)\" \
-DPACKAGE_DATA_DIR=\"$(pkgdatadir)\"
-DPACKAGE_DATA_DIR=\"$(pkgdatadir)\" @TERMINOLOGY_CFLAGS@
tyalpha_LDADD =
typop_SOURCES = \
tycommon.c \
typop.c
typop_CPPFLAGS = -I. \
-DPACKAGE_BIN_DIR=\"$(bindir)\" -DPACKAGE_LIB_DIR=\"$(libdir)\" \
-DPACKAGE_DATA_DIR=\"$(pkgdatadir)\"
-DPACKAGE_DATA_DIR=\"$(pkgdatadir)\" @TERMINOLOGY_CFLAGS@
typop_LDADD =
tyq_SOURCES = \
tycommon.c \
tyq.c
tyq_CPPFLAGS = -I. \
-DPACKAGE_BIN_DIR=\"$(bindir)\" -DPACKAGE_LIB_DIR=\"$(libdir)\" \
-DPACKAGE_DATA_DIR=\"$(pkgdatadir)\"
-DPACKAGE_DATA_DIR=\"$(pkgdatadir)\" @TERMINOLOGY_CFLAGS@
tyq_LDADD =
tycat_SOURCES = \
tycat.c \
tycommon.c \
extns.c extns.h
tycat_CPPFLAGS = -I. \
@ -110,6 +115,7 @@ tycat_LDADD = @TERMINOLOGY_LIBS@
tyls_SOURCES = \
tyls.c \
tycommon.c \
extns.h
tyls_CPPFLAGS = -I. \

View File

@ -4,12 +4,16 @@
#include <unistd.h>
#include <string.h>
#include <Eina.h>
#include "tycommon.h"
int
main(int argc, char **argv)
{
int i, perm = 0;
if (!getenv("TERMINOLOGY")) return 0;
ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1();
if (argc <= 1)
{
printf("Usage: %s [-p] on|off|<opacity level>\n"

View File

@ -4,12 +4,17 @@
#include <unistd.h>
#include <string.h>
#include <Eina.h>
#include "tycommon.h"
int
main(int argc, char **argv)
{
int i, perm = 0;
if (!getenv("TERMINOLOGY")) return 0;
ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1();
if (argc > 1 &&
(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))
{

View File

@ -11,6 +11,8 @@
#include <unistd.h>
#include <string.h>
#include "tycommon.h"
enum {
CENTER,
FILL,
@ -308,7 +310,8 @@ main(int argc, char **argv)
char *rp;
Eina_List *file_q = NULL;
if (!getenv("TERMINOLOGY")) return 0;
ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1();
if (argc <= 1)
{
print_usage(argv[0]);

21
src/bin/tycommon.c Normal file
View File

@ -0,0 +1,21 @@
#include <stdlib.h>
#include <Eina.h>
#include "tycommon.h"
Eina_Bool
is_running_in_terminology(void)
{
if (!getenv("TERMINOLOGY"))
return EINA_FALSE;
// Terminology's escape codes do not got through tmux
if (getenv("TMUX"))
return EINA_FALSE;
// Terminology's escape codes do not got through screen
if (getenv("STY"))
return EINA_FALSE;
return EINA_TRUE;
}

18
src/bin/tycommon.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef _TY_COMMON_H__
#define _TY_COMMON_H__ 1
Eina_Bool is_running_in_terminology(void);
#define ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1() \
do \
{ \
if (!is_running_in_terminology()) \
{ \
fprintf(stderr, "not running in terminology\n"); \
exit(1); \
} \
} \
while (0)
#endif

View File

@ -11,6 +11,7 @@
#include <unistd.h>
#include <string.h>
#include <fnmatch.h>
#include "tycommon.h"
// this code sucks. just letting you know... in advance... in case you
// might be tempted to think otherwise... :)
@ -725,8 +726,9 @@ main(int argc, char **argv)
char *path;
Eina_List *dirs = NULL;
Tyls_Options options = {SMALL, EINA_FALSE};
if (!getenv("TERMINOLOGY")) return 0;
ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1();
if ((argc == 2) && (!strcmp(argv[1], "-h")))
{
printf("Usage: %s [-a] [-s|-m] FILE1 [FILE2 ...]\n"

View File

@ -4,12 +4,16 @@
#include <unistd.h>
#include <string.h>
#include <Eina.h>
#include "tycommon.h"
int
main(int argc, char **argv)
{
int i;
if (!getenv("TERMINOLOGY")) return 0;
ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1();
if (argc <= 1)
{
printf("Usage: %s FILE1 [FILE2 ...]\n"

View File

@ -4,12 +4,16 @@
#include <unistd.h>
#include <string.h>
#include <Eina.h>
#include "tycommon.h"
int
main(int argc, char **argv)
{
int i;
if (!getenv("TERMINOLOGY")) return 0;
ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1();
if (argc <= 1)
{
printf("Usage: %s FILE1 [FILE2 ...]\n"