diff options
-rw-r--r-- | editor.c | 1 | ||||
-rw-r--r-- | file.c | 2 | ||||
-rw-r--r-- | window.c | 15 | ||||
-rw-r--r-- | window.h | 1 |
4 files changed, 19 insertions, 0 deletions
@@ -28,6 +28,7 @@ void init_editor(struct editor_state* editor) editor->mode = EDITOR_MODE_NORMAL; editor_update_screen_size(editor); + window_set_filename("[New]"); } void editor_set_status_message(struct editor_state* editor, const char* format, ...) @@ -42,6 +42,7 @@ void editor_open(struct editor_state* editor, char* filename) memcpy(editor->filename, filename, filename_len); editor_select_syntax_highlight(editor); + window_set_filename(filename); /* If there is no file with this name, the editor will create it on save. */ if (access(filename, F_OK) != 0) @@ -78,6 +79,7 @@ void editor_save(struct editor_state* editor) return; editor_select_syntax_highlight(editor); + window_set_filename(editor->filename); } int length; @@ -1,5 +1,6 @@ #include "window.h" +#include <unistd.h> #include <SDL2/SDL.h> #include "buffer.h" @@ -177,6 +178,20 @@ void window_redraw(struct editor_state *editor) SDL_UpdateWindowSurface(window); } +void window_set_filename(const char *filename) +{ +#define TITLE_BUFSIZE 128 +#define WORKDIR_BUFSIZE 128 + + char titlebuf[TITLE_BUFSIZE]; + char cwdbuf[WORKDIR_BUFSIZE]; + char *workdir; + workdir = getcwd(cwdbuf, WORKDIR_BUFSIZE); + + snprintf(titlebuf, TITLE_BUFSIZE, "%s - (%s)", filename, workdir); + SDL_SetWindowTitle(window, titlebuf); +} + void window_get_size(int *rows, int *cols) { *cols = window_width / font.width; @@ -6,6 +6,7 @@ struct editor_state; void window_init(const char *title, int rows, int cols); int window_handle_event(struct editor_state *editor); void window_redraw(struct editor_state *editor); +void window_set_filename(const char *filename); void window_get_size(int *rows, int *cols); void window_destroy(); |