Inline color file
This commit is contained in:
parent
e79ce52125
commit
e33aff908b
2
Makefile
2
Makefile
@ -24,7 +24,7 @@ G=-ggdb
|
||||
O=-Og
|
||||
CFLAGS=$(CCONFIG) $(EXTRA) $(CWARN) $(G) $(O) $(OSFLAGS)
|
||||
LDLIBS=-lgc -lcord -lm -lunistring -ldl -L. -ltomo
|
||||
BUILTIN_OBJS=builtins/array.o builtins/bool.o builtins/color.o builtins/nums.o builtins/functions.o builtins/integers.o \
|
||||
BUILTIN_OBJS=builtins/array.o builtins/bool.o builtins/nums.o builtins/functions.o builtins/integers.o \
|
||||
builtins/pointer.o builtins/memory.o builtins/text.o builtins/table.o builtins/types.o builtins/util.o builtins/files.o
|
||||
|
||||
all: libtomo.so tomo
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include "functions.h"
|
||||
#include "types.h"
|
||||
|
||||
extern bool USE_COLOR;
|
||||
|
||||
// Convert negative indices to back-indexed without branching: index0 = index + (index < 0)*(len+1)) - 1
|
||||
#define Array_get(item_type, arr_expr, index_expr, filename, start, end) *({ \
|
||||
const array_t arr = arr_expr; int64_t index = (int64_t)(index_expr); \
|
||||
|
@ -1,17 +0,0 @@
|
||||
// Logic for detecting whether console color should be used
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "color.h"
|
||||
|
||||
public bool USE_COLOR = true;
|
||||
|
||||
public void detect_color(void)
|
||||
{
|
||||
USE_COLOR = getenv("COLOR") ? strcmp(getenv("COLOR"), "1") == 0 : isatty(STDOUT_FILENO);
|
||||
}
|
||||
|
||||
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
|
@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// Logic for console color usage
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
extern bool USE_COLOR;
|
||||
|
||||
void detect_color(void);
|
||||
|
||||
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
|
@ -10,6 +10,8 @@
|
||||
#include "datatypes.h"
|
||||
#include "array.h"
|
||||
|
||||
extern bool USE_COLOR;
|
||||
|
||||
#define Table(key_t, val_t, key_info, value_info, fb, def, N, ...) ({ \
|
||||
struct { key_t k; val_t v; } ents[N] = {__VA_ARGS__}; \
|
||||
table_t table = Table$from_entries((array_t){ \
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
#include "array.h"
|
||||
#include "bool.h"
|
||||
#include "color.h"
|
||||
#include "datatypes.h"
|
||||
#include "functions.h"
|
||||
#include "halfsiphash.h"
|
||||
|
6
tomo.c
6
tomo.c
@ -316,11 +316,13 @@ int compile_executable(const char *filename, const char *object_files)
|
||||
"#include <tomo/tomo.h>\n"
|
||||
"#include \"", filename, ".h\"\n"
|
||||
"\n"
|
||||
"public bool USE_COLOR = true;\n"
|
||||
"\n"
|
||||
"int main(int argc, char *argv[]) {\n"
|
||||
"GC_INIT();\n"
|
||||
"USE_COLOR = getenv(\"COLOR\") ? strcmp(getenv(\"COLOR\"), \"1\") == 0 : isatty(STDOUT_FILENO);\n"
|
||||
"srand(arc4random_uniform(UINT32_MAX));\n"
|
||||
"srand48(arc4random_uniform(UINT32_MAX));\n"
|
||||
"detect_color();\n",
|
||||
"srand48(arc4random_uniform(UINT32_MAX));\n",
|
||||
module_name, "$main$run(argc, argv);\n",
|
||||
"return 0;\n"
|
||||
"}\n"
|
||||
|
Loading…
Reference in New Issue
Block a user