Compare commits

...

2 Commits

Author SHA1 Message Date
Krzosa Karol
930620a49e Init variables, ReportErrorf now doesn't pop a message cause it doesn't do the queuing 2026-02-03 21:10:33 +01:00
Krzosa Karol
8cb1b49cd8 Fix ctrl-4 2026-02-03 20:06:56 +01:00
13 changed files with 125 additions and 57 deletions

View File

@@ -73,10 +73,10 @@ static const char *glsl_fshader_es3 = R"==(#version 300 es
} }
)=="; )==";
void ReportWarningf(const char *fmt, ...); void ReportErrorf(const char *fmt, ...);
void GLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *user) { void GLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *user) {
Unused(source); Unused(type); Unused(id); Unused(length); Unused(user); Unused(source); Unused(type); Unused(id); Unused(length); Unused(user);
ReportWarningf("OpenGL message: %s", message); ReportErrorf("OpenGL message: %s", message);
if (severity == GL_DEBUG_SEVERITY_HIGH || severity == GL_DEBUG_SEVERITY_MEDIUM) { if (severity == GL_DEBUG_SEVERITY_HIGH || severity == GL_DEBUG_SEVERITY_MEDIUM) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "OpenGL error", message, NULL); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "OpenGL error", message, NULL);
} }

View File

@@ -1557,7 +1557,7 @@ void SaveBuffer(Buffer *buffer) {
buffer->dirty = false; buffer->dirty = false;
buffer->temp = false; buffer->temp = false;
} else { } else {
ReportWarningf("Failed to save file with name: %S", buffer->name); ReportErrorf("Failed to save file with name: %S", buffer->name);
} }
} }

View File

