perf ui browser: Add method to draw up/down arrow line
authorArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 27 Apr 2012 19:27:52 +0000 (16:27 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 27 Apr 2012 19:27:52 +0000 (16:27 -0300)
It figures out the direction and draws downwards arrows too if that is
the case.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-tg329nr7q4dg9d0tl3o0wywg@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/ui/browser.c
tools/perf/ui/browser.h

index 32ac1165100d4b2bf967716e8723d92e3f66de76..f4b2530ae1d3e10832e4ed2f4cd54d0a4bc28747 100644 (file)
@@ -600,8 +600,9 @@ void ui_browser__write_graph(struct ui_browser *browser __used, int graph)
        SLsmg_set_char_set(0);
 }
 
-void __ui_browser__line_arrow_up(struct ui_browser *browser, unsigned int column,
-                                u64 start, u64 end, int start_width)
+static void __ui_browser__line_arrow_up(struct ui_browser *browser,
+                                       unsigned int column,
+                                       u64 start, u64 end, int start_width)
 {
        unsigned int row, end_row;
 
@@ -639,6 +640,55 @@ out:
        SLsmg_set_char_set(0);
 }
 
+static void __ui_browser__line_arrow_down(struct ui_browser *browser,
+                                         unsigned int column,
+                                         u64 start, u64 end, int start_width)
+{
+       unsigned int row, end_row;
+
+       SLsmg_set_char_set(1);
+
+       if (start >= browser->top_idx) {
+               row = start - browser->top_idx;
+               ui_browser__gotorc(browser, row, column);
+               SLsmg_write_char(SLSMG_ULCORN_CHAR);
+               ui_browser__gotorc(browser, row, column + 1);
+               SLsmg_draw_hline(start_width);
+
+               if (row++ == 0)
+                       goto out;
+       } else
+               row = 0;
+
+       if (end >= browser->top_idx + browser->height)
+               end_row = browser->height - 1;
+       else
+               end_row = end - browser->top_idx;;
+
+       ui_browser__gotorc(browser, row, column);
+       SLsmg_draw_vline(end_row - row + 1);
+
+       ui_browser__gotorc(browser, end_row, column);
+       if (end < browser->top_idx + browser->height) {
+               SLsmg_write_char(SLSMG_LLCORN_CHAR);
+               ui_browser__gotorc(browser, end_row, column + 1);
+               SLsmg_write_char(SLSMG_HLINE_CHAR);
+               ui_browser__gotorc(browser, end_row, column + 2);
+               SLsmg_write_char(SLSMG_RARROW_CHAR);
+       }
+out:
+       SLsmg_set_char_set(0);
+}
+
+void __ui_browser__line_arrow(struct ui_browser *browser, unsigned int column,
+                             u64 start, u64 end, int start_width)
+{
+       if (start > end)
+               __ui_browser__line_arrow_up(browser, column, start, end, start_width);
+       else
+               __ui_browser__line_arrow_down(browser, column, start, end, start_width);
+}
+
 void ui_browser__init(void)
 {
        int i = 0;
index 2f226cb79f6ab159a54fabfa264bc4c67a1e2913..059764b29b2dab9d892ae6135a96f7a37c9616f3 100644 (file)
@@ -38,8 +38,8 @@ void ui_browser__reset_index(struct ui_browser *self);
 
 void ui_browser__gotorc(struct ui_browser *self, int y, int x);
 void ui_browser__write_graph(struct ui_browser *browser, int graph);
-void __ui_browser__line_arrow_up(struct ui_browser *browser, unsigned int column,
-                                u64 start, u64 end, int start_width);
+void __ui_browser__line_arrow(struct ui_browser *browser, unsigned int column,
+                             u64 start, u64 end, int start_width);
 void __ui_browser__show_title(struct ui_browser *browser, const char *title);
 void ui_browser__show_title(struct ui_browser *browser, const char *title);
 int ui_browser__show(struct ui_browser *self, const char *title,