SDL_Window *SDLWindow;
bool IsInFullscreen;
int FullScreenSizeX, FullScreenSizeY;
int FullScreenPositionX, FullScreenPositionY;
bool Testing = false;
bool AppIsRunning  = true;
bool WaitForEvents = true;
bool RunGCThisFrame;
bool SearchCaseSensitive = false;
bool SearchWordBoundary = false;

WindowID WindowIDs;
ViewID   ViewIDs;
Int BufferIDs;

Array<Window *> Windows;
Array<View *> Views;
Array<Buffer *> Buffers;

// First window
BufferID NullBufferID;
ViewID   NullViewID;
WindowID NullWindowID;


// hidden floating window
WindowID DebugWindowID;
ViewID DebugViewID;
BufferID DebugBufferID;

WindowID CommandWindowID;
WindowID StatusBarWindowID;
WindowID SearchWindowID;
ViewID   SearchViewID;
BufferID SearchBufferID;

WindowID NextActiveWindowID;
WindowID ActiveWindowID;
WindowID LastActiveLayoutWindowID;
WindowID ScrollbarSelected = {-1};
WindowID DocumentSelected  = {-1};
WindowID ResizerSelected = {-1};
WindowID ResizerHover = {-1};
Caret    DocumentAnchor;

Buffer *BuildBuffer;
Buffer *GCInfoBuffer;
Buffer *EventBuffer;
Buffer *TraceBuffer;
View *TraceView;

String WorkDir;
RandomSeed UniqueBufferNameSeed = {};
Array<Event> EventPlayback;
BlockArena Perm;

// clipboard
BlockArena ClipboardArena;
String16 SavedClipboardString;
Array<String16> SavedClipboardCarets = {SysAllocator};

struct InternTable {
    HashTable<String> strings; // general allocator
    BlockArena arena;
};

String Intern(InternTable *table, String string) {
    String *value = table->strings.get(string);
    if (!value) {
        String copy = Copy(table->arena, string);
        table->strings.put(copy, copy);
        return copy;
    }
    return *value;
}

// We use the intern table to optimize for space, I don't want to worry about freeing
// buffer names and event text data so let it all accumulate and interning will at least
// optimize worst offenders (like event text)
InternTable GlobalInternTable;

Function *LastExecutedManualCommand;
Array<CommandData> CommandFunctions;
Array<FunctionData> TestFunctions;
Array<Variable> Variables;

Array<Process> ActiveProcesses = {};
Array<String> ProcessEnviroment = {};

struct CoData { mco_coro *co; String name; BlockArena arena; bool dont_wait_until_resolved; void *user_ctx; };
Array<CoData> ActiveCoroutines;


