From 991892fff518f59f02bbe1c8a4637843a82bd74e Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Tue, 27 Sep 2016 23:30:10 +0200
Subject: Allow specifying terminal name in termo_new()
---
demo-async.c | 2 +-
demo-draw.c | 2 +-
demo-glib.c | 2 +-
demo.c | 2 +-
termo.c | 8 ++++++--
termo.h | 2 +-
tests/05read.c | 2 +-
7 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/demo-async.c b/demo-async.c
index 6b29a58..302312f 100644
--- a/demo-async.c
+++ b/demo-async.c
@@ -25,7 +25,7 @@ main (int argc, char *argv[])
TERMO_CHECK_VERSION;
setlocale (LC_CTYPE, "");
- termo_t *tk = termo_new (STDIN_FILENO, NULL, 0);
+ termo_t *tk = termo_new (STDIN_FILENO, NULL, NULL, 0);
if (!tk)
{
diff --git a/demo-draw.c b/demo-draw.c
index 26b583f..c193302 100644
--- a/demo-draw.c
+++ b/demo-draw.c
@@ -158,7 +158,7 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
- termo_t *tk = termo_new (STDIN_FILENO, NULL, 0);
+ termo_t *tk = termo_new (STDIN_FILENO, NULL, NULL, 0);
if (!tk)
{
fprintf (stderr, "Cannot allocate termo instance\n");
diff --git a/demo-glib.c b/demo-glib.c
index 80f3a7b..5ad346d 100644
--- a/demo-glib.c
+++ b/demo-glib.c
@@ -57,7 +57,7 @@ main (int argc, char *argv[])
TERMO_CHECK_VERSION;
setlocale (LC_CTYPE, "");
- tk = termo_new (STDIN_FILENO, NULL, 0);
+ tk = termo_new (STDIN_FILENO, NULL, NULL, 0);
if (!tk)
{
fprintf (stderr, "Cannot allocate termo instance\n");
diff --git a/demo.c b/demo.c
index bc416c0..6550358 100644
--- a/demo.c
+++ b/demo.c
@@ -46,7 +46,7 @@ main(int argc, char *argv[])
}
}
- tk = termo_new (STDIN_FILENO, NULL,
+ tk = termo_new (STDIN_FILENO, NULL, NULL,
TERMO_FLAG_SPACESYMBOL | TERMO_FLAG_CTRLC);
if (!tk)
{
diff --git a/termo.c b/termo.c
index 953bc88..8a92821 100644
--- a/termo.c
+++ b/termo.c
@@ -415,7 +415,7 @@ abort_free_to_utf32:
}
termo_t *
-termo_new (int fd, const char *encoding, int flags)
+termo_new (int fd, const char *term, const char *encoding, int flags)
{
termo_t *tk = termo_alloc ();
if (!tk)
@@ -424,7 +424,11 @@ termo_new (int fd, const char *encoding, int flags)
tk->fd = fd;
termo_set_flags (tk, flags);
- const char *term = getenv ("TERM");
+ // In theory, we might have multiple different terminals open
+ // simultaneously; I'm not currently sure if it works
+ if (!term)
+ term = getenv ("TERM");
+
if (termo_init (tk, term, encoding)
&& termo_start (tk))
return tk;
diff --git a/termo.h b/termo.h
index 9df3e73..624060c 100644
--- a/termo.h
+++ b/termo.h
@@ -203,7 +203,7 @@ enum
void termo_check_version (int major, int minor);
-termo_t *termo_new (int fd, const char *encoding, int flags);
+termo_t *termo_new (int fd, const char *term, const char *encoding, int flags);
termo_t *termo_new_abstract (const char *term,
const char *encoding, int flags);
void termo_free (termo_t *tk);
diff --git a/tests/05read.c b/tests/05read.c
index 226acca..67f2092 100644
--- a/tests/05read.c
+++ b/tests/05read.c
@@ -21,7 +21,7 @@ main (int argc, char *argv[])
// Sanitise this just in case
putenv ("TERM=vt100");
- tk = termo_new (fd[0], NULL, TERMO_FLAG_NOTERMIOS);
+ tk = termo_new (fd[0], NULL, NULL, TERMO_FLAG_NOTERMIOS);
is_int (termo_get_buffer_remaining (tk), 256,
"buffer free initially 256");
--
cgit v1.2.3-70-g09d2