aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/interface-curses.cpp18
-rw-r--r--src/interface-gtk.cpp8
-rw-r--r--src/string-utils.cpp36
-rw-r--r--src/string-utils.h2
4 files changed, 60 insertions, 4 deletions
diff --git a/src/interface-curses.cpp b/src/interface-curses.cpp
index 9060a0b..a9bb466 100644
--- a/src/interface-curses.cpp
+++ b/src/interface-curses.cpp
@@ -38,6 +38,7 @@
#endif
#include "sciteco.h"
+#include "string-utils.h"
#include "cmdline.h"
#include "qregisters.h"
#include "ring.h"
@@ -226,14 +227,27 @@ InterfaceCurses::draw_info(void)
wbkgdset(info_window, ' ' | SCI_COLOR_ATTR(COLOR_BLACK, COLOR_WHITE));
waddstr(info_window, info_current);
wclrtoeol(info_window);
+
+#ifdef PDCURSES
+ PDC_set_title(info_current);
+#endif
}
void
InterfaceCurses::info_update_impl(const QRegister *reg)
{
+ /*
+ * We cannot rely on Curses' control character drawing
+ * and we need the info_current string for other purposes
+ * (like PDC_set_title()), so we "canonicalize" the
+ * register name here:
+ */
+ gchar *name = String::canonicalize_ctl(reg->name);
+
g_free(info_current);
- info_current = g_strdup_printf("%s - <QRegister> %s", PACKAGE_NAME,
- reg->name);
+ info_current = g_strdup_printf("%s - <QRegister> %s",
+ PACKAGE_NAME, name);
+ g_free(name);
draw_info();
}
diff --git a/src/interface-gtk.cpp b/src/interface-gtk.cpp
index 14dfafd..c8c96f5 100644
--- a/src/interface-gtk.cpp
+++ b/src/interface-gtk.cpp
@@ -36,6 +36,7 @@
#include <ScintillaWidget.h>
#include "sciteco.h"
+#include "string-utils.h"
#include "cmdline.h"
#include "qregisters.h"
#include "ring.h"
@@ -168,10 +169,13 @@ InterfaceGtk::show_view_impl(ViewGtk *view)
void
InterfaceGtk::info_update_impl(const QRegister *reg)
{
+ gchar *name = String::canonicalize_ctl(reg->name);
gchar buf[255];
- g_snprintf(buf, sizeof(buf), "%s - <QRegister> %s", PACKAGE_NAME,
- reg->name);
+ g_snprintf(buf, sizeof(buf), "%s - <QRegister> %s",
+ PACKAGE_NAME, name);
+ g_free(name);
+
gtk_window_set_title(GTK_WINDOW(window), buf);
}
diff --git a/src/string-utils.cpp b/src/string-utils.cpp
index 6481765..7da9875 100644
--- a/src/string-utils.cpp
+++ b/src/string-utils.cpp
@@ -21,10 +21,46 @@
#include <glib.h>
+#include "sciteco.h"
#include "string-utils.h"
namespace SciTECO {
+/**
+ * Canonicalize control characters in str.
+ * This converts all control characters to printable
+ * characters without tabs, line feeds, etc.
+ * Useful for displaying Q-Register names and
+ * TECO code.
+ */
+gchar *
+String::canonicalize_ctl(const gchar *str)
+{
+ gsize ret_len = 1; /* for trailing 0 */
+ gchar *ret, *p;
+
+ /*
+ * Instead of approximating size with strlen()
+ * we can just as well calculate it exactly:
+ */
+ for (const gchar *p = str; *p; p++)
+ ret_len += IS_CTL(*p) ? 2 : 1;
+
+ p = ret = (gchar *)g_malloc(ret_len);
+
+ while (*str) {
+ if (IS_CTL(*str)) {
+ *p++ = '^';
+ *p++ = CTL_ECHO(*str++);
+ } else {
+ *p++ = *str++;
+ }
+ }
+ *p = '\0';
+
+ return ret;
+}
+
void
String::get_coord(const gchar *str, gint pos,
gint &line, gint &column)
diff --git a/src/string-utils.h b/src/string-utils.h
index e2f7be3..aa646d6 100644
--- a/src/string-utils.h
+++ b/src/string-utils.h
@@ -75,6 +75,8 @@ append(gchar *&str, gchar chr)
append(str, buf);
}
+gchar *canonicalize_ctl(const gchar *str);
+
void get_coord(const gchar *str, gint pos,
gint &line, gint &column);