/* Generated by Nim Compiler v1.0.4 */
/*   (c) 2019 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 64

#include "nimbase.h"
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
#define nimfr_(x, y)
#define nimln_(x, y)
typedef struct tyObject_PTerminalcolonObjectType___EcU8GhMNGo9bGDXbfqZ82og tyObject_PTerminalcolonObjectType___EcU8GhMNGo9bGDXbfqZ82og;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
struct tyObject_PTerminalcolonObjectType___EcU8GhMNGo9bGDXbfqZ82og {
NIM_BOOL trueColorIsSupported;
NIM_BOOL trueColorIsEnabled;
NIM_BOOL fgSetColor;
};
typedef NU8 tyEnum_TNimKind__jIBKr1ejBgsfM33Kxw4j7A;
typedef NU8 tySet_tyEnum_TNimTypeFlag__v8QUszD1sWlSIWZz7mC4bQ;
typedef N_NIMCALL_PTR(void, tyProc__ojoeKfW4VYIm36I9cpDTQIg) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, tyProc__WSm2xU5ARYv9aAR4l0z9c9auQ) (void* p);
struct TNimType {
NI size;
tyEnum_TNimKind__jIBKr1ejBgsfM33Kxw4j7A kind;
tySet_tyEnum_TNimTypeFlag__v8QUszD1sWlSIWZz7mC4bQ flags;
TNimType* base;
TNimNode* node;
void* finalizer;
tyProc__ojoeKfW4VYIm36I9cpDTQIg marker;
tyProc__WSm2xU5ARYv9aAR4l0z9c9auQ deepcopy;
};
typedef NU8 tyEnum_TNimNodeKind__unfNsxrcATrufDZmpBq4HQ;
struct TNimNode {
tyEnum_TNimNodeKind__unfNsxrcATrufDZmpBq4HQ kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
typedef N_NIMCALL_PTR(void, tyProc__T4eqaYlFJYZUv9aG9b1TV0bQ) (void);
typedef NU16 tySet_tyEnum_Style__NXKayqTLMsAibFwNceBlpA;
typedef NU8 tyEnum_Style__NXKayqTLMsAibFwNceBlpA;
struct TGenericSeq {
NI len;
NI reserved;
};
struct NimStringDesc {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef NU8 tyEnum_ForegroundColor__ez9ah4IgQc0AbdW68acioDg;
static N_NIMCALL(void, Marker_tyRef__flNJLrANZti6Wiy5LTlGGA)(void* p, NI op);
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
static N_NIMCALL(void, TM__CN3raB9atujkEiPpxYAdlgQ_3)(void);
N_NIMCALL(void, nimRegisterThreadLocalMarker)(tyProc__T4eqaYlFJYZUv9aG9b1TV0bQ markerProc);
N_LIB_PRIVATE N_NIMCALL(int, getFileHandle__hOwLbM7eXaZgEJrHWLeiNg)(FILE* f);
static N_INLINE(NI, chckRange)(NI i, NI a, NI b);
N_NOINLINE(void, raiseRangeError)(NI64 val);
N_LIB_PRIVATE N_NIMCALL(void, write__PArlm09bKklm2BLsCg6YtaA)(FILE* f, NimStringDesc* s);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, ansiStyleCode__9cVIfUEE6Zf6B3dSUGw8cLQ)(NI style);
N_NIMCALL(NimStringDesc*, rawNewString)(NI cap);
N_LIB_PRIVATE N_NIMCALL(void, formatValue__3zjq9csYPBcIN7AqvyU5ZLA)(NimStringDesc** result, NimStringDesc* value, NimStringDesc* specifier);
N_LIB_PRIVATE N_NIMCALL(void, formatValue__ACNJL1q6Oxfvi53i9bkeK6Q)(NimStringDesc** result, NI value, NimStringDesc* specifier);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
static N_INLINE(void, copyMem__i80o3k0SgEI5gTRCzYdyWAsystem)(void* dest, void* source, NI size);
static N_INLINE(void, nimCopyMem)(void* dest, void* source, NI size);
N_NIMCALL(NimStringDesc*, resizeString)(NimStringDesc* dest, NI addlen);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
static N_INLINE(NI, addInt)(NI a, NI b);
N_NOINLINE(void, raiseOverflow)(void);
tyObject_PTerminalcolonObjectType___EcU8GhMNGo9bGDXbfqZ82og* gTerm__wkpx9csKte2r1l45yvskIcA;
TNimType NTI__EcU8GhMNGo9bGDXbfqZ82og_;
extern TNimType NTI__VaVACK0bpYmqIQ0mKcHfQQ_;
TNimType NTI__flNJLrANZti6Wiy5LTlGGA_;
NI gFG__g7w4T3anr20OMlWloNx2tQ;
NI gBG__dgmeknpHWrtwqMJGQAp9atA;
STRING_LITERAL(TM__CN3raB9atujkEiPpxYAdlgQ_4, "\033[", 2);
STRING_LITERAL(TM__CN3raB9atujkEiPpxYAdlgQ_5, "m", 1);
STRING_LITERAL(TM__CN3raB9atujkEiPpxYAdlgQ_7, "\033[0m", 4);
static N_NIMCALL(void, Marker_tyRef__flNJLrANZti6Wiy5LTlGGA)(void* p, NI op) {
	tyObject_PTerminalcolonObjectType___EcU8GhMNGo9bGDXbfqZ82og* a;
	a = (tyObject_PTerminalcolonObjectType___EcU8GhMNGo9bGDXbfqZ82og*)p;
}
static N_NIMCALL(void, TM__CN3raB9atujkEiPpxYAdlgQ_3)(void) {
	nimGCvisit((void*)gTerm__wkpx9csKte2r1l45yvskIcA, 0);
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, isatty__N9cWRL9bvOiaeIezt6AEzXqw)(FILE* f) {	NIM_BOOL result;
	int T1_;
	int T2_;
	result = (NIM_BOOL)0;
	T1_ = (int)0;
	T1_ = getFileHandle__hOwLbM7eXaZgEJrHWLeiNg(f);
	T2_ = (int)0;
	T2_ = isatty(T1_);
	result = !((T2_ == ((NI32) 0)));
	return result;
}
static N_INLINE(NI, chckRange)(NI i, NI a, NI b) {	NI result;
{	result = (NI)0;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = (a <= i);
		if (!(T3_)) goto LA4_;
		T3_ = (i <= b);
		LA4_: ;
		if (!T3_) goto LA5_;
		result = i;
		goto BeforeRet_;
	}
	goto LA1_;
	LA5_: ;
	{
		raiseRangeError(((NI64) (i)));
	}
	LA1_: ;
	}BeforeRet_: ;
	return result;
}
static N_INLINE(void, nimCopyMem)(void* dest, void* source, NI size) {	void* T1_;
	T1_ = (void*)0;
	T1_ = memcpy(dest, source, ((size_t) (size)));
}
static N_INLINE(void, copyMem__i80o3k0SgEI5gTRCzYdyWAsystem)(void* dest, void* source, NI size) {	nimCopyMem(dest, source, size);
}
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src) {	{
		if (!!((src == NIM_NIL))) goto LA3_;
		copyMem__i80o3k0SgEI5gTRCzYdyWAsystem(((void*) ((&(*dest).data[(*dest).Sup.len]))), ((void*) ((*src).data)), ((NI) ((NI)((*src).Sup.len + ((NI) 1)))));
		(*dest).Sup.len += (*src).Sup.len;
	}
	LA3_: ;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, ansiStyleCode__9cVIfUEE6Zf6B3dSUGw8cLQ)(NI style) {	NimStringDesc* result;
	NimStringDesc* fmtRes;
	result = (NimStringDesc*)0;
	fmtRes = rawNewString(((NI) 41));
	formatValue__3zjq9csYPBcIN7AqvyU5ZLA((&fmtRes), ((NimStringDesc*) &TM__CN3raB9atujkEiPpxYAdlgQ_4), ((NimStringDesc*) NIM_NIL));
	formatValue__ACNJL1q6Oxfvi53i9bkeK6Q((&fmtRes), style, ((NimStringDesc*) NIM_NIL));
	fmtRes = resizeString(fmtRes, 1);
appendString(fmtRes, ((NimStringDesc*) &TM__CN3raB9atujkEiPpxYAdlgQ_5));
	result = copyString(fmtRes);
	return result;
}
static N_INLINE(NI, addInt)(NI a, NI b) {	NI result;
{	result = (NI)0;
	result = (NI)((NU64)(a) + (NU64)(b));
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = (((NI) 0) <= (NI)(result ^ a));
		if (T3_) goto LA4_;
		T3_ = (((NI) 0) <= (NI)(result ^ b));
		LA4_: ;
		if (!T3_) goto LA5_;
		goto BeforeRet_;
	}
	LA5_: ;
	raiseOverflow();
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, setStyle__y8lW2LrW2n5ZHaxH9bAf4WA)(FILE* f, tySet_tyEnum_Style__NXKayqTLMsAibFwNceBlpA style) {	{
		tyEnum_Style__NXKayqTLMsAibFwNceBlpA s;
		NI i;
		s = (tyEnum_Style__NXKayqTLMsAibFwNceBlpA)0;
		i = ((NI) 1);
		{
			while (1) {
				NI TM__CN3raB9atujkEiPpxYAdlgQ_6;
				if (!(i <= ((NI) 9))) goto LA3;
				{
					NimStringDesc* T8_;
					if (!((style &(1U<<((NU)((((tyEnum_Style__NXKayqTLMsAibFwNceBlpA)chckRange(i, ((tyEnum_Style__NXKayqTLMsAibFwNceBlpA) 1), ((tyEnum_Style__NXKayqTLMsAibFwNceBlpA) 9)))- 1))&15U)))!=0)) goto LA6_;
					s = ((tyEnum_Style__NXKayqTLMsAibFwNceBlpA)chckRange(i, ((tyEnum_Style__NXKayqTLMsAibFwNceBlpA) 1), ((tyEnum_Style__NXKayqTLMsAibFwNceBlpA) 9)));
					T8_ = (NimStringDesc*)0;
					T8_ = ansiStyleCode__9cVIfUEE6Zf6B3dSUGw8cLQ(((NI) (s)));
					write__PArlm09bKklm2BLsCg6YtaA(f, T8_);
				}
				LA6_: ;
				TM__CN3raB9atujkEiPpxYAdlgQ_6 = addInt(i, ((NI) 1));
				i = (NI)(TM__CN3raB9atujkEiPpxYAdlgQ_6);
			} LA3: ;
		}
	}
}
N_LIB_PRIVATE N_NIMCALL(void, resetAttributes__6J8xlU57R8cS9bLzTS89aM5g)(FILE* f) {	write__PArlm09bKklm2BLsCg6YtaA(f, ((NimStringDesc*) &TM__CN3raB9atujkEiPpxYAdlgQ_7));
}
N_LIB_PRIVATE N_NIMCALL(void, setForegroundColor__vJutklhcnQq9akCXxcuSHAg)(FILE* f, tyEnum_ForegroundColor__ez9ah4IgQc0AbdW68acioDg fg, NIM_BOOL bright) {	NimStringDesc* T5_;
	gFG__g7w4T3anr20OMlWloNx2tQ = fg;
	{
		NI TM__CN3raB9atujkEiPpxYAdlgQ_8;
		if (!bright) goto LA3_;
		TM__CN3raB9atujkEiPpxYAdlgQ_8 = addInt(gFG__g7w4T3anr20OMlWloNx2tQ, ((NI) 60));
		gFG__g7w4T3anr20OMlWloNx2tQ = (NI)(TM__CN3raB9atujkEiPpxYAdlgQ_8);
	}
	LA3_: ;
	T5_ = (NimStringDesc*)0;
	T5_ = ansiStyleCode__9cVIfUEE6Zf6B3dSUGw8cLQ(gFG__g7w4T3anr20OMlWloNx2tQ);
	write__PArlm09bKklm2BLsCg6YtaA(f, T5_);
}
N_LIB_PRIVATE N_NIMCALL(void, stdlib_terminalInit000)(void) {
{

	nimRegisterThreadLocalMarker(TM__CN3raB9atujkEiPpxYAdlgQ_3);

}
}

N_LIB_PRIVATE N_NIMCALL(void, stdlib_terminalDatInit000)(void) {
static TNimNode* TM__CN3raB9atujkEiPpxYAdlgQ_2_3[3];
static TNimNode TM__CN3raB9atujkEiPpxYAdlgQ_0[4];
NTI__EcU8GhMNGo9bGDXbfqZ82og_.size = sizeof(tyObject_PTerminalcolonObjectType___EcU8GhMNGo9bGDXbfqZ82og);
NTI__EcU8GhMNGo9bGDXbfqZ82og_.kind = 18;
NTI__EcU8GhMNGo9bGDXbfqZ82og_.base = 0;
NTI__EcU8GhMNGo9bGDXbfqZ82og_.flags = 3;
TM__CN3raB9atujkEiPpxYAdlgQ_2_3[0] = &TM__CN3raB9atujkEiPpxYAdlgQ_0[1];
TM__CN3raB9atujkEiPpxYAdlgQ_0[1].kind = 1;
TM__CN3raB9atujkEiPpxYAdlgQ_0[1].offset = offsetof(tyObject_PTerminalcolonObjectType___EcU8GhMNGo9bGDXbfqZ82og, trueColorIsSupported);
TM__CN3raB9atujkEiPpxYAdlgQ_0[1].typ = (&NTI__VaVACK0bpYmqIQ0mKcHfQQ_);
TM__CN3raB9atujkEiPpxYAdlgQ_0[1].name = "trueColorIsSupported";
TM__CN3raB9atujkEiPpxYAdlgQ_2_3[1] = &TM__CN3raB9atujkEiPpxYAdlgQ_0[2];
TM__CN3raB9atujkEiPpxYAdlgQ_0[2].kind = 1;
TM__CN3raB9atujkEiPpxYAdlgQ_0[2].offset = offsetof(tyObject_PTerminalcolonObjectType___EcU8GhMNGo9bGDXbfqZ82og, trueColorIsEnabled);
TM__CN3raB9atujkEiPpxYAdlgQ_0[2].typ = (&NTI__VaVACK0bpYmqIQ0mKcHfQQ_);
TM__CN3raB9atujkEiPpxYAdlgQ_0[2].name = "trueColorIsEnabled";
TM__CN3raB9atujkEiPpxYAdlgQ_2_3[2] = &TM__CN3raB9atujkEiPpxYAdlgQ_0[3];
TM__CN3raB9atujkEiPpxYAdlgQ_0[3].kind = 1;
TM__CN3raB9atujkEiPpxYAdlgQ_0[3].offset = offsetof(tyObject_PTerminalcolonObjectType___EcU8GhMNGo9bGDXbfqZ82og, fgSetColor);
TM__CN3raB9atujkEiPpxYAdlgQ_0[3].typ = (&NTI__VaVACK0bpYmqIQ0mKcHfQQ_);
TM__CN3raB9atujkEiPpxYAdlgQ_0[3].name = "fgSetColor";
TM__CN3raB9atujkEiPpxYAdlgQ_0[0].len = 3; TM__CN3raB9atujkEiPpxYAdlgQ_0[0].kind = 2; TM__CN3raB9atujkEiPpxYAdlgQ_0[0].sons = &TM__CN3raB9atujkEiPpxYAdlgQ_2_3[0];
NTI__EcU8GhMNGo9bGDXbfqZ82og_.node = &TM__CN3raB9atujkEiPpxYAdlgQ_0[0];
NTI__flNJLrANZti6Wiy5LTlGGA_.size = sizeof(tyObject_PTerminalcolonObjectType___EcU8GhMNGo9bGDXbfqZ82og*);
NTI__flNJLrANZti6Wiy5LTlGGA_.kind = 22;
NTI__flNJLrANZti6Wiy5LTlGGA_.base = (&NTI__EcU8GhMNGo9bGDXbfqZ82og_);
NTI__flNJLrANZti6Wiy5LTlGGA_.flags = 2;
NTI__flNJLrANZti6Wiy5LTlGGA_.marker = Marker_tyRef__flNJLrANZti6Wiy5LTlGGA;
}