///////////////////////////////
// CONFIG
Color GruvboxDark0Hard = {0x1d, 0x20, 0x21, 0xff};
Color GruvboxDark0 = {0x28, 0x28, 0x28, 0xff};
Color GruvboxDark0Soft = {0x32, 0x30, 0x2f, 0xff};
Color GruvboxDark1 = {0x3c, 0x38, 0x36, 0xff};
Color GruvboxDark2 = {0x50, 0x49, 0x45, 0xff};
Color GruvboxDark3 = {0x66, 0x5c, 0x54, 0xff};
Color GruvboxDark4 = {0x7c, 0x6f, 0x64, 0xff};
Color GruvboxGray245 = {0x92, 0x83, 0x74, 0xff};
Color GruvboxGray244 = {0x92, 0x83, 0x74, 0xff};
Color GruvboxLight0Hard = {0xf9, 0xf5, 0xd7, 0xff};
Color GruvboxLight0 = {0xfb, 0xf1, 0xc7, 0xff};
Color GruvboxLight0Soft = {0xf2, 0xe5, 0xbc, 0xff};
Color GruvboxLight1 = {0xeb, 0xdb, 0xb2, 0xff};
Color GruvboxLight2 = {0xd5, 0xc4, 0xa1, 0xff};
Color GruvboxLight3 = {0xbd, 0xae, 0x93, 0xff};
Color GruvboxLight4 = {0xa8, 0x99, 0x84, 0xff};
Color GruvboxBrightRed = {0xfb, 0x49, 0x34, 0xff};
Color GruvboxBrightGreen = {0xb8, 0xbb, 0x26, 0xff};
Color GruvboxBrightYellow = {0xfa, 0xbd, 0x2f, 0xff};
Color GruvboxBrightBlue = {0x83, 0xa5, 0x98, 0xff};
Color GruvboxBrightPurple = {0xd3, 0x86, 0x9b, 0xff};
Color GruvboxBrightAqua = {0x8e, 0xc0, 0x7c, 0xff};
Color GruvboxBrightOrange = {0xfe, 0x80, 0x19, 0xff};
Color GruvboxNeutralRed = {0xcc, 0x24, 0x1d, 0xff};
Color GruvboxNeutralGreen = {0x98, 0x97, 0x1a, 0xff};
Color GruvboxNeutralYellow = {0xd7, 0x99, 0x21, 0xff};
Color GruvboxNeutralBlue = {0x45, 0x85, 0x88, 0xff};
Color GruvboxNeutralPurple = {0xb1, 0x62, 0x86, 0xff};
Color GruvboxNeutralAqua = {0x68, 0x9d, 0x6a, 0xff};
Color GruvboxNeutralOrange = {0xd6, 0x5d, 0x0e, 0xff};
Color GruvboxFadedRed = {0x9d, 0x00, 0x06, 0xff};
Color GruvboxFadedGreen = {0x79, 0x74, 0x0e, 0xff};
Color GruvboxFadedYellow = {0xb5, 0x76, 0x14, 0xff};
Color GruvboxFadedBlue = {0x07, 0x66, 0x78, 0xff};
Color GruvboxFadedPurple = {0x8f, 0x3f, 0x71, 0xff};
Color GruvboxFadedAqua = {0x42, 0x7b, 0x58, 0xff};
Color GruvboxFadedOrange = {0xaf, 0x3a, 0x03, 0xff};
RegisterVariable(Color, ColorText, GruvboxDark0Hard);
RegisterVariable(Color, ColorLoadTextHighlight, {0x00, 0x00, 0x00, 0x0F});
RegisterVariable(Color, ColorBackground, GruvboxLight0Hard);
RegisterVariable(Color, ColorInactiveWindow, {0x00, 0x00, 0x00, 0x1F});
RegisterVariable(Color, ColorTextLineNumbers, GruvboxDark4);
RegisterVariable(Color, ColorLineHighlight, GruvboxLight0Soft);
RegisterVariable(Color, ColorMainCaret, GruvboxDark0Hard);
RegisterVariable(Color, ColorSubCaret, GruvboxGray245);
RegisterVariable(Color, ColorSelection, GruvboxLight1);
RegisterVariable(Color, ColorWhitespaceDuringSelection, GruvboxLight4);
RegisterVariable(Color, ColorMouseUnderline, GruvboxDark0Hard);
RegisterVariable(Color, ColorCaretUnderline, GruvboxGray245);
RegisterVariable(Color, ColorScrollbarBackground, GruvboxLight2);
RegisterVariable(Color, ColorScrollbarScroller, GruvboxLight1);
RegisterVariable(Color, ColorScrollbarScrollerSelected, GruvboxLight0Hard);
RegisterVariable(Color, ColorTitleBarText, GruvboxDark0Hard);
RegisterVariable(Color, ColorTitleBarBackground, GruvboxLight0Hard);
RegisterVariable(Color, ColorTitleBarSelection, GruvboxLight3);
RegisterVariable(Color, ColorTitleBarLineHighlight, GruvboxLight0Soft);
RegisterVariable(Color, ColorTitleBarOutline, GruvboxLight3);
RegisterVariable(Color, ColorResizerBackground, GruvboxLight0Hard);
RegisterVariable(Color, ColorResizerOutline, GruvboxLight3);
RegisterVariable(Int, ConfigWaitForEvents, 1);
RegisterVariable(Int, ConfigDrawLineNumbers, 1);
RegisterVariable(Int, ConfigDrawScrollbar, 1);
RegisterVariable(Int, ConfigIndentSize, 4);
RegisterVariable(Int, ConfigFontSize, 15);
RegisterVariable(Int, ConfigFontFilter, 0);
RegisterVariable(String, ConfigFont, "/home/krz/text_editor/package/CascadiaMono.ttf");
RegisterVariable(String, ConfigVCVarsall, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat");
RegisterVariable(Float, ConfigUndoMergeTimeWindow, 0.3);
RegisterVariable(Float, ConfigJumpHistoryMergeTimeWindow, 0.3);
RegisterVariable(Int, ConfigJumpHistorySize, 4096);
RegisterVariable(String, ConfigInternetBrowser, "firefox");
