summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editor.c1
-rw-r--r--file.c2
-rw-r--r--window.c15
-rw-r--r--window.h1
4 files changed, 19 insertions, 0 deletions
diff --git a/editor.c b/editor.c
index f7fc684..b83ad26 100644
--- a/editor.c
+++ b/editor.c
@@ -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, ...)
diff --git a/file.c b/file.c
index 606fcc3..88f789e 100644
--- a/file.c
+++ b/file.c
@@ -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;
diff --git a/window.c b/window.c
index 031caef..bbd7d2f 100644
--- a/window.c
+++ b/window.c
@@ -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;
diff --git a/window.h b/window.h
index a414f6f..a5fa195 100644
--- a/window.h
+++ b/window.h
@@ -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();