diff --git a/programs/src/desktop/apps/filemanager/render.cpp b/programs/src/desktop/apps/filemanager/render.cpp index 84fa804..77185bb 100644 --- a/programs/src/desktop/apps/filemanager/render.cpp +++ b/programs/src/desktop/apps/filemanager/render.cpp @@ -217,16 +217,29 @@ void filemanager_on_draw(Window* win, Framebuffer& fb) { c.vline(cx, ty, system_font_height(), colors::ACCENT); } } else { + // Truncate by pixel width so names never overflow cells + int max_w = FM_GRID_CELL_W - 4; + const char* name = fm->entry_names[i]; + int nlen = montauk::slen(name); char label[64]; - int nlen = montauk::slen(fm->entry_names[i]); - if (nlen > 60) { - for (int k = 0; k < 60; k++) label[k] = fm->entry_names[i][k]; - label[60] = '.'; - label[61] = '.'; - label[62] = '\0'; - } else { - montauk::strncpy(label, fm->entry_names[i], 63); + montauk::strncpy(label, name, 63); + + if (text_width(label) > max_w && nlen > 3) { + int ellipsis_w = text_width("..."); + int final_len = nlen; + while (final_len > 1) { + label[final_len] = '\0'; + int w = text_width(label); + if (w + ellipsis_w <= max_w) break; + final_len--; + } + if (final_len > 60) final_len = 60; + label[final_len] = '.'; + label[final_len + 1] = '.'; + label[final_len + 2] = '.'; + label[final_len + 3] = '\0'; } + int tw = text_width(label); int tx = cell_x + (FM_GRID_CELL_W - tw) / 2; if (tx < cell_x) tx = cell_x; diff --git a/programs/src/edit/main.cpp b/programs/src/edit/main.cpp index b70930d..a6ea7a7 100644 --- a/programs/src/edit/main.cpp +++ b/programs/src/edit/main.cpp @@ -222,17 +222,47 @@ static void set_status(const char* msg) { // Build VFS path from filename static void build_path(const char* fname, char* out, int outMax) { - int i = 0; // Check if already has drive prefix bool hasPrefix = (fname[0] >= '0' && fname[0] <= '9' && fname[1] == ':'); - if (!hasPrefix) { - out[i++] = '0'; out[i++] = ':'; out[i++] = '/'; + + if (hasPrefix) { + // Absolute path - copy as-is + int i = 0; + while (fname[i] && i < outMax - 1) { + out[i++] = fname[i]; + } + out[i] = '\0'; + } else { + // Relative path - prepend CWD + char cwd[256]; + if (montauk::getcwd(cwd, sizeof(cwd)) > 0) { + int i = 0; + int j = 0; + // Copy CWD + while (cwd[j] && i < outMax - 1) { + out[i++] = cwd[j++]; + } + // Ensure we end with / + if (i > 0 && out[i-1] != '/') { + out[i++] = '/'; + } + // Append filename + j = 0; + while (fname[j] && i < outMax - 1) { + out[i++] = fname[j++]; + } + out[i] = '\0'; + } else { + // Fallback: just prepend 0:/ + int i = 0; + out[i++] = '0'; out[i++] = ':'; out[i++] = '/'; + int j = 0; + while (fname[j] && i < outMax - 1) { + out[i++] = fname[j++]; + } + out[i] = '\0'; + } } - int j = 0; - while (fname[j] && i < outMax - 1) { - out[i++] = fname[j++]; - } - out[i] = '\0'; } static void load_file(const char* fname) {