Move STDIN association to termio module

modified:   Makefile
	modified:   src/nmseffect.c
	modified:   src/nmstermio.c
	modified:   src/nmstermio_ncurses.c
This commit is contained in:
Brian Barto 2018-10-24 22:20:33 -04:00
parent a771cf32c1
commit 1440337579
4 changed files with 10 additions and 7 deletions

View File

@ -27,7 +27,7 @@ all: nms sneakers
all-ncurses: nms-ncurses sneakers-ncurses
nms-ncurses: $(OBJ)/nmscharset.o $(OBJ)/nmstermio_ncurses.o $(OBJ)/nmseffect.o $(OBJ)/nms.o | $(BIN)
nms-ncurses: $(OBJ)/input.o $(OBJ)/error.o $(OBJ)/nmscharset.o $(OBJ)/nmstermio_ncurses.o $(OBJ)/nmseffect.o $(OBJ)/nms.o | $(BIN)
$(CC) $(CFLAGS) -o $(BIN)/nms $^ -lncurses
sneakers-ncurses: $(OBJ)/nmscharset.o $(OBJ)/nmstermio_ncurses.o $(OBJ)/nmseffect.o $(OBJ)/sneakers.o | $(BIN)

View File

@ -63,12 +63,6 @@ char nmseffect_exec(unsigned char *string, int string_len) {
int maxRows, maxCols, curRow, curCol, origRow = 0, origCol = 0;
char ret = 0;
// Reassociate STDIN to the terminal if needed
if (!isatty(STDIN_FILENO) && !freopen ("/dev/tty", "r", stdin)) {
fprintf(stderr, "Error. Can't associate STDIN with terminal.\n");
return 0;
}
// Needed for UTF-8 support
setlocale(LC_ALL, "");

View File

@ -294,6 +294,10 @@ static void nmstermio_set_terminal(int s) {
struct termios tp;
static struct termios save;
static int state = 1;
if (!isatty(STDIN_FILENO)) {
stdin = freopen("/dev/tty", "r", stdin);
}
if (s == 0) {
if (tcgetattr(STDIN_FILENO, &tp) == -1) {

View File

@ -11,6 +11,8 @@
* functionality is defined and implemented here.
*/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <ncurses.h>
@ -25,6 +27,9 @@ static int foregroundColor = COLOR_BLUE; // Foreground color settin
* otherwise.
*/
void nmstermio_init_terminal(void) {
if (!isatty(STDIN_FILENO)) {
stdin = freopen("/dev/tty", "r", stdin);
}
initscr();
cbreak();
noecho();