/* This file is part of limb https://lila.oss/limb
* Copyright (C) 2023 Olivier Brunel jjk@jjacky.com */
/* SPDX-License-Identifier: GPL-2.0-only */
#include <errno.h>
#include <termios.h>
#include <limb/term.h>
int
term_echo(int fd, int want)
{
struct termios tio;
int r;
r = tcgetattr(fd, &tio);
if (r < 0) return -1;
if (want == !!(tio.c_lflag & ECHO))
return 0;
if (want)
tio.c_lflag |= ECHO;
else
tio.c_lflag &= ~ECHO;
if (tcsetattr(fd, TCSAFLUSH, &tio) < 0)
return -1;
return 1;
}