perf ui browser: Introduce ui_browser__write_nstring()

To remove direct access to libslang functions, with the immediate goal
of implementing horizontal scrolling at the ui_browser level, but also
because we may at some point want to implement ui_browser with other UIs
in addition to the current libslang implementation.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-437ineavoejzou727mr9bxpi@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
index 6680fa5..5c730ab 100644
--- a/tools/perf/ui/browser.c
+++ b/tools/perf/ui/browser.c
@@ -46,6 +46,12 @@
 	SLsmg_gotorc(browser->y + y, browser->x + x);
 }
 
+void ui_browser__write_nstring(struct ui_browser *browser __maybe_unused, const char *msg,
+			       unsigned int width)
+{
+	slsmg_write_nstring(msg, width);
+}
+
 static struct list_head *
 ui_browser__list_head_filter_entries(struct ui_browser *browser,
 				     struct list_head *pos)
@@ -234,7 +240,7 @@
 {
 	SLsmg_gotorc(0, 0);
 	ui_browser__set_color(browser, HE_COLORSET_ROOT);
-	slsmg_write_nstring(title, browser->width + 1);
+	ui_browser__write_nstring(browser, title, browser->width + 1);
 }
 
 void ui_browser__show_title(struct ui_browser *browser, const char *title)
diff --git a/tools/perf/ui/browser.h b/tools/perf/ui/browser.h
index 92ae721..ba276c7 100644
--- a/tools/perf/ui/browser.h
+++ b/tools/perf/ui/browser.h
@@ -37,6 +37,8 @@
 void ui_browser__reset_index(struct ui_browser *browser);
 
 void ui_browser__gotorc(struct ui_browser *browser, int y, int x);
+void ui_browser__write_nstring(struct ui_browser *browser, const char *msg,
+			       unsigned int width);
 void ui_browser__write_graph(struct ui_browser *browser, int graph);
 void __ui_browser__line_arrow(struct ui_browser *browser, unsigned int column,
 			      u64 start, u64 end);
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index b5fc847..c14f8f9 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -141,22 +141,22 @@
 					slsmg_printf("%6.2f ", bdl->samples[i].percent);
 			}
 		} else {
-			slsmg_write_nstring(" ", 7 * ab->nr_events);
+			ui_browser__write_nstring(browser, " ", 7 * ab->nr_events);
 		}
 	} else {
 		ui_browser__set_percent_color(browser, 0, current_entry);
-		slsmg_write_nstring(" ", 7 * ab->nr_events);
+		ui_browser__write_nstring(browser, " ", 7 * ab->nr_events);
 	}
 	if (ab->have_cycles) {
 		if (dl->ipc)
 			slsmg_printf("%*.2f ", IPC_WIDTH - 1, dl->ipc);
 		else
-			slsmg_write_nstring(" ", IPC_WIDTH);
+			ui_browser__write_nstring(browser, " ", IPC_WIDTH);
 		if (dl->cycles)
 			slsmg_printf("%*" PRIu64 " ",
 				     CYCLES_WIDTH - 1, dl->cycles);
 		else
-			slsmg_write_nstring(" ", CYCLES_WIDTH);
+			ui_browser__write_nstring(browser, " ", CYCLES_WIDTH);
 	}
 
 	SLsmg_write_char(' ');
@@ -166,7 +166,7 @@
 		width += 1;
 
 	if (!*dl->line)
-		slsmg_write_nstring(" ", width - pcnt_width);
+		ui_browser__write_nstring(browser, " ", width - pcnt_width);
 	else if (dl->offset == -1) {
 		if (dl->line_nr && annotate_browser__opts.show_linenr)
 			printed = scnprintf(bf, sizeof(bf), "%-*d ",
@@ -174,8 +174,8 @@
 		else
 			printed = scnprintf(bf, sizeof(bf), "%*s  ",
 				    ab->addr_width, " ");
-		slsmg_write_nstring(bf, printed);
-		slsmg_write_nstring(dl->line, width - printed - pcnt_width + 1);
+		ui_browser__write_nstring(browser, bf, printed);
+		ui_browser__write_nstring(browser, dl->line, width - printed - pcnt_width + 1);
 	} else {
 		u64 addr = dl->offset;
 		int color = -1;
@@ -194,7 +194,7 @@
 							    bdl->jump_sources);
 					prev = annotate_browser__set_jumps_percent_color(ab, bdl->jump_sources,
 											 current_entry);
-					slsmg_write_nstring(bf, printed);
+					ui_browser__write_nstring(browser, bf, printed);
 					ui_browser__set_color(browser, prev);
 				}
 
@@ -208,7 +208,7 @@
 
 		if (change_color)
 			color = ui_browser__set_color(browser, HE_COLORSET_ADDR);
