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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,6 +357,8 @@ bool GlobalCommand(Event event) {
|
||||
if (command_window->visible) {
|
||||
SetActiveWindow(GetLastActiveWindow());
|
||||
} else {
|
||||
View *view = GetView(command_window->active_view);
|
||||
Command_EvalLua(view, L"list_buffers()");
|
||||
SetActiveWindow(command_window->id);
|
||||
}
|
||||
run_window_command = false;
|
||||
@@ -376,15 +378,18 @@ bool GlobalCommand(Event event) {
|
||||
}
|
||||
|
||||
if (Ctrl(SDLK_1)) {
|
||||
SetActiveWindow({0});
|
||||
Window *window = GetLayoutWindow(0);
|
||||
if (window) SetActiveWindow(window->id);
|
||||
run_window_command = false;
|
||||
}
|
||||
if (Ctrl(SDLK_2)) {
|
||||
SetActiveWindow({1});
|
||||
Window *window = GetLayoutWindow(1);
|
||||
if (window) SetActiveWindow(window->id);
|
||||
run_window_command = false;
|
||||
}
|
||||
if (Ctrl(SDLK_3)) {
|
||||
SetActiveWindow({2});
|
||||
Window *window = GetLayoutWindow(2);
|
||||
if (window) SetActiveWindow(window->id);
|
||||
run_window_command = false;
|
||||
}
|
||||
|
||||
@@ -451,10 +456,7 @@ void ReportWarningf(const char *fmt, ...) {
|
||||
STRING_FORMAT(scratch, fmt, string);
|
||||
String16 string16 = ToString16(scratch, string);
|
||||
AppendToConsole(string16);
|
||||
|
||||
{
|
||||
Buffer *buffer = GetBuffer("*popup*");
|
||||
ReplaceText(buffer, GetRange(*buffer), string16);
|
||||
SetActiveWindow(PopupWindowID);
|
||||
}
|
||||
Window *window = GetWindow(ConsoleWindowID);
|
||||
SetVisibility(window, true);
|
||||
SetActiveWindow(window->id);
|
||||
}
|
||||
@@ -1,56 +1,3 @@
|
||||
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};
|
||||
Color ColorText = GruvboxDark0Hard;
|
||||
Color ColorBackground = GruvboxLight0Hard;
|
||||
Color ColorInactiveWindow = {0x00, 0x00, 0x00, 0x0F};
|
||||
Color ColorTextLineNumbers = GruvboxDark4;
|
||||
Color ColorLineHighlight = GruvboxLight0Soft;
|
||||
Color ColorMainCaret = GruvboxDark0Hard;
|
||||
Color ColorSubCaret = GruvboxGray245;
|
||||
Color ColorSelection = GruvboxLight1;
|
||||
Color ColorWhitespaceDuringSelection = GruvboxLight4;
|
||||
Color ColorFuzzySearchLineHighlight = GruvboxDark0;
|
||||
Color ColorScrollbarBackground = GruvboxLight2;
|
||||
Color ColorScrollbarScroller = GruvboxLight1;
|
||||
Color ColorScrollbarScrollerSelected = GruvboxLight0Hard;
|
||||
Color ColorTitleBarText = GruvboxDark2;
|
||||
Color ColorTitleBarBackground = GruvboxLight1;
|
||||
Color ColorTitleBarSelection = GruvboxLight3;
|
||||
String BaseLuaConfig = R"==(
|
||||
local GruvboxDark0Hard = 0x1d2021ff
|
||||
local GruvboxDark0 = 0x282828ff
|
||||
@@ -106,44 +53,13 @@ Color.ScrollbarScrollerSelected = GruvboxLight0Hard
|
||||
Color.TitleBarText = GruvboxDark2
|
||||
Color.TitleBarBackground = GruvboxLight1
|
||||
Color.TitleBarSelection = GruvboxLight3
|
||||
Style = {}
|
||||
Style.DrawLineNumbers = 0
|
||||
Style.DrawScrollbar = 0
|
||||
|
||||
-- @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
|
||||
|
||||
@@ -205,16 +121,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
|
||||
@@ -229,7 +194,7 @@ end
|
||||
|
||||
|
||||
)==";
|
||||
void ReloadColors() {
|
||||
void ReloadStyle() {
|
||||
ColorText = GetColor("Text", ColorText);
|
||||
ColorBackground = GetColor("Background", ColorBackground);
|
||||
ColorInactiveWindow = GetColor("InactiveWindow", ColorInactiveWindow);
|
||||
@@ -246,4 +211,6 @@ void ReloadColors() {
|
||||
ColorTitleBarText = GetColor("TitleBarText", ColorTitleBarText);
|
||||
ColorTitleBarBackground = GetColor("TitleBarBackground", ColorTitleBarBackground);
|
||||
ColorTitleBarSelection = GetColor("TitleBarSelection", ColorTitleBarSelection);
|
||||
StyleDrawLineNumbers = GetStyle("DrawLineNumbers", StyleDrawLineNumbers);
|
||||
StyleDrawScrollbar = GetStyle("DrawScrollbar", StyleDrawScrollbar);
|
||||
}
|
||||
55
src/text_editor/generated_variables.cpp
Normal file
55
src/text_editor/generated_variables.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
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};
|
||||
Color ColorText = GruvboxDark0Hard;
|
||||
Color ColorBackground = GruvboxLight0Hard;
|
||||
Color ColorInactiveWindow = {0x00, 0x00, 0x00, 0x0F};
|
||||
Color ColorTextLineNumbers = GruvboxDark4;
|
||||
Color ColorLineHighlight = GruvboxLight0Soft;
|
||||
Color ColorMainCaret = GruvboxDark0Hard;
|
||||
Color ColorSubCaret = GruvboxGray245;
|
||||
Color ColorSelection = GruvboxLight1;
|
||||
Color ColorWhitespaceDuringSelection = GruvboxLight4;
|
||||
Color ColorFuzzySearchLineHighlight = GruvboxDark0;
|
||||
Color ColorScrollbarBackground = GruvboxLight2;
|
||||
Color ColorScrollbarScroller = GruvboxLight1;
|
||||
Color ColorScrollbarScrollerSelected = GruvboxLight0Hard;
|
||||
Color ColorTitleBarText = GruvboxDark2;
|
||||
Color ColorTitleBarBackground = GruvboxLight1;
|
||||
Color ColorTitleBarSelection = GruvboxLight3;
|
||||
Int StyleDrawLineNumbers = 0;
|
||||
Int StyleDrawScrollbar = 0;
|
||||
@@ -73,6 +73,19 @@ int LuaListOpenBuffers(lua_State *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaListOpenBuffersObject(lua_State *L) {
|
||||
lua_createtable(L, 0, (int)Buffers.len);
|
||||
|
||||
int i = 1;
|
||||
For(Buffers) {
|
||||
lua_pushinteger(L, i++);
|
||||
lua_pushlstring(L, it.name.data, it.name.len);
|
||||
lua_settable(L, -3); /* 3rd element from the stack top */
|
||||
}
|
||||
/* We still have table left on top of the Lua stack. */
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaGetWorkingDir(lua_State *L) {
|
||||
lua_pushlstring(LuaState, WorkingDir.data, WorkingDir.len);
|
||||
return 1;
|
||||
@@ -101,6 +114,9 @@ void InitLua() {
|
||||
lua_pushcfunction(LuaState, LuaListOpenBuffers);
|
||||
lua_setglobal(LuaState, "list_buffers");
|
||||
|
||||
lua_pushcfunction(LuaState, LuaListOpenBuffersObject);
|
||||
lua_setglobal(LuaState, "list_buffers_object");
|
||||
|
||||
lua_pushcfunction(LuaState, LuaOpenBigBuffer);
|
||||
lua_setglobal(LuaState, "open_big_buffer");
|
||||
|
||||
@@ -130,6 +146,22 @@ String16 EvalString(Allocator allocator, String16 string16) {
|
||||
}
|
||||
}
|
||||
|
||||
Int GetStyle(String name, Int default_int) {
|
||||
Int result = default_int;
|
||||
lua_getglobal(LuaState, "Style");
|
||||
defer { lua_pop(LuaState, 1); };
|
||||
if (lua_istable(LuaState, -1)) {
|
||||
lua_pushlstring(LuaState, name.data, name.len);
|
||||
lua_gettable(LuaState, -2);
|
||||
defer { lua_pop(LuaState, 1); };
|
||||
if (lua_isnumber(LuaState, -1) || lua_isboolean(LuaState, -1) || lua_isinteger(LuaState, -1)) {
|
||||
lua_Integer num = lua_tointeger(LuaState, -1);
|
||||
result = (Int)num;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Color GetColor(String name, Color default_color) {
|
||||
Color result = default_color;
|
||||
lua_getglobal(LuaState, "Color");
|
||||
@@ -148,3 +180,62 @@ Color GetColor(String name, Color default_color) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Buffer *LuaBuffer = NULL;
|
||||
Int LuaBufferChangeID = 0;
|
||||
void ReloadStyle();
|
||||
extern String BaseLuaConfig;
|
||||
|
||||
void ReloadLuaConfig() {
|
||||
// Init base config, test that it works and initialize the lua stuff
|
||||
if (LuaBufferChangeID == 0) {
|
||||
if (!luaL_dostring(LuaState, BaseLuaConfig.data) == LUA_OK) {
|
||||
const char *error_message = lua_tostring(LuaState, -1);
|
||||
ReportErrorf("Failed to load base lua config! %s", error_message);
|
||||
lua_pop(LuaState, 1);
|
||||
Assert(!"Invalid codepath");
|
||||
}
|
||||
|
||||
// Init user config
|
||||
Scratch scratch;
|
||||
String lua_config_path = Format(scratch, "%.*s/init.lua", FmtString(ConfigDir));
|
||||
|
||||
#if DEBUG_BUILD
|
||||
// WARNING! Delete config to make sure we are running this code more frequently
|
||||
SDL_RemovePath(lua_config_path.data);
|
||||
#endif
|
||||
|
||||
LuaBuffer = BufferOpenFile(lua_config_path);
|
||||
if (LuaBuffer->len == 0) {
|
||||
ReplaceText(LuaBuffer, {}, ToString16(scratch, BaseLuaConfig));
|
||||
}
|
||||
|
||||
// if we loaded from file this should force to read
|
||||
LuaBuffer->change_id = 2;
|
||||
LuaBufferChangeID = 1;
|
||||
}
|
||||
|
||||
if (LuaBuffer->dirty == false && LuaBuffer->change_id != LuaBufferChangeID) {
|
||||
Scratch scratch;
|
||||
String16 string16 = GetString(*LuaBuffer);
|
||||
String string = ToString(scratch, string16);
|
||||
if (luaL_dostring(LuaState, string.data) == LUA_OK) {
|
||||
if (lua_isstring(LuaState, -1)) {
|
||||
const char *text = lua_tostring(LuaState, -1);
|
||||
ReportConsolef(text);
|
||||
lua_pop(LuaState, 1);
|
||||
}
|
||||
ReloadStyle();
|
||||
ForItem(window, Windows) {
|
||||
if (!window.visible || window.absolute_position || window.is_title_bar) continue;
|
||||
window.draw_scrollbar = StyleDrawScrollbar;
|
||||
window.draw_line_numbers = StyleDrawLineNumbers;
|
||||
}
|
||||
} else {
|
||||
const char *error_message = lua_tostring(LuaState, -1);
|
||||
ReportWarningf("Failed to load user config! %s", error_message);
|
||||
lua_pop(LuaState, 1);
|
||||
}
|
||||
LuaBufferChangeID = LuaBuffer->change_id;
|
||||
}
|
||||
}
|
||||
@@ -79,8 +79,8 @@ Buffer *CreateTempBuffer(Allocator allocator, Int size = 4096) {
|
||||
Window *CreateWindow() {
|
||||
Window *w = Alloc(&Windows);
|
||||
w->visible = true;
|
||||
w->draw_scrollbar = true;
|
||||
w->draw_line_numbers = true;
|
||||
w->draw_scrollbar = StyleDrawScrollbar;
|
||||
w->draw_line_numbers = StyleDrawLineNumbers;
|
||||
w->id = AllocWindowID();
|
||||
return w;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ int FullScreenPositionX, FullScreenPositionY;
|
||||
|
||||
#include "platform/font.cpp"
|
||||
#include "platform/render_opengl.cpp"
|
||||
#include "generated_variables.cpp"
|
||||
|
||||
#include "text_editor.h"
|
||||
#include "buffer_helpers.cpp"
|
||||
@@ -38,6 +39,7 @@ int FullScreenPositionX, FullScreenPositionY;
|
||||
#include "lua.hpp"
|
||||
#include "lua_api.cpp"
|
||||
#include "generated.cpp"
|
||||
|
||||
#include "window_draw.cpp"
|
||||
|
||||
void FillEventWithBasicData(Event *event) {
|
||||
@@ -128,9 +130,7 @@ void HandleEvent(Event event) {
|
||||
}
|
||||
}
|
||||
|
||||
Buffer *LuaBuffer = NULL;
|
||||
Int LuaBufferChangeID = 0;
|
||||
void Update(const Event &event) {
|
||||
void Update(const Event &event) {
|
||||
WindowSize = {(float)event.xwindow, (float)event.ywindow};
|
||||
LayoutWindows();
|
||||
|
||||
@@ -144,30 +144,12 @@ void Update(const Event &event) {
|
||||
view->update_scroll = true;
|
||||
window->mouse_in_scrollbar = false;
|
||||
}
|
||||
HandleEvent(event);
|
||||
|
||||
HandleEvent(event);
|
||||
ReloadLuaConfig();
|
||||
For(Windows) if (it.is_title_bar) ReplaceTitleBarData(&it);
|
||||
ReplaceDebugData();
|
||||
|
||||
if (LuaBuffer->dirty == false && LuaBuffer->change_id != LuaBufferChangeID) {
|
||||
Scratch scratch;
|
||||
String16 string16 = GetString(*LuaBuffer);
|
||||
String string = ToString(scratch, string16);
|
||||
if (luaL_dostring(LuaState, string.data) == LUA_OK) {
|
||||
if (lua_isstring(LuaState, -1)) {
|
||||
const char *text = lua_tostring(LuaState, -1);
|
||||
ReportConsolef(text);
|
||||
lua_pop(LuaState, 1);
|
||||
}
|
||||
ReloadColors();
|
||||
} else {
|
||||
const char *error_message = lua_tostring(LuaState, -1);
|
||||
ReportWarningf("Failed to load user config! %s", error_message);
|
||||
lua_pop(LuaState, 1);
|
||||
}
|
||||
LuaBufferChangeID = LuaBuffer->change_id;
|
||||
}
|
||||
|
||||
For(IterateInReverse(&order)) {
|
||||
Window *window = &Windows[it];
|
||||
{
|
||||
@@ -290,43 +272,8 @@ int main()
|
||||
Buffer *null_buffer = CreateBuffer(sys_allocator, "*scratch*");
|
||||
View *null_view = CreateView(null_buffer->id);
|
||||
|
||||
{
|
||||
// Init base config, test that it works and initialize the lua stuff
|
||||
if (!luaL_dostring(LuaState, BaseLuaConfig.data) == LUA_OK) {
|
||||
const char *error_message = lua_tostring(LuaState, -1);
|
||||
ReportErrorf("Failed to load base lua config! %s", error_message);
|
||||
lua_pop(LuaState, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Init user config
|
||||
Scratch scratch;
|
||||
String lua_config_path = Format(scratch, "%.*s/init.lua", FmtString(ConfigDir));
|
||||
|
||||
#if DEBUG_BUILD
|
||||
// WARNING! Delete config to make sure we are running this code more frequently
|
||||
SDL_RemovePath(lua_config_path.data);
|
||||
#endif
|
||||
|
||||
LuaBuffer = BufferOpenFile(lua_config_path);
|
||||
if (LuaBuffer->len) {
|
||||
String16 string16 = GetString(*LuaBuffer);
|
||||
String string = ToString(scratch, string16);
|
||||
if (luaL_dostring(LuaState, string.data) == LUA_OK) {
|
||||
ReloadColors();
|
||||
} else {
|
||||
const char *error_message = lua_tostring(LuaState, -1);
|
||||
ReportWarningf("Failed to load user config! %s", error_message);
|
||||
lua_pop(LuaState, 1);
|
||||
}
|
||||
} else {
|
||||
ReplaceText(LuaBuffer, {}, ToString16(scratch, BaseLuaConfig));
|
||||
}
|
||||
|
||||
LuaBufferChangeID = LuaBuffer->change_id;
|
||||
}
|
||||
|
||||
InitWindows(null_view);
|
||||
ReloadLuaConfig();
|
||||
|
||||
while (AppIsRunning) {
|
||||
FrameID += 1;
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
- bugs:
|
||||
- scrolling in fullscreen is busted because no space outside of window
|
||||
- scrolling when clicking on scroller is busted
|
||||
- page up and down should also scroll and leave you in exactly same scroll
|
||||
- Shift + click is not selecting!!!
|
||||
|
||||
- underline the word which can be loaded / executed
|
||||
- search as a command to execute which is going to be in the title bar
|
||||
|
||||
- commands:
|
||||
- indent selected lines
|
||||
- trim whitespace
|
||||
- Ctrl + G should select the line number in bar
|
||||
- How to make search into bar?
|
||||
- command window should close on esacpe but make it more coherent
|
||||
|
||||
- simulation:
|
||||
- make the editor replayable, store events and then replay
|
||||
@@ -33,7 +45,6 @@
|
||||
- open selected string or auto enclosed word when right clicking or middle (this needs to be also handled on keyboard level)
|
||||
|
||||
|
||||
- page up and down should also scroll and leave you in exactly same scroll
|
||||
|
||||
- word completion
|
||||
- Colored strings
|
||||
|
||||
@@ -20,6 +20,16 @@ Array<VisualColumn> GetVisualColumns(Allocator allocator) {
|
||||
return columns;
|
||||
}
|
||||
|
||||
Window *GetLayoutWindow(int n) {
|
||||
int i = 0;
|
||||
ForItem(window, Windows) {
|
||||
if (!window.visible || window.absolute_position || window.is_title_bar) continue;
|
||||
if (n == i) return &window;
|
||||
i += 1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Array<Int> GetWindowZOrder(Allocator allocator) {
|
||||
Array<Int> order = {allocator};
|
||||
For(Windows) if (it.z == 2) Add(&order, GetIndex(Windows, it));
|
||||
@@ -169,7 +179,6 @@ void InitWindows(View *null_view) {
|
||||
SetVisibility(w, false);
|
||||
|
||||
CommandWindowID = w->id;
|
||||
Command_EvalLua(v, L"list_buffers()");
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user