fix [#24586] Report mode of console does not show proper cariage returns.
authorCampbell Barton <ideasman42@gmail.com>
Thu, 2 Dec 2010 21:48:46 +0000 (21:48 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 2 Dec 2010 21:48:46 +0000 (21:48 +0000)
use the line iterator to split up newlines.

source/blender/editors/space_info/info_draw.c
source/blender/editors/space_info/info_intern.h
source/blender/editors/space_info/info_report.c
source/blender/editors/space_info/textview.h

index fe2c0efe44d1d2710d3687581bdbe285f05b71f5..cc5e02c6266a5e87b88929556b1ba4e30d392df2 100644 (file)
 
 #include "UI_resources.h"
 
+#include "info_intern.h"
 #include "../space_info/textview.h"
 
+/* complicates things a bit, so leaving in old simple code */
+#define USE_INFO_NEWLINE
+
 static void info_report_color(unsigned char *fg, unsigned char *bg, Report *report, int bool)
 {
        /*
@@ -89,8 +93,34 @@ static void info_report_color(unsigned char *fg, unsigned char *bg, Report *repo
        }
 }
 
-
 /* reports! */
+#ifdef USE_INFO_NEWLINE
+static void report_textview_init__internal(TextViewContext *tvc)
+{
+       Report *report= (Report *)tvc->iter;
+       const char *str= report->message;
+       const char *next_str= strchr(str + tvc->iter_char, '\n');
+
+       if(next_str) {
+               tvc->iter_char_next= (int)(next_str - str);
+       }
+       else {
+               tvc->iter_char_next= report->len;
+       }
+}
+
+static int report_textview_skip__internal(TextViewContext *tvc)
+{
+       SpaceInfo *sinfo= (SpaceInfo *)tvc->arg1;
+       const int report_mask= info_report_mask(sinfo);
+       while (tvc->iter && (((Report *)tvc->iter)->type & report_mask)==0) {
+               tvc->iter= (void *)((Link *)tvc->iter)->prev;
+       }
+       return (tvc->iter != NULL);
+}
+
+#endif // USE_INFO_NEWLINE
+
 static int report_textview_begin(TextViewContext *tvc)
 {
        // SpaceConsole *sc= (SpaceConsole *)tvc->arg1;
@@ -106,7 +136,21 @@ static int report_textview_begin(TextViewContext *tvc)
        glClearColor(120.0/255.0, 120.0/255.0, 120.0/255.0, 1.0);
        glClear(GL_COLOR_BUFFER_BIT);
 
+#ifdef USE_INFO_NEWLINE
+       tvc->iter_tmp= 0;
+       if(tvc->iter && report_textview_skip__internal(tvc)) {
+               /* init the newline iterator */
+               tvc->iter_char= 0;
+               report_textview_init__internal(tvc);
+
+               return TRUE;
+       }
+       else {
+               return FALSE;
+       }
+#else
        return (tvc->iter != NULL);
+#endif
 }
 
 static void report_textview_end(TextViewContext *UNUSED(tvc))
@@ -114,9 +158,62 @@ static void report_textview_end(TextViewContext *UNUSED(tvc))
        /* pass */
 }
 
+#ifdef USE_INFO_NEWLINE
+static int report_textview_step(TextViewContext *tvc)
+{
+       /* simple case, but no newline support */
+       Report *report= (Report *)tvc->iter;
+
+       if(report->len <= tvc->iter_char_next) {
+               tvc->iter= (void *)((Link *)tvc->iter)->prev;
+               if(tvc->iter && report_textview_skip__internal(tvc)) {
+                       tvc->iter_tmp++;
+
+                       tvc->iter_char= 0; /* reset start */
+                       report_textview_init__internal(tvc);
+
+                       return TRUE;
+               }
+               else {
+                       return FALSE;
+               }
+       }
+       else {
+               /* step to the next newline */
+               tvc->iter_char= tvc->iter_char_next + 1;
+               report_textview_init__internal(tvc);
+
+               return TRUE;
+       }
+}
+
+static int report_textview_line_get(struct TextViewContext *tvc, const char **line, int *len)
+{
+       Report *report= (Report *)tvc->iter;
+       *line= report->message + tvc->iter_char;
+       *len= tvc->iter_char_next - tvc->iter_char;
+       return 1;
+}
+
+static int report_textview_line_color(struct TextViewContext *tvc, unsigned char fg[3], unsigned char bg[3])
+{
+       Report *report= (Report *)tvc->iter;
+       info_report_color(fg, bg, report, tvc->iter_tmp % 2);
+       return TVC_LINE_FG | TVC_LINE_BG;
+}
+
+
+#else // USE_INFO_NEWLINE
+
 static int report_textview_step(TextViewContext *tvc)
 {
-       return ((tvc->iter= (void *)((Link *)tvc->iter)->prev) != NULL);
+       SpaceInfo *sinfo= (SpaceInfo *)tvc->arg1;
+       const int report_mask= info_report_mask(sinfo);
+       do {
+               tvc->iter= (void *)((Link *)tvc->iter)->prev;
+       } while (tvc->iter && (((Report *)tvc->iter)->type & report_mask)==0);
+
+       return (tvc->iter != NULL);
 }
 
 static int report_textview_line_get(struct TextViewContext *tvc, const char **line, int *len)
@@ -131,10 +228,13 @@ static int report_textview_line_get(struct TextViewContext *tvc, const char **li
 static int report_textview_line_color(struct TextViewContext *tvc, unsigned char fg[3], unsigned char bg[3])
 {
        Report *report= (Report *)tvc->iter;
-       info_report_color(fg, bg, report, tvc->iter_index % 2);
+       info_report_color(fg, bg, report, tvc->iter_tmp % 2);
        return TVC_LINE_FG | TVC_LINE_BG;
 }
 
+#endif // USE_INFO_NEWLINE
+
+#undef USE_INFO_NEWLINE
 
 static int info_textview_main__internal(struct SpaceInfo *sinfo, struct ARegion *ar, ReportList *reports, int draw, int mval[2], void **mouse_pick, int *pos_pick)
 {
index 4953bc1b4bef7bb9a77fd82dacec885623a312ca..abbe37a4fe1912652835c19ac6aaca1e53b9eee8 100644 (file)
@@ -49,7 +49,7 @@ int info_textview_height(struct SpaceInfo *sinfo, struct ARegion *ar, struct Rep
 void info_textview_main(struct SpaceInfo *sinfo, struct ARegion *ar, struct ReportList *reports);
 
 /* info_report.c */
-/* console_report.c */
+int info_report_mask(struct SpaceInfo *sinfo);
 void INFO_OT_select_pick(struct wmOperatorType *ot); /* report selection */
 void INFO_OT_select_all_toggle(struct wmOperatorType *ot);
 void INFO_OT_select_border(struct wmOperatorType *ot);
index 0fc8e157d92f2808ac4c34382fe5f8694373a2de..8ae9c1293ebb310ea6ef2185f959887a12f50689 100644 (file)
@@ -45,8 +45,9 @@
 
 #include "info_intern.h"
 
-int info_report_mask(SpaceInfo *sinfo)
+int info_report_mask(SpaceInfo *UNUSED(sinfo))
 {
+#if 0
        int report_mask = 0;
 
        if(sinfo->rpt_mask & INFO_RPT_DEBUG)    report_mask |= RPT_DEBUG_ALL;
@@ -56,6 +57,9 @@ int info_report_mask(SpaceInfo *sinfo)
        if(sinfo->rpt_mask & INFO_RPT_ERR)              report_mask |= RPT_ERROR_ALL;
 
        return report_mask;
+#endif
+
+       return RPT_DEBUG_ALL|RPT_INFO_ALL|RPT_OPERATOR_ALL|RPT_WARNING_ALL|RPT_ERROR_ALL;
 }
 
 // TODO, get this working again!
index 390f9f5ed7cea8248abe361f35e4fbc528a9eb50..aeea12827beccc21c2e638b9988b26d74bc331d1 100644 (file)
@@ -45,6 +45,9 @@ typedef struct TextViewContext {
        int (*line_color)(struct TextViewContext *tvc, unsigned char fg[3], unsigned char bg[3]);
        void *iter;
        int iter_index;
+       int iter_char;          /* char intex, used for multi-line report display */
+       int iter_char_next;     /* same as above, next \n */
+       int iter_tmp;           /* internal iterator use */
 
 } TextViewContext;