lchat

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

commit 1f48fc49963432855d340efd51abcc613bfcfd6c
parent 8340100b4c016335b15dc693c57d603a81a9831c
Author: Tom Schwindl <schwindl@posteo.de>
Date:   Sat,  8 Oct 2022 12:14:00 +0200

minor cleanup and adjustments

Diffstat:
MMakefile | 6+++---
MREADME.md | 4++--
Mconfig.mk | 16+++++-----------
Mlchat.c | 24+++++++++++++++++-------
4 files changed, 27 insertions(+), 23 deletions(-)

diff --git a/Makefile b/Makefile @@ -7,11 +7,11 @@ clean: rm -f lchat *.o *.core sl_test filter/indent install: lchat - cp lchat ${DESTDIR}${BINDIR} - cp lchat.1 ${DESTDIR}${MAN1DIR} + cp lchat $(DESTDIR)$(BINDIR) + cp lchat.1 $(DESTDIR)$(MAN1DIR) uninstall: - rm -f ${DESTDIR}${BINDIR}/lchat ${DESTDIR}${MAN1DIR}/lchat.1 + rm -f $(DESTDIR)$(BINDIR)/lchat $(DESTDIR)$(MAN1DIR)/lchat.1 test: sl_test ./sl_test diff --git a/README.md b/README.md @@ -1,9 +1,9 @@ line chat ========= -lchat (line chat) is a line oriented front end for for ii-like chat programs. +lchat (line chat) is a line oriented front end for ii-like chat programs. It handles the input from keyboard and output file in parallel. Thus, you are -able to type new messages while new chat lines arriving. Its main focus is on +able to type messages while new chat lines are arriving. Its main focus is on usability and simplicity. ![lchat](/lchat.png) diff --git a/config.mk b/config.mk @@ -1,16 +1,10 @@ # paths PREFIX = /usr/local -BINDIR = ${PREFIX}/bin -MANDIR = ${PREFIX}/share/man -MAN1DIR = ${MANDIR}/man1 +BINDIR = $(PREFIX)/bin +MANDIR = $(PREFIX)/share/man +MAN1DIR = $(MANDIR)/man1 -CC ?= cc -CFLAGS = -std=c99 -pedantic -Wall -Wextra -g +CFLAGS = -std=c99 -pedantic -Wall -Wextra -I/usr/local/include -# utf.h -CFLAGS += -I/usr/local/include +# grapheme.h LIBS = -L/usr/local/lib -lgrapheme - -# For sbase users: -#CFLAGS += -I../sbase -#LIBS = -L../sbase -lutf diff --git a/lchat.c b/lchat.c @@ -35,8 +35,8 @@ #define INFTIM -1 #endif -struct termios origin_term; -struct winsize winsize; +static struct termios origin_term; +static struct winsize winsize; static void sigwinch(int sig) @@ -48,6 +48,14 @@ sigwinch(int sig) static void exit_handler(void) { + char *title = getenv("TERM"); + + /* reset terminal's window name */ + if (strncmp(title, "screen", 6) == 0) + printf("\033k%s\033\\", title); + else + printf("\033]0;%s\a", title); + if (tcsetattr(STDIN_FILENO, TCSANOW, &origin_term) == -1) die("tcsetattr:"); } @@ -139,9 +147,8 @@ fork_filter(int *read, int *write) static void usage(void) { - fputs("lchat [-aeh] [-n lines] [-p prompt] [-t title] [-i in] [-o out]" - " [directory]\n", stderr); - exit(EXIT_FAILURE); + die("lchat [-aeh] [-n lines] [-p prompt] [-t title] [-i in] [-o out]" + " [directory]"); } int @@ -164,6 +171,9 @@ main(int argc, char *argv[]) char *prompt = read_file_line(".prompt"); char *title = read_file_line(".title"); + if (sl == NULL) + die("Failed to initialize slackline"); + if (prompt == NULL) /* set default prompt */ prompt = "> "; @@ -242,7 +252,7 @@ main(int argc, char *argv[]) if ((title = basename(path)) == NULL) die("basename:"); } - if (strcmp(getenv("TERM"), "screen") == 0) + if (strncmp(getenv("TERM"), "screen", 6) == 0) printf("\033k%s\033\\", title); else printf("\033]0;%s\a", title); @@ -278,7 +288,7 @@ main(int argc, char *argv[]) FILE *fh; /* open external source */ - snprintf(tail_cmd, sizeof tail_cmd, "exec tail -n %zd -f %s", + snprintf(tail_cmd, sizeof tail_cmd, "exec tail -n %zu -f %s", history_len, out_file); if ((fh = popen(tail_cmd, "r")) == NULL)