Trace buffer vs Debug buffer, print Buffer info, Add SaveAll

This commit is contained in:
2025-08-21 09:16:31 +02:00
parent 24533dfe7f
commit 166f06d1fb
10 changed files with 72 additions and 10 deletions

View File

@@ -391,9 +391,19 @@ function KeybindsBasic(e)
return false
end
FKey = {"build.bat", "", "", "", "", "", "", "", "", "", "", ""}
function BasicBuild()
SaveAll()
if OS_VALUE == OS_WINDOWS then
return "build.bat"
else
return "./build.sh"
end
end
FKey = {BasicBuild, "", "", "", "", "", "", "", "", "", "", ""}
FKeySDLK = {SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5, SDLK_F6, SDLK_F7, SDLK_F8, SDLK_F9, SDLK_F10, SDLK_F11, SDLK_F12}
function KeybindsFKeys(e)
for i = #FKey,1,-1 do
if FKey[i] ~= "" then

View File

@@ -14,4 +14,5 @@ int main() {
Add(&array, String{"\n)==\";\n"});
String result = Merge(scratch, array, "");
WriteFile("../src/text_editor/generated_config.cpp", result);
}

View File

@@ -226,9 +226,7 @@ void ReportWarningf(const char *fmt, ...) {
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"));
Command_Appendf(TraceView, "%.*s\n", FmtString(string));
}
void Command_MoveCursorsByPageSize(Window *window, int direction, bool shift = false) {
@@ -696,6 +694,18 @@ int Lua_Save(lua_State *L) {
return 0;
}
void Command_SaveAll() {
for (Buffer *it = FirstBuffer; it; it = it->next) {
if (it->file_mod_time) {
SaveBuffer(it);
}
}
}
int Lua_SaveAll(lua_State *L) {
Command_SaveAll();
return 0;
}
void Command_KillSelectedLines(View *view) {
Scratch scratch;
Buffer *buffer = GetBuffer(view->active_buffer);

View File

@@ -392,9 +392,19 @@ function KeybindsBasic(e)
return false
end
FKey = {"build.bat", "", "", "", "", "", "", "", "", "", "", ""}
function BasicBuild()
SaveAll()
if OS_VALUE == OS_WINDOWS then
return "build.bat"
else
return "./build.sh"
end
end
FKey = {BasicBuild, "", "", "", "", "", "", "", "", "", "", ""}
FKeySDLK = {SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5, SDLK_F6, SDLK_F7, SDLK_F8, SDLK_F9, SDLK_F10, SDLK_F11, SDLK_F12}
function KeybindsFKeys(e)
for i = #FKey,1,-1 do
if FKey[i] ~= "" then

View File

@@ -14,12 +14,11 @@ int Lua_print(lua_State *L) {
int Lua_Print(lua_State *L) {
Scratch scratch;
int nargs = lua_gettop(L);
View *view = GetView(DebugViewID);
for (int i = 1; i <= nargs; i += 1) {
String string = lua_tostring(L, i);
Command_Appendf(view, "%.*s ", FmtString(string));
Command_Appendf(TraceView, "%.*s ", FmtString(string));
}
Command_Appendf(view, "\n");
Command_Appendf(TraceView, "\n");
lua_pop(L, nargs);
return 0;
}

View File

@@ -1,6 +1,7 @@
luaL_Reg LuaFunctions[] = {
{"print", Lua_print},
{"Print", Lua_Print},
{"SaveAll", Lua_SaveAll},
{"Kill", Lua_Kill},
{"GetLoadWord", Lua_GetLoadWord},
{"BufferExists", Lua_BufferExists},

View File

@@ -38,6 +38,8 @@ Buffer *LuaConfigBuffer;
Buffer *GCInfoBuffer;
Buffer *EventBuffer;
Buffer *ScratchBuffer;
Buffer *TraceBuffer;
View *TraceView;
String WorkDir;
RandomSeed UniqueBufferNameSeed = {};
@@ -74,6 +76,8 @@ void InitScratchBuffer() {
View *null_view = CreateView(null_buffer->id);
Assert(null_buffer->id == NullBufferID && null_view->id == NullViewID);
TraceBuffer = CreateBuffer(sys_allocator, GetUniqueBufferName(WorkDir, "trace"));
TraceView = CreateView(TraceBuffer->id);
GCInfoBuffer = CreateBuffer(sys_allocator, GetUniqueBufferName(WorkDir, "gc"));
EventBuffer = CreateBuffer(sys_allocator, GetUniqueBufferName(WorkDir, "events"));
ScratchBuffer = BufferOpenFile(GetUniqueBufferName(WorkDir, "scratch"));

View File

@@ -239,6 +239,7 @@ void Update(Event event) {
UpdateCo(&event);
ReloadLuaConfigs();
CallLuaOnUpdate(&event);
UpdateDebugBuffer();
GarbageCollect();
For(IterateInReverse(&order)) {

View File

@@ -15,8 +15,32 @@ void UpdateDebugBuffer() {
float xmouse, ymouse;
SDL_GetMouseState(&xmouse, &ymouse);
RawAppendf(buffer, "mouse: [%f, %f]\n", xmouse, ymouse);
RawAppendf(buffer, "C:/Work/text_editor/src/text_editor/text_editor.cpp\n");
RawAppendf(buffer, "config dir: %.*s\n", FmtString(ConfigDir));
RawAppendf(buffer, "BufferID id = %d\n", main.buffer->id.id);
RawAppendf(buffer, "Buffer *next = %zu\n", main.buffer->next);
RawAppendf(buffer, "Buffer *prev = %zu\n", main.buffer->prev);
RawAppendf(buffer, "String name = %.*s\n", FmtString(main.buffer->name));
RawAppendf(buffer, "Int change_id = %lld\n", (long long)main.buffer->change_id);
RawAppendf(buffer, "Int user_change_id = %lld\n", (long long)main.buffer->user_change_id);
RawAppendf(buffer, "Int file_mod_time = %lld\n", (long long)main.buffer->file_mod_time);
RawAppendf(buffer, "\n");
RawAppendf(buffer, "U16 *data = %zu\n", main.buffer->data);
RawAppendf(buffer, "Int len = %lld\n", (long long)main.buffer->len);
RawAppendf(buffer, "Int cap = %lld\n", (long long)main.buffer->cap);
RawAppendf(buffer, "Array<Int> line_starts = {len = %lld, cap = %lld, data = %zu}\n", (long long)main.buffer->line_starts.len, (long long)main.buffer->line_starts.cap, main.buffer->line_starts.data);
RawAppendf(buffer, "\n");
RawAppendf(buffer, "Array<HistoryEntry> undo_stack = {len = %lld, cap = %lld, data = %zu}\n", (long long)main.buffer->undo_stack.len, (long long)main.buffer->undo_stack.cap, main.buffer->undo_stack.data);
RawAppendf(buffer, "Array<HistoryEntry> redo_stack = {len = %lld, cap = %lld, data = %zu}\n", (long long)main.buffer->redo_stack.len, (long long)main.buffer->redo_stack.cap, main.buffer->redo_stack.data);
RawAppendf(buffer, "int edit_phase = %d", main.buffer->edit_phase);
RawAppendf(buffer, "\n");
RawAppendf(buffer, "int no_history = %d\n", main.buffer->no_history);
RawAppendf(buffer, "int no_line_starts = %d\n", main.buffer->no_line_starts);
RawAppendf(buffer, "int dirty = %d\n", main.buffer->dirty);
RawAppendf(buffer, "int changed_on_disk = %d\n", main.buffer->changed_on_disk);
RawAppendf(buffer, "int garbage = %d\n", main.buffer->garbage);
}
void ReplaceTitleBarData(Window *window) {

View File

@@ -12,6 +12,8 @@ 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
PLATFORM Fix windows build
ISSUE What to do / how should Reopen work after we delete the file on disk in some other program?
- 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?)