From 6fc5f0538f45e2edc05a2d6bce5a47315a5556ae Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sat, 17 Jan 2026 09:51:40 +0100 Subject: [PATCH] CMD_RunFile --- build.sh | 3 --- src/text_editor/plugin_build_window.cpp | 20 ++++++++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/build.sh b/build.sh index 364f229..380730e 100755 --- a/build.sh +++ b/build.sh @@ -4,9 +4,6 @@ mkdir build cd build FLAGS="-Wall -Wno-missing-braces -Wno-writable-strings -nostdlib++ -fsanitize=address -fno-exceptions -fdiagnostics-absolute-paths -g -Wno-writable-strings -I../src -DDEBUG_BUILD=1" -# clang -o metaprogram $FLAGS ../src/metaprogram/metaprogram.cpp -# ./metaprogram - I="-I../src/external/SDL/include -I../src/external/lua/src -I../src/external/glad" clang -o te $FLAGS ../src/text_editor/text_editor.cpp $I -lSDL3 -lm -lbacktrace diff --git a/src/text_editor/plugin_build_window.cpp b/src/text_editor/plugin_build_window.cpp index ec397fd..eaafc47 100644 --- a/src/text_editor/plugin_build_window.cpp +++ b/src/text_editor/plugin_build_window.cpp @@ -31,12 +31,12 @@ void LayoutBuildWindow(Rect2I *rect, int16_t wx, int16_t wy) { window->document_rect = window->total_rect = CutBottom(rect, barsize); } -BSet ExecBuild(String cmd) { +BSet ExecBuild(String cmd, String working_dir = ProjectDirectory) { BSet build = GetBSet(BuildWindowID); BSet main = GetBSet(PrimaryWindowID); SelectRange(build.view, Range{}); ResetBuffer(build.buffer); - Exec(build.view->id, true, cmd, ProjectDirectory); + Exec(build.view->id, true, cmd, working_dir); main.window->active_goto_list = build.view->id; main.window->goto_list_pos = 0; return build; @@ -53,6 +53,22 @@ void CMD_Build() { main.window->visible = true; } RegisterCommand(CMD_Build, "f1", "Run build.sh or build.bat in working directory, output is printed in a popup console and a special build buffer"); +void CMD_RunFile() { + Scratch scratch; + BSet primary = GetBSet(PrimaryWindowID); + BSet build = GetBSet(BuildWindowID); + SaveBuffer(primary.buffer); + + if (OS_WINDOWS) { + String cmd = Format(scratch, "cl %S -Fe:cfile.exe /Zi /FC /nologo /WX /W3 /wd4200 /wd4334 /diagnostics:column && cfile.exe", primary.buffer->name); + ExecBuild(cmd, GetDir(primary.buffer)); + } else { + String cmd = Format(scratch, "bash <name); + ExecBuild(cmd, GetDir(primary.buffer)); + } + build.window->visible = true; +} RegisterCommand(CMD_RunFile, "", "Run and build current file, currently only C/C++ supported"); + void CMD_ShowBuildWindow() { BSet main = GetBSet(BuildWindowID); if (ActiveWindowID != BuildWindowID) {