Redesign lua reloading and other generation stuff
This commit is contained in:
207
build_file.cpp
207
build_file.cpp
@@ -192,41 +192,7 @@ char *C(const char *value) {
|
||||
S8_String LuaScript = R"==(
|
||||
-- @todo: should we rewrite linux paths to windows on windows and vice-versa?
|
||||
|
||||
function GenericTextFileRule(_s)
|
||||
function match_path(s)
|
||||
-- ./something
|
||||
-- add working directory
|
||||
local working_dir_i, working_dir_j = string.find(s, "^%./.+")
|
||||
if working_dir_j then
|
||||
result = s:sub(3)
|
||||
result = GetWorkingDir().."/"..result
|
||||
return result
|
||||
end
|
||||
|
||||
-- C:/something
|
||||
local abs_i, abs_j = string.find(s, "^%a:/.+")
|
||||
if abs_i then
|
||||
return s
|
||||
end
|
||||
|
||||
-- C:\something
|
||||
local abs_i, abs_j = s:find("^%a:\\.+")
|
||||
if abs_i then
|
||||
s = s:gsub("\\", "/")
|
||||
return s
|
||||
end
|
||||
|
||||
-- /mnt/something
|
||||
local abs_i, abs_j = s:find("^/.*")
|
||||
if abs_i then
|
||||
return s
|
||||
end
|
||||
|
||||
-- other_random_filename
|
||||
return s
|
||||
end
|
||||
|
||||
function match_line_col(s)
|
||||
function ExtractLineAndColumn(s)
|
||||
local line = 1
|
||||
local col = 1
|
||||
|
||||
@@ -288,16 +254,65 @@ function GenericTextFileRule(_s)
|
||||
end
|
||||
|
||||
return 0, 0, s
|
||||
end
|
||||
|
||||
function GenericTextFileRule(_s)
|
||||
function match_path(s)
|
||||
-- ./something
|
||||
-- add working directory
|
||||
local working_dir_i, working_dir_j = string.find(s, "^%./.+")
|
||||
if working_dir_j then
|
||||
result = s:sub(3)
|
||||
result = GetWorkingDir().."/"..result
|
||||
return result
|
||||
end
|
||||
|
||||
-- C:/something
|
||||
local abs_i, abs_j = string.find(s, "^%a:/.+")
|
||||
if abs_i then
|
||||
return s
|
||||
end
|
||||
|
||||
-- C:\something
|
||||
local abs_i, abs_j = s:find("^%a:\\.+")
|
||||
if abs_i then
|
||||
s = s:gsub("\\", "/")
|
||||
return s
|
||||
end
|
||||
|
||||
-- /mnt/something
|
||||
local abs_i, abs_j = s:find("^/.*")
|
||||
if abs_i then
|
||||
return s
|
||||
end
|
||||
|
||||
-- other_random_filename
|
||||
return s
|
||||
end
|
||||
|
||||
line, col, _s = match_line_col(_s)
|
||||
line, col, _s = ExtractLineAndColumn(_s)
|
||||
file_path = match_path(_s)
|
||||
return {kind = "text", file_path = file_path, line = line, col = col}
|
||||
end
|
||||
|
||||
-- function RuleFindExistingBuffer(_s)
|
||||
-- line, col, _s = ExtractLineAndColumn(_s)
|
||||
--
|
||||
-- buffers = list_buffers_object()
|
||||
-- for i = 1,#buffers do
|
||||
-- buff = buffers[i]
|
||||
-- if buff == _s then
|
||||
-- return {kind = "text", file_path = buff, line = line, col = col}
|
||||
-- end
|
||||
-- end
|
||||
--
|
||||
-- return nil
|
||||
-- end
|
||||
|
||||
|
||||
Rules = {}
|
||||
Rules[#Rules + 1] = GenericTextFileRule
|
||||
-- Rules[#Rules + 2] = RuleFindExistingBuffer
|
||||
|
||||
function ApplyRules(s)
|
||||
for i = #Rules,1,-1 do
|
||||
@@ -313,73 +328,74 @@ end
|
||||
)==";
|
||||
|
||||
void GenerateConfig() {
|
||||
struct Color {
|
||||
struct Var {
|
||||
const char *name;
|
||||
const char *value;
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
Array<Color> gruvbox = {};
|
||||
gruvbox.add({"GruvboxDark0Hard" , "0x1d2021ff"});
|
||||
gruvbox.add({"GruvboxDark0" , "0x282828ff"});
|
||||
gruvbox.add({"GruvboxDark0Soft" , "0x32302fff"});
|
||||
gruvbox.add({"GruvboxDark1" , "0x3c3836ff"});
|
||||
gruvbox.add({"GruvboxDark2" , "0x504945ff"});
|
||||
gruvbox.add({"GruvboxDark3" , "0x665c54ff"});
|
||||
gruvbox.add({"GruvboxDark4" , "0x7c6f64ff"});
|
||||
gruvbox.add({"GruvboxGray245" , "0x928374ff"});
|
||||
gruvbox.add({"GruvboxGray244" , "0x928374ff"});
|
||||
gruvbox.add({"GruvboxLight0Hard" , "0xf9f5d7ff"});
|
||||
gruvbox.add({"GruvboxLight0" , "0xfbf1c7ff"});
|
||||
gruvbox.add({"GruvboxLight0Soft" , "0xf2e5bcff"});
|
||||
gruvbox.add({"GruvboxLight1" , "0xebdbb2ff"});
|
||||
gruvbox.add({"GruvboxLight2" , "0xd5c4a1ff"});
|
||||
gruvbox.add({"GruvboxLight3" , "0xbdae93ff"});
|
||||
gruvbox.add({"GruvboxLight4" , "0xa89984ff"});
|
||||
gruvbox.add({"GruvboxBrightRed" , "0xfb4934ff"});
|
||||
gruvbox.add({"GruvboxBrightGreen" , "0xb8bb26ff"});
|
||||
gruvbox.add({"GruvboxBrightYellow" , "0xfabd2fff"});
|
||||
gruvbox.add({"GruvboxBrightBlue" , "0x83a598ff"});
|
||||
gruvbox.add({"GruvboxBrightPurple" , "0xd3869bff"});
|
||||
gruvbox.add({"GruvboxBrightAqua" , "0x8ec07cff"});
|
||||
gruvbox.add({"GruvboxBrightOrange" , "0xfe8019ff"});
|
||||
gruvbox.add({"GruvboxNeutralRed" , "0xcc241dff"});
|
||||
gruvbox.add({"GruvboxNeutralGreen" , "0x98971aff"});
|
||||
Array<Var> gruvbox = {};
|
||||
gruvbox.add({"GruvboxDark0Hard", "0x1d2021ff"});
|
||||
gruvbox.add({"GruvboxDark0", "0x282828ff"});
|
||||
gruvbox.add({"GruvboxDark0Soft", "0x32302fff"});
|
||||
gruvbox.add({"GruvboxDark1", "0x3c3836ff"});
|
||||
gruvbox.add({"GruvboxDark2", "0x504945ff"});
|
||||
gruvbox.add({"GruvboxDark3", "0x665c54ff"});
|
||||
gruvbox.add({"GruvboxDark4", "0x7c6f64ff"});
|
||||
gruvbox.add({"GruvboxGray245", "0x928374ff"});
|
||||
gruvbox.add({"GruvboxGray244", "0x928374ff"});
|
||||
gruvbox.add({"GruvboxLight0Hard", "0xf9f5d7ff"});
|
||||
gruvbox.add({"GruvboxLight0", "0xfbf1c7ff"});
|
||||
gruvbox.add({"GruvboxLight0Soft", "0xf2e5bcff"});
|
||||
gruvbox.add({"GruvboxLight1", "0xebdbb2ff"});
|
||||
gruvbox.add({"GruvboxLight2", "0xd5c4a1ff"});
|
||||
gruvbox.add({"GruvboxLight3", "0xbdae93ff"});
|
||||
gruvbox.add({"GruvboxLight4", "0xa89984ff"});
|
||||
gruvbox.add({"GruvboxBrightRed", "0xfb4934ff"});
|
||||
gruvbox.add({"GruvboxBrightGreen", "0xb8bb26ff"});
|
||||
gruvbox.add({"GruvboxBrightYellow", "0xfabd2fff"});
|
||||
gruvbox.add({"GruvboxBrightBlue", "0x83a598ff"});
|
||||
gruvbox.add({"GruvboxBrightPurple", "0xd3869bff"});
|
||||
gruvbox.add({"GruvboxBrightAqua", "0x8ec07cff"});
|
||||
gruvbox.add({"GruvboxBrightOrange", "0xfe8019ff"});
|
||||
gruvbox.add({"GruvboxNeutralRed", "0xcc241dff"});
|
||||
gruvbox.add({"GruvboxNeutralGreen", "0x98971aff"});
|
||||
gruvbox.add({"GruvboxNeutralYellow", "0xd79921ff"});
|
||||
gruvbox.add({"GruvboxNeutralBlue" , "0x458588ff"});
|
||||
gruvbox.add({"GruvboxNeutralBlue", "0x458588ff"});
|
||||
gruvbox.add({"GruvboxNeutralPurple", "0xb16286ff"});
|
||||
gruvbox.add({"GruvboxNeutralAqua" , "0x689d6aff"});
|
||||
gruvbox.add({"GruvboxNeutralAqua", "0x689d6aff"});
|
||||
gruvbox.add({"GruvboxNeutralOrange", "0xd65d0eff"});
|
||||
gruvbox.add({"GruvboxFadedRed" , "0x9d0006ff"});
|
||||
gruvbox.add({"GruvboxFadedGreen" , "0x79740eff"});
|
||||
gruvbox.add({"GruvboxFadedYellow" , "0xb57614ff"});
|
||||
gruvbox.add({"GruvboxFadedBlue" , "0x076678ff"});
|
||||
gruvbox.add({"GruvboxFadedPurple" , "0x8f3f71ff"});
|
||||
gruvbox.add({"GruvboxFadedAqua" , "0x427b58ff"});
|
||||
gruvbox.add({"GruvboxFadedOrange" , "0xaf3a03ff"});
|
||||
gruvbox.add({"GruvboxFadedRed", "0x9d0006ff"});
|
||||
gruvbox.add({"GruvboxFadedGreen", "0x79740eff"});
|
||||
gruvbox.add({"GruvboxFadedYellow", "0xb57614ff"});
|
||||
gruvbox.add({"GruvboxFadedBlue", "0x076678ff"});
|
||||
gruvbox.add({"GruvboxFadedPurple", "0x8f3f71ff"});
|
||||
gruvbox.add({"GruvboxFadedAqua", "0x427b58ff"});
|
||||
gruvbox.add({"GruvboxFadedOrange", "0xaf3a03ff"});
|
||||
|
||||
Array<Color> colors = {};
|
||||
colors.add({"Text" , "GruvboxDark0Hard"});
|
||||
colors.add({"Background" , "GruvboxLight0Hard"});
|
||||
colors.add({"InactiveWindow" , "0x0000000F"});
|
||||
colors.add({"TextLineNumbers" , "GruvboxDark4"});
|
||||
colors.add({"LineHighlight" , "GruvboxLight0Soft"});
|
||||
colors.add({"MainCaret" , "GruvboxDark0Hard"});
|
||||
colors.add({"SubCaret" , "GruvboxGray245"});
|
||||
colors.add({"Selection" , "GruvboxLight1"});
|
||||
Array<Var> colors = {};
|
||||
colors.add({"Text", "GruvboxDark0Hard"});
|
||||
colors.add({"Background", "GruvboxLight0Hard"});
|
||||
colors.add({"InactiveWindow", "0x0000000F"});
|
||||
colors.add({"TextLineNumbers", "GruvboxDark4"});
|
||||
colors.add({"LineHighlight", "GruvboxLight0Soft"});
|
||||
colors.add({"MainCaret", "GruvboxDark0Hard"});
|
||||
colors.add({"SubCaret", "GruvboxGray245"});
|
||||
colors.add({"Selection", "GruvboxLight1"});
|
||||
colors.add({"WhitespaceDuringSelection", "GruvboxLight4"});
|
||||
|
||||
colors.add({"FuzzySearchLineHighlight", "GruvboxDark0"});
|
||||
|
||||
colors.add({"ScrollbarBackground" , "GruvboxLight2"});
|
||||
colors.add({"ScrollbarScroller" , "GruvboxLight1"});
|
||||
colors.add({"ScrollbarBackground", "GruvboxLight2"});
|
||||
colors.add({"ScrollbarScroller", "GruvboxLight1"});
|
||||
colors.add({"ScrollbarScrollerSelected", "GruvboxLight0Hard"});
|
||||
|
||||
colors.add({"TitleBarText" , "GruvboxDark2"});
|
||||
colors.add({"TitleBarBackground" , "GruvboxLight1"});
|
||||
colors.add({"TitleBarSelection" , "GruvboxLight3"});
|
||||
colors.add({"TitleBarText", "GruvboxDark2"});
|
||||
colors.add({"TitleBarBackground", "GruvboxLight1"});
|
||||
colors.add({"TitleBarSelection", "GruvboxLight3"});
|
||||
|
||||
// clang-format on
|
||||
Array<Var> style = {};
|
||||
style.add({"DrawLineNumbers", "0"});
|
||||
style.add({"DrawScrollbar", "0"});
|
||||
|
||||
{
|
||||
MA_Scratch scratch;
|
||||
@@ -387,23 +403,34 @@ void GenerateConfig() {
|
||||
{
|
||||
For(gruvbox) sb.add(Fmt("Color %s = %s;", it.name, C(it.value)));
|
||||
For(colors) sb.add(Fmt("Color Color%s = %s;", it.name, C(it.value)));
|
||||
For(style) sb.add(Fmt("Int Style%s = %s;", it.name, it.value));
|
||||
}
|
||||
S8_String string = Merge(scratch, sb, "\n");
|
||||
OS_WriteFile("../src/text_editor/generated_variables.cpp", string);
|
||||
sb = {};
|
||||
|
||||
sb.add("String BaseLuaConfig = R\"==(");
|
||||
{
|
||||
For(gruvbox) sb.add(Fmt("local %s = %s", it.name, it.value));
|
||||
|
||||
sb.add("Color = {}");
|
||||
For(colors) sb.add(Fmt("Color.%s = %s", it.name, it.value));
|
||||
|
||||
sb.add("Style = {}");
|
||||
For(style) sb.add(Fmt("Style.%s = %s", it.name, it.value));
|
||||
|
||||
sb.add(LuaScript);
|
||||
}
|
||||
sb.add(")==\";");
|
||||
|
||||
sb.add("void ReloadColors() {");
|
||||
sb.add("void ReloadStyle() {");
|
||||
{
|
||||
For(colors) sb.add(Fmt(" Color%s = GetColor(\"%s\", Color%s);", it.name, it.name, it.name));
|
||||
For(style) sb.add(Fmt(" Style%s = GetStyle(\"%s\", Style%s);", it.name, it.name, it.name));
|
||||
}
|
||||
sb.add("}");
|
||||
|
||||
S8_String string = Merge(scratch, sb, "\n");
|
||||
string = Merge(scratch, sb, "\n");
|
||||
OS_WriteFile("../src/text_editor/generated.cpp", string);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user