-		slsmg_write_nstring(bf, printed);
+		ui_browser__write_nstring(browser, bf, printed);
 		if (change_color)
 			ui_browser__set_color(browser, color);
 		if (dl->ins && dl->ins->ops->scnprintf) {
@@ -222,11 +222,11 @@
 				ui_browser__write_graph(browser, SLSMG_RARROW_CHAR);
 				SLsmg_write_char(' ');
 			} else {
-				slsmg_write_nstring(" ", 2);
+				ui_browser__write_nstring(browser, " ", 2);
 			}
 		} else {
 			if (strcmp(dl->name, "retq")) {
-				slsmg_write_nstring(" ", 2);
+				ui_browser__write_nstring(browser, " ", 2);
 			} else {
 				ui_browser__write_graph(browser, SLSMG_LARROW_CHAR);
 				SLsmg_write_char(' ');
@@ -234,7 +234,7 @@
 		}
 
 		disasm_line__scnprintf(dl, bf, sizeof(bf), !annotate_browser__opts.use_offset);
-		slsmg_write_nstring(bf, width - pcnt_width - 3 - printed);
+		ui_browser__write_nstring(browser, bf, width - pcnt_width - 3 - printed);
 	}
 
 	if (current_entry)
diff --git a/tools/perf/ui/browsers/header.c b/tools/perf/ui/browsers/header.c
index e8278c5..f106817 100644
--- a/tools/perf/ui/browsers/header.c
+++ b/tools/perf/ui/browsers/header.c
@@ -25,7 +25,7 @@
 	ui_browser__set_color(browser, current_entry ? HE_COLORSET_SELECTED :
 						       HE_COLORSET_NORMAL);
 
-	slsmg_write_nstring(str, browser->width);
+	ui_browser__write_nstring(browser, str, browser->width);
 }
 
 static int list_menu__run(struct ui_browser *menu)
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index fa67613..9e94dc8 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -540,10 +540,10 @@
 
 	ui_browser__set_color(&browser->b, color);
 	hist_browser__gotorc(browser, row, 0);
-	slsmg_write_nstring(" ", offset);
+	ui_browser__write_nstring(&browser->b, " ", offset);
 	slsmg_printf("%c", folded_sign);
 	ui_browser__write_graph(&browser->b, show_annotated ? SLSMG_RARROW_CHAR : ' ');
-	slsmg_write_nstring(str, width);
+	ui_browser__write_nstring(&browser->b, str, width);
 }
 
 static void hist_browser__fprintf_callchain_entry(struct hist_browser *b __maybe_unused,
@@ -822,7 +822,7 @@
 		if (!browser->b.navkeypressed)
 			width += 1;
 
-		slsmg_write_nstring("", width);
+		ui_browser__write_nstring(&browser->b, "", width);
 
 		++row;
 		++printed;
@@ -899,7 +899,7 @@
 	hists__scnprintf_headers(headers, sizeof(headers), browser->hists);
 	ui_browser__gotorc(&browser->b, 0, 0);
 	ui_browser__set_color(&browser->b, HE_COLORSET_ROOT);
-	slsmg_write_nstring(headers, browser->b.width + 1);
+	ui_browser__write_nstring(&browser->b, headers, browser->b.width + 1);
 }
 
 static void ui_browser__hists_init_top(struct ui_browser *browser)
@@ -2057,7 +2057,7 @@
 		warn = bf;
 	}
 
-	slsmg_write_nstring(warn, browser->width - printed);
+	ui_browser__write_nstring(browser, warn, browser->width - printed);
 
 	if (current_entry)
 		menu->selection = evsel;
diff --git a/tools/perf/ui/browsers/map.c b/tools/perf/ui/browsers/map.c
index b11639f..fb1ae24 100644
--- a/tools/perf/ui/browsers/map.c
+++ b/tools/perf/ui/browsers/map.c
@@ -32,7 +32,7 @@
 		     sym->binding == STB_LOCAL  ? 'l' : 'w');
 	width = browser->width - ((mb->addrlen * 2) + 4);
 	if (width > 0)
-		slsmg_write_nstring(sym->name, width);
+		ui_browser__write_nstring(browser, sym->name, width);
 }
 
 /* FIXME uber-kludgy, see comment on cmd_report... */
diff --git a/tools/perf/ui/browsers/scripts.c b/tools/perf/ui/browsers/scripts.c
index 402d2bd..e13b48d 100644
--- a/tools/perf/ui/browsers/scripts.c
+++ b/tools/perf/ui/browsers/scripts.c
@@ -81,7 +81,7 @@
 	ui_browser__set_color(browser, current_entry ? HE_COLORSET_SELECTED :
 						       HE_COLORSET_NORMAL);
 
-	slsmg_write_nstring(sline->line, browser->width);
+	ui_browser__write_nstring(browser, sline->line, browser->width);
 }
 
 static int script_browser__run(struct perf_script_browser *browser)
diff --git a/tools/perf/ui/tui/util.c b/tools/perf/ui/tui/util.c
index bf890f7..d96ad7c 100644
--- a/tools/perf/ui/tui/util.c
+++ b/tools/perf/ui/tui/util.c
@@ -21,7 +21,7 @@
 
 	ui_browser__set_color(browser, current_entry ? HE_COLORSET_SELECTED :
 						       HE_COLORSET_NORMAL);
-	slsmg_write_nstring(*arg, browser->width);
+	ui_browser__write_nstring(browser, *arg, browser->width);
 }
 
 static int popup_menu__run(struct ui_browser *menu)