Inline color file

This commit is contained in:
Bruce Hill 2024-04-20 14:24:37 -04:00
parent e79ce52125
commit e33aff908b
7 changed files with 9 additions and 32 deletions

View File

@ -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

View File

@ -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); \

View File

@ -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

View File

@ -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

View File

@ -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){ \

View File

@ -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
View File

@ -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"