93 lines
3.8 KiB
C++
93 lines
3.8 KiB
C++
WindowID BuildWindowID;
|
|
ViewID BuildViewID;
|
|
BufferID BuildBufferID;
|
|
|
|
void InitBuildWindow() {
|
|
Window *window = CreateWind();
|
|
BuildWindowID = window->id;
|
|
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(ProjectFolder, "build"));
|
|
buffer->special = true;
|
|
buffer->no_history = true;
|
|
BuildBufferID = buffer->id;
|
|
View *view = CreateView(buffer->id);
|
|
view->special = true;
|
|
BuildViewID = view->id;
|
|
window->active_view = view->id;
|
|
window->secondary_window_style = true;
|
|
window->draw_line_highlight = true;
|
|
window->primary = false;
|
|
window->visible = false;
|
|
window->lose_visibility_on_escape = true;
|
|
window->jump_history = false;
|
|
}
|
|
|
|
void LayoutBuildWindow(Rect2I *rect, int16_t wx, int16_t wy) {
|
|
Unused(wx); Unused(wy);
|
|
Window *window = GetWindow(BuildWindowID);
|
|
Rect2I copy_rect = *rect;
|
|
if (!window->visible) {
|
|
rect = ©_rect;
|
|
}
|
|
Int barsize = window->font->line_spacing * 10;
|
|
window->document_rect = window->total_rect = CutBottom(rect, barsize);
|
|
}
|
|
|
|
BSet ExecBuild(String windows_cmd, String unix_cmd, String working_dir = ProjectFolder) {
|
|
SaveAll();
|
|
Scratch scratch;
|
|
BSet build = GetBSet(BuildWindowID);
|
|
BSet main = GetBSet(PrimaryWindowID);
|
|
SelectRange(build.view, Range{});
|
|
ResetBuffer(build.buffer);
|
|
{
|
|
ExecArgs args = ShellArgs(scratch, build.view->id, OS_WINDOWS ? windows_cmd : unix_cmd, working_dir);
|
|
args.scroll_to_end = true;
|
|
Exec(args);
|
|
}
|
|
main.window->active_goto_list = build.view->id;
|
|
main.window->goto_list_pos = -1;
|
|
build.window->visible = true;
|
|
return build;
|
|
}
|
|
|
|
void CMD_Build1() {
|
|
ExecBuild(Build1OnWindows, Build1OnUnix);
|
|
} RegisterCommand(CMD_Build1, "ctrl-b", "Run Build1OnWindows or OnUnix in working directory, output is printed in a popup console and a special build buffer");
|
|
|
|
void CMD_Build2() {
|
|
ExecBuild(Build2OnWindows, Build2OnUnix);
|
|
} RegisterCommand(CMD_Build2, "alt-b", "Run Build2OnWindows or OnUnix in working directory, output is printed in a popup console and a special build buffer");
|
|
|
|
void CMD_Build3() {
|
|
ExecBuild(Build3OnWindows, Build3OnUnix);
|
|
} RegisterCommand(CMD_Build3, "shift-b", "Run Build3OnWindows or OnUnix in working directory, output is printed in a popup console and a special build buffer");
|
|
|
|
void CMD_Build4() {
|
|
ExecBuild(Build4OnWindows, Build4OnUnix);
|
|
} RegisterCommand(CMD_Build4, "ctrl-alt-b", "Run Build4OnWindows or OnUnix in working directory, output is printed in a popup console and a special build buffer");
|
|
|
|
void CMD_RunFile() {
|
|
Scratch scratch;
|
|
BSet primary = GetBSet(PrimaryWindowID);
|
|
// @todo: this calls for language_cpp, language_c, language_python etc.
|
|
String windows_command = "";
|
|
String unix_command = "";
|
|
if (EndsWith(primary.buffer->name, ".py")) {
|
|
unix_command = windows_command = Format(scratch, "python %S", primary.buffer->name);
|
|
} else {
|
|
windows_command = Format(scratch, "cl %S -Fe:cfile.exe /Zi /FC /nologo /WX /W3 /wd4200 /wd4334 /diagnostics:column && cfile.exe && del cfile.*", primary.buffer->name);
|
|
unix_command = Format(scratch, "bash <<EOF\nclang %S -o cfile.exe -g -Wall -Wno-missing-braces -Wno-writable-strings -Wno-writable-strings -fsanitize=address -fdiagnostics-absolute-paths -lm \n./cfile.exe \nrm cfile.exe\nEOF", primary.buffer->name);
|
|
}
|
|
ExecBuild(windows_command, unix_command, GetDirectory(primary.buffer));
|
|
} RegisterCommand(CMD_RunFile, "", "Run and build current file, currently only C/C++ supported");
|
|
|
|
void CMD_ShowBuildWindow() {
|
|
BSet main = GetBSet(BuildWindowID);
|
|
if (ActiveWindowID != BuildWindowID) {
|
|
main.window->visible = true;
|
|
NextActiveWindowID = BuildWindowID;
|
|
} else {
|
|
main.window->visible = false;
|
|
}
|
|
} RegisterCommand(CMD_ShowBuildWindow, "ctrl-grave", "Toggles visibility of the build window");
|