about summary refs log tree commit diff stats
path: root/src/ui/buffer.c
diff options
context:
space:
mode:
authorImmae <ismael.bouya@normalesup.org>2014-06-29 15:04:23 +0200
committerImmae <ismael.bouya@normalesup.org>2014-06-29 15:04:23 +0200
commit945d6559103bc774dccb70b2e2634f47aa80b771 (patch)
tree64f7d04b587ef8b7c09fca3d4260b49df165e7ae /src/ui/buffer.c
parentdada8793475e44575923c865aa39d2efeb3c5aca (diff)
downloadprofani-tty-945d6559103bc774dccb70b2e2634f47aa80b771.tar.gz
Implemented the buffer for windows resizing
Diffstat (limited to 'src/ui/buffer.c')
-rw-r--r--src/ui/buffer.c51
1 files changed, 37 insertions, 14 deletions
diff --git a/src/ui/buffer.c b/src/ui/buffer.c
index 0c0d4d90..6fc6394f 100644
--- a/src/ui/buffer.c
+++ b/src/ui/buffer.c
@@ -23,6 +23,15 @@ buffer_create() {
   return new_buff;
 }
 
+int buffer_size(ProfBuff* buffer) {
+  if(buffer->wrap == 1) {
+    return BUFF_SIZE;
+  }
+  else {
+    return buffer->current;
+  }
+}
+
 void
 buffer_free(ProfBuff* buffer) {
   int i = 0;
@@ -33,29 +42,32 @@ buffer_free(ProfBuff* buffer) {
   for(i = 0; i < imax; i++) {
     free(buffer->entry[i].message);
     free(buffer->entry[i].from);
+    free(buffer->entry[i].date_fmt);
   }
   free(buffer);
 }
 
 void
-buffer_push(ProfBuff* buffer, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message) {
+buffer_push(ProfBuff* buffer, const char show_char, const char * const date_fmt, int flags, int attrs, const char * const from, const char * const message) {
   int *current = &(buffer->current);
-  ProfBuffEntry e = buffer->entry[*current];
+  ProfBuffEntry* e = &(buffer->entry[buffer->current]);
 
   if(buffer->wrap == 1) {
-    free(e.message);
-    free(e.from);
+    free(e->message);
+    free(e->from);
   }
-  e.show_char = show_char;
-  e.tstamp = *tstamp;
-  e.flags = flags;
-  e.attrs = attrs;
+  e->show_char = show_char;
+  e->flags = flags;
+  e->attrs = attrs;
+
+  e->date_fmt = malloc(strlen(date_fmt)+1);
+  strcpy(e->date_fmt, date_fmt);
 
-  e.from = malloc(strlen(from)+1);
-  strcpy(e.from, from);
+  e->from = malloc(strlen(from)+1);
+  strcpy(e->from, from);
 
-  e.message = malloc(strlen(message)+1);
-  strcpy(e.message, message);
+  e->message = malloc(strlen(message)+1);
+  strcpy(e->message, message);
 
   *current += 1;
   if(*current >= BUFF_SIZE) {
@@ -64,11 +76,22 @@ buffer_push(ProfBuff* buffer, const char show_char, GTimeVal *tstamp, int flags,
   }
 }
 
+ProfBuffEntry
+buffer_yield_entry(ProfBuff* buffer, int entry) {
+  return (buffer->entry)[entry];
+  if(buffer->wrap == 1) {
+    return buffer->entry[(buffer->current + entry) % BUFF_SIZE];
+  }
+  else {
+    return buffer->entry[entry % (buffer->current)];
+  }
+}
+
 int
 buffer_yield(ProfBuff* buffer, int line, ProfBuffEntry** list) {
-  //Returns the (line+1)-th last line
+  //Returns the size of the (line+1)-th last line, and list contains the line
   //e.g. if line == 0, returns the last line
-  //To correct for splitted lines...
+  //bug if the wrap happens in the middle of a line
   int current = buffer->current;
   int imax = current;
   if(buffer->wrap == 1) {