diff --git a/src/basic/filesystem.h b/src/basic/filesystem.h index 6650213..de9d740 100644 --- a/src/basic/filesystem.h +++ b/src/basic/filesystem.h @@ -38,6 +38,7 @@ struct Process { bool is_valid; int exit_code; char platform[6 * 8]; + int64_t id; int64_t view_id; // text editor view bool scroll_to_end; diff --git a/src/basic/unix.cpp b/src/basic/unix.cpp index 3063085..80c1312 100644 --- a/src/basic/unix.cpp +++ b/src/basic/unix.cpp @@ -216,15 +216,6 @@ FileIter IterateFiles(Allocator alo, String path) { return it; } -// struct Process { -// bool is_valid; -// int exit_code; -// char platform[6 * 8]; -// -// int64_t view_id; // text editor view -// bool scroll_to_end; -// }; - struct UnixProcess { pid_t pid; int child_stdout_read; @@ -262,9 +253,6 @@ Process SpawnProcess(String command_line, String working_dir, String write_stdin const int PIPE_WRITE = 1; bool error = false; - printf("cmd = %.*s\n", FmtString(command_line)); - printf("cwd = %.*s\n", FmtString(working_dir)); - char *buffer = AllocArray(scratch, char, 4096); chdir(working_dir.data); getcwd(buffer, 4096); @@ -285,7 +273,7 @@ Process SpawnProcess(String command_line, String working_dir, String write_stdin posix_spawn_file_actions_t actions = {}; if (posix_spawn_file_actions_init(&actions) != 0) { - perror("posix_spawn_file_actions_init"); + Error("Libc function failed: posix_spawn_file_actions_init, with error: %s", strerror(errno)); return process; } defer { @@ -293,7 +281,7 @@ Process SpawnProcess(String command_line, String working_dir, String write_stdin }; if (pipe(stdout_desc) == -1) { - perror("pipe"); + Error("Libc function failed: pipe, with error: %s", strerror(errno)); return process; } defer { @@ -306,7 +294,7 @@ Process SpawnProcess(String command_line, String working_dir, String write_stdin }; if (pipe(stdin_desc) == -1) { - perror("pipe"); + Error("Libc function failed: pipe, with error: %s", strerror(errno)); return process; } defer { @@ -320,38 +308,38 @@ Process SpawnProcess(String command_line, String working_dir, String write_stdin error = posix_spawn_file_actions_addclose(&actions, stdout_desc[PIPE_READ]) != 0; if (error) { - perror("posix_spawn_file_actions_addclose"); + Error("Libc function failed: posix_spawn_file_actions_addclose, with error: %s", strerror(errno)); return process; } error = posix_spawn_file_actions_adddup2(&actions, stdout_desc[PIPE_WRITE], STDOUT_FILENO) != 0; if (error) { - perror("posix_spawn_file_actions_adddup2 STDOUT_FILENO"); + Error("Libc function failed: posix_spawn_file_actions_adddup2 STDOUT_FILENO, with error: %s", strerror(errno)); return process; } error = posix_spawn_file_actions_adddup2(&actions, stdout_desc[PIPE_WRITE], STDERR_FILENO) != 0; if (error) { - perror("posix_spawn_file_actions_adddup2 STDERR_FILENO"); + Error("Libc function failed: posix_spawn_file_actions_adddup2 STDERR_FILENO, with error: %s", strerror(errno)); return process; } error = posix_spawn_file_actions_addclose(&actions, stdin_desc[PIPE_WRITE]) != 0; if (error) { - perror("posix_spawn_file_actions_addclose"); + Error("Libc function failed: posix_spawn_file_actions_addclose, with error: %s", strerror(errno)); return process; } error = posix_spawn_file_actions_adddup2(&actions, stdin_desc[PIPE_READ], STDIN_FILENO) != 0; if (error) { - perror("posix_spawn_file_actions_adddup2 STDIN_FILENO"); + Error("Libc function failed: posix_spawn_file_actions_adddup2 STDIN_FILENO, with error: %s", strerror(errno)); return process; } pid_t process_pid = 0; error = posix_spawnp(&process_pid, args[0], &actions, NULL, args.data, env.data) != 0; if (error) { - perror("failed to create process\n"); + Error("Libc function failed: failed to create process\n, with error: %s", strerror(errno)); return process; } @@ -365,6 +353,7 @@ Process SpawnProcess(String command_line, String working_dir, String write_stdin CloseStdin(&process); } + process.id = process_pid; process.is_valid = true; return process; } diff --git a/src/basic/win32.cpp b/src/basic/win32.cpp index 3b9f9c7..865668c 100644 --- a/src/basic/win32.cpp +++ b/src/basic/win32.cpp @@ -418,6 +418,7 @@ Process SpawnProcess(String command_line, String working_dir, String write_stdin p->handle = info.hProcess; process.is_valid = true; + process.id = (int64_t)p->handle; if (write_stdin.len) { WriteStdin(&process, write_stdin); diff --git a/src/render/opengl.cpp b/src/render/opengl.cpp index 6de791a..8994d72 100644 --- a/src/render/opengl.cpp +++ b/src/render/opengl.cpp @@ -75,8 +75,9 @@ void EndFrameRender(float wx, float wy, Color color) { } } +void ReportWarningf(const char *fmt, ...); void GLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *user) { - printf("%s", message); + ReportWarningf("OpenGL message: %s", message); if (severity == GL_DEBUG_SEVERITY_HIGH || severity == GL_DEBUG_SEVERITY_MEDIUM) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "OpenGL error", message, NULL); } diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index bee4400..cacc5c9 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -223,6 +223,14 @@ void ReportWarningf(const char *fmt, ...) { ActiveWindow = NullWindowID; } +void ReportDebugf(const char *fmt, ...) { + Scratch scratch; + STRING_FORMAT(scratch, fmt, string); + Buffer *buffer = GetBuffer(DebugBufferID); + ReplaceWithoutMovingCarets(buffer, GetEndAsRange(buffer), ToString16(scratch, string)); + ReplaceWithoutMovingCarets(buffer, GetEndAsRange(buffer), ToString16(scratch, "\n")); +} + void Command_MoveCursorsByPageSize(Window *window, int direction, bool shift = false) { Assert(direction == DIR_UP || direction == DIR_DOWN); BSet set = GetBSet(window); diff --git a/src/text_editor/process.cpp b/src/text_editor/process.cpp index 49b571b..29756da 100644 --- a/src/text_editor/process.cpp +++ b/src/text_editor/process.cpp @@ -22,7 +22,7 @@ void UpdateProcesses() { Command_Append(view, poll, it.scroll_to_end); } if (!IsValid(&it)) { - printf("exit code = %d\n", it.exit_code); + ReportDebugf("process %lld exit code = %d", it.id, it.exit_code); remove_item = true; } } @@ -30,6 +30,7 @@ void UpdateProcesses() { void Exec(ViewID view, bool scroll_to_end, String cmd, String working_dir) { Process process = SpawnProcess(cmd, working_dir, {}, Enviroment); + ReportDebugf("process %lld start. is_valid = %d cmd = %.*s working_dir = %.*s", process.id, process.is_valid, FmtString(cmd), FmtString(working_dir)); process.view_id = view.id; process.scroll_to_end = scroll_to_end; if (process.is_valid) Add(&ActiveProcesses, process); @@ -42,6 +43,8 @@ void Exec(ViewID view, bool scroll_to_end, String16 cmd16, String working_dir) { } Buffer *ExecAndWait(Allocator allocator, String cmd, String working_dir, String stdin_string = {}) { + ReportDebugf("ExecAndWait cmd = %.*s working_dir = %.*s stdin_string = %.*s", FmtString(cmd), FmtString(working_dir), FmtString(stdin_string)); + Buffer *temp_buffer = CreateTempBuffer(allocator, 4096 * 4); for (Process process = SpawnProcess(cmd, working_dir, stdin_string, Enviroment); IsValid(&process);) { Scratch scratch(allocator); diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index fa83398..08761f1 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -239,7 +239,6 @@ void Update(Event event) { UpdateCo(&event); ReloadLuaConfigs(); CallLuaOnUpdate(&event); - UpdateDebugBuffer(); GarbageCollect(); For(IterateInReverse(&order)) { diff --git a/src/text_editor/text_editor.h b/src/text_editor/text_editor.h index 724b0aa..76f9b67 100644 --- a/src/text_editor/text_editor.h +++ b/src/text_editor/text_editor.h @@ -121,6 +121,7 @@ Array Command_ReplaceEx(Allocator scratch, View *view, String16 string); void Command_Eval(String string); void Command_Eval(String16 string); String Command_GetMainDir(); +void ReportDebugf(const char *fmt, ...); void ReplaceWithoutMovingCarets(Buffer *buffer, Range range, String16 string); void Command_Copy(View *view); diff --git a/src/text_editor/todo.txt b/src/text_editor/todo.txt index 5a9aaa2..5a6c40b 100644 --- a/src/text_editor/todo.txt +++ b/src/text_editor/todo.txt @@ -1,28 +1,20 @@ +FEATURE SaveAll dirty files which are saved on disk already but dirty DESIGN Config file versions, when loading should be checked, at the top of the file, what to do when old version? - ISSUE Ctrl+Alt+Down (DuplicateLine) doesn't work on ubuntu -DESIGN Add debug buffer that will hold info on exit codes and other debug information - DESIGN Moving vertically between splits, which keys??? DESIGN Console, when writing commands and evaling in console it should properly insert a new line after our thing when writing on last line DESIGN The cursor hopping history needs a bit of fixing, probably needs to be more complicated with collapsing commands FEATURE KillConsole, or maybe some window targetting but how?? -FEATURE SaveAll dirty files which are saved on disk already but dirty - ISSUE I hit a case where GC tried deleting a buffer which was not attached to the buffer list, it had zeroed next, prev. It happened after iterating through directories using the ctrl + period - FEATURE Search whole words, case sensitive etc. FEATURE Select all searched occurences DESIGN Indicate maybe on the console border that a process is running in the console! also maybe exit code when exits - -- Add metaprogram? -- PLATFORM Fix windows build +PLATFORM Fix windows build - Changing window properties by changing the window name? - commands for scrolling: center, cursor_at_bottom_of_screen, cursor_at_top - Add metadata to Lua bindings so that we would get a better listing (function args?, what else?) - Kill buffer command (it should be marked for deletion and deleted at the end of frame!) -- Save all command - Delete directory/file on disk command - Check. Convert more commands to taking buffer instead of view - Check. Rewrite more commands to use already implemented commands?