@@ -67,6 +67,12 @@ void Appendf(View *view, const char *fmt, ...) {
Append(view, string, true); Append(view, string, true);
} }
void ReportConsolef(const char *fmt, ...) {
Scratch scratch;
STRING_FORMAT(scratch, fmt, string);
Appendf(LogView, "%S\n", string);
}
void ReportErrorf(const char *fmt, ...) { void ReportErrorf(const char *fmt, ...) {
ErrorCount += 1; ErrorCount += 1;
Scratch scratch; Scratch scratch;
@@ -77,28 +83,11 @@ void ReportErrorf(const char *fmt, ...) {
if (LogView) { if (LogView) {
Appendf(LogView, "%S\n", string); Appendf(LogView, "%S\n", string);
ShowUIMessagef("%S", string);
} else { } else {
printf("%.*s\n", (int)string.len, string.data); printf("%.*s\n", (int)string.len, string.data);
} }
} }
void ReportConsolef(const char *fmt, ...) {
Scratch scratch;
STRING_FORMAT(scratch, fmt, string);
Appendf(LogView, "%S\n", string);
}
void ReportWarningf(const char *fmt, ...) {
ErrorCount += 1;
Scratch scratch;
STRING_FORMAT(scratch, fmt, string);
if (BreakOnError) {
BREAK();
}
Appendf(LogView, "%S\n", string);
}
void CMD_CenterView() { void CMD_CenterView() {
CenterView(PrimaryWindowID); CenterView(PrimaryWindowID);
} RegisterCommand(CMD_CenterView, "", ""); } RegisterCommand(CMD_CenterView, "", "");

View File

@@ -4,7 +4,7 @@ struct Lexer {
char *start; char *start;
char *end; char *end;
char *name; char *name;
int line, column; Int line, column;
}; };
enum TriggerKind { enum TriggerKind {
@@ -34,6 +34,11 @@ struct CachedTrigger {
}; };
Array<CachedTrigger> CachedTriggers; Array<CachedTrigger> CachedTriggers;
Lexer MakeLexer(Allocator allocator, String string, char *file, Int line, Int column) {
Lexer lexer = {allocator, string.data, string.data, string.data + string.len, file, line, column};
return lexer;
}
void Advance(Lexer *lex) { void Advance(Lexer *lex) {
if (lex->at < lex->end) { if (lex->at < lex->end) {
if (lex->at[0] == '\n') { if (lex->at[0] == '\n') {

View File

@@ -61,7 +61,7 @@ void UpdateCoroutines(Event *event) {
_CoroutineContext = &it; _CoroutineContext = &it;
mco_result ok = mco_resume(it.co); mco_result ok = mco_resume(it.co);
if (ok != MCO_SUCCESS) { if (ok != MCO_SUCCESS) {
ReportWarningf("failed to resume coroutine %d", ok); ReportErrorf("failed to resume coroutine %d", ok);
DestroyCoroutine(&it); DestroyCoroutine(&it);
remove_item = true; remove_item = true;
} }

View File

@@ -176,6 +176,7 @@ RegisterVariable(String, OpenCodePatterns, ".c .h .cpp .hpp .cc .cxx .rs .go .zi
RegisterVariable(String, OpenCodeExcludePatterns, ""); RegisterVariable(String, OpenCodeExcludePatterns, "");
RegisterVariable(Int, TrimTrailingWhitespace, 1); RegisterVariable(Int, TrimTrailingWhitespace, 1);
// PROJECT_MANAGEMENT // PROJECT_MANAGEMENT
// Set at the beginning of the program to current directory // Set at the beginning of the program to current directory
RegisterVariable(String, ProjectDirectory, ""); RegisterVariable(String, ProjectDirectory, "");

View File

@@ -56,17 +56,6 @@ void CMD_EvalCommandsLineByLine() {
EvalCommandsLineByLine(set); EvalCommandsLineByLine(set);
} RegisterCommand(CMD_EvalCommandsLineByLine, "", "Goes line by line over a buffer and evaluates every line as a command, ignores empty or lines starting with '//'"); } RegisterCommand(CMD_EvalCommandsLineByLine, "", "Goes line by line over a buffer and evaluates every line as a command, ignores empty or lines starting with '//'");
Variable *GetVariable(String name) {
Variable *var = NULL;
For (Variables) {
if (name == it.name) {
var = &it;
break;
}
}
return var;
}
BufferID LoadConfig(String config_path) { BufferID LoadConfig(String config_path) {
ReportConsolef("Loading config %S...", config_path); ReportConsolef("Loading config %S...", config_path);
Window *window = GetWindow(NullWindowID); Window *window = GetWindow(NullWindowID);

View File

@@ -1,3 +1,4 @@
#if PLUGIN_CONFIG #if PLUGIN_CONFIG
void Set(String string); void Set(String string);
String InsertVariables(Allocator allocator, String string);
#endif #endif

View File

@@ -2133,7 +2133,7 @@ bool RDBG_InitConnection(mco_coro *co, bool create_session = true) {
} }
if (file.len == 0) { if (file.len == 0) {
ReportWarningf("Couldn't find neither .rdbg file, nor use the BinaryUnderDebug variable to locate the binary"); ReportErrorf("Couldn't find neither .rdbg file, nor use the BinaryUnderDebug variable to locate the binary");
return false; return false;
} }
} }

View File

@@ -57,7 +57,7 @@ void CMD_FocusWindow4() {
Window *third = GetOverlappingWindow(GetSideOfWindow(second, DIR_RIGHT)); Window *third = GetOverlappingWindow(GetSideOfWindow(second, DIR_RIGHT));
if (third) { if (third) {
Window *fourth = GetOverlappingWindow(GetSideOfWindow(third, DIR_RIGHT)); Window *fourth = GetOverlappingWindow(GetSideOfWindow(third, DIR_RIGHT));
if (fourth) NextActiveWindowID = third->id; if (fourth) NextActiveWindowID = fourth->id;
} }
} }
} }

View File

@@ -1,5 +1,6 @@
// MAAAAAAAAAAAAN I DONT LIKE THIS CODE, BUT HOPE IT WORKS // MAAAAAAAAAAAAN I DONT LIKE THIS CODE, BUT HOPE IT WORKS
// @todo: potentially bad that we are not checking against end! lexer->at[0] == 0 check is not enough
struct Lexer2 { struct Lexer2 {
char16_t *at; char16_t *at;
}; };

View File

@@ -854,25 +854,15 @@ extern char **environ;
int main(int argc, char **argv) int main(int argc, char **argv)
#endif #endif
{ {
InitScratch();
InitOS(ReportErrorf);
#if OS_WINDOWS #if OS_WINDOWS
int argc = __argc; int argc = __argc;
char **argv = __argv; char **argv = __argv;
AttachConsole(ATTACH_PARENT_PROCESS); AttachConsole(ATTACH_PARENT_PROCESS);
#endif #endif
InitScratch();
if (1) { InitOS(ReportErrorf);
RunArenaTest(); ProjectDirectory = GetWorkingDir(Perm);
For (TestFunctions) { #if OS_WINDOWS
it.function();
}
// ReportErrorf("Testing DONE\n");
// return 0;
}
#if OS_WINDOWS
{ {
wchar_t *p = GetEnvironmentStringsW(); wchar_t *p = GetEnvironmentStringsW();
for (;p && p[0];) { for (;p && p[0];) {
@@ -889,7 +879,16 @@ int main(int argc, char **argv)
} }
#endif #endif
ProjectDirectory = GetWorkingDir(Perm); if (1) {
RunArenaTest();
For (TestFunctions) {
it.function();
}
// ReportErrorf("Testing DONE\n");
// return 0;
}
{ {
String sdl_config_path = SDL_GetPrefPath("krzosa", "text_editor"); String sdl_config_path = SDL_GetPrefPath("krzosa", "text_editor");
if (sdl_config_path.len && sdl_config_path.data[sdl_config_path.len - 1] == '\\') { if (sdl_config_path.len && sdl_config_path.data[sdl_config_path.len - 1] == '\\') {
@@ -1009,7 +1008,7 @@ int main(int argc, char **argv)
ReloadFont(PathToFont, (U32)FontSize); ReloadFont(PathToFont, (U32)FontSize);
CreateWind(); CreateWind();
ReopenBuffer(GetBuffer(NullBufferID)); ReopenBuffer(GetBuffer(NullBufferID));
InitOS(ReportWarningf); InitOS(ReportErrorf);
For (GlobalCommands) { For (GlobalCommands) {
if (it.binding.len != 0) { if (it.binding.len != 0) {

View File

@@ -217,11 +217,88 @@ bool IsOpenBoundary(char c) {
return result; return result;
} }
/* Variable *GetVariable(String name) {
Variable *var = NULL;
For (Variables) {
if (name == it.name) {
var = &it;
break;
}
}
return var;
}
Variables that control the default shell for '!' commands String InsertVariables(Allocator allocator, String string) {
DefaultShellWindows - "cmd" Scratch scratch(allocator);
DefaultShellUnix - "bash | sh" Array<String> parts = {scratch};
String it = string;
for (;;) {
int64_t idx = 0;
bool found = Seek(it, "@", &idx, SeekFlag_None);
if (!found) {
if (it.len > 0) {
Add(&parts, it);
}
break;
}
String prev = GetPrefix(it, idx);
if (prev.len > 0) {
Add(&parts, prev);
}
it = Skip(it, idx + 1);
char c = At(it, 0);
String name = {};
if (c == '@') {
Add(&parts, String{"@", 1});
it = Skip(it, 1);
continue;
} else if (c == '(') {
char *start = it.data + 1;
while (At(it, 0) && At(it, 0) != ')') {
it = Skip(it, 1);
}
Int len = it.data - start;
name = {start, len};
it = Skip(it, 1); // skip ')'
} else {
char *start = it.data;
while (IsAlphanumeric(At(it, 0))) {
it = Skip(it, 1);
}
Int len = it.data - start;
name = {start, len};
}
Variable *variable = GetVariable(name);
if (!variable) {
ReportErrorf("Variable: %S, not found", name);
return string;
}
if (variable->type != VariableType_String) {
// @todo: this will not report - open will override
ReportErrorf("Variable: %S, not of type String", variable->type);
return string;
}
Add(&parts, *variable->string);
}
String result = Merge(allocator, parts, "");
return result;
}
void TestInsertVariable() {
Scratch scratch;
String a = "Thing/@(ProjectDirectory)/Another";
String b = "Thing/@ProjectDirectory/Another";
Assert(InsertVariables(scratch, a) == InsertVariables(scratch, b));
int c = 10;
} RegisterFunction(&TestFunctions, TestInsertVariable);
/*
Variables: Variables:
@ProjectDirectory/build/te @ProjectDirectory/build/te
@@ -249,7 +326,13 @@ Otherwise it does filepath parsing:
TODO: need to add '~', but where? TODO: need to add '~', but where?
TODO: on linux find shell on first command and set as default
USECASE: Wouldn't it be cool to just select a part of codebase pipe that into a script
and get a result in a clipboard or capture the output and change the selection.
TODO: Data desc language
!{bash,Out:Sel} SCRIPT
!{bash,Out:Clip} SCRIPT
Use variables for injecting selection: @Sel
*/ */
ResolvedOpen ResolveOpen(Allocator alo, Window *window, String path, ResolveOpenMeta meta) { ResolvedOpen ResolveOpen(Allocator alo, Window *window, String path, ResolveOpenMeta meta) {
@@ -258,7 +341,7 @@ ResolvedOpen ResolveOpen(Allocator alo, Window *window, String path, ResolveOpen
bool exec = !(ResolveOpenMeta_DontExec & meta); bool exec = !(ResolveOpenMeta_DontExec & meta);
#if PLUGIN_CONFIG #if PLUGIN_CONFIG
// @todo: variable substitution {{ProjectDirectory}}/build/te.exe path = InsertVariables(alo, path);
if (exec && result.kind == OpenKind_Invalid && StartsWith(path, ":Set ")) { if (exec && result.kind == OpenKind_Invalid && StartsWith(path, ":Set ")) {
result.kind = OpenKind_Set; result.kind = OpenKind_Set;