lchat

A line oriented chat front end for ii.
git clone git://git.suckless.org/lchat
Log | Files | Refs | README

commit 02a8a6ac430d7987f9f0b5af9280e72b6b43019f
parent ee4b1cfdb77b67d8e9ca491c3f2f11d9e3805851
Author: Jan Klemkow <j.klemkow@wemelug.de>
Date:   Sun, 25 Oct 2015 01:56:23 +0200

prepare terminal handling

Diffstat:
MMakefile | 2+-
Mlchat.c | 13++++++++++++-
2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -8,7 +8,7 @@ clean: rm -f lchat *.o lchat: lchat.o slackline.o - $(CC) -o $@ lchat.o slackline.o + $(CC) -o $@ lchat.o slackline.o -ltermlib lchat.o: lchat.c $(CC) -c $(CFLAGS) -o $@ lchat.c diff --git a/lchat.c b/lchat.c @@ -1,6 +1,7 @@ #include <err.h> #include <stdio.h> #include <stdlib.h> +#include <term.h> #include <termios.h> #include <unistd.h> @@ -20,9 +21,18 @@ main(void) { struct termios term; struct slackline *sl = sl_init(); + char *term_name = getenv("TERM"); int fd = STDIN_FILENO; int c; + if (term_name == NULL) + errx(EXIT_FAILURE, "environment TERM is not set"); + + switch (tgetent(NULL, term_name)) { + case -1: err(EXIT_FAILURE, "tgetent"); + case 0: errx(EXIT_FAILURE, "no termcap entry found for %s", term_name); + } + if (isatty(fd) == 0) err(EXIT_FAILURE, "isatty"); @@ -46,7 +56,8 @@ main(void) setbuf(stdout, NULL); while ((c = getchar()) != 13) { - sl_keystroke(sl, c); + if (sl_keystroke(sl, c) == -1) + errx(EXIT_FAILURE, "sl_keystroke"); printf("c: %d: buf: %s\r\n", c, sl->buf); }