소스 검색

[app.h] Adding function to create buffer list

Vinicius Teshima 1 년 전
부모
커밋
f216725918
1개의 변경된 파일32개의 추가작업 그리고 0개의 파일을 삭제
  1. 32 0
      src/app.h

+ 32 - 0
src/app.h

@@ -12,6 +12,8 @@
 
 #include "buffer.h"
 
+#define BUF_NAME_LST "<Buffer_List>"
+
 DA_DEF_STRUCT(struct buffer, app_buffers);
 
 enum keybind_dir {
@@ -83,6 +85,8 @@ struct vec2i app_calc_cursor(struct app app);
 
 struct ret_app_vec2 app_calc_buffer_cam(struct app app, double dt);
 
+struct buffer *app_create_buffer_list(struct app *app);
+
 void app_add_global_keybind(struct app *app, const char *keybind,
 			    keybind_func func, enum keybind_dir dir);
 
@@ -254,6 +258,34 @@ app_calc_buffer_cam(struct app app, double dt)
 	};
 }
 
+
+struct buffer *
+app_create_buffer_list(struct app *app)
+{
+	struct buffer *buf = NULL;
+	for ( size_t i = 0; i < app->bufs.size; ++i ) {
+		if ( str_eq_cstr_ns(app->bufs.items[i].name, BUF_NAME_LST) ) {
+			buf = &app->bufs.items[i];
+			break;
+		}
+	}
+	if ( buf == NULL ) {
+		DA_APPEND(app->bufs, buffer_create());
+		buf = &DA_TAIL(app->bufs);
+	}
+	buf->name = str_from_cstr_ns(BUF_NAME_LST);
+
+	for ( size_t i = 0; i < app->bufs.size; ++i ) {
+		if ( str_eq_cstr_ns(app->bufs.items[i].name, BUF_NAME_LST) ) {
+			continue;
+		}
+
+		buffer_insert_str_as_line(buf, app->bufs.items[i].name);
+	}
+
+	return buf;
+}
+
 static SDL_KeyCode
 char_to_keycode(char c)
 {