~aritra1911/ansi_anim

68c3b39d9c7736a0e0481ebd4194b32cce442ac0 — Aritra Sarkar 2 years ago e3d9e4a
Begin setting up raw mode
3 files changed, 60 insertions(+), 0 deletions(-)

A .gitignore
A Makefile
A main.c
A .gitignore => .gitignore +2 -0
@@ 0,0 1,2 @@
*.o
anim

A Makefile => Makefile +17 -0
@@ 0,0 1,17 @@
CFLAGS = -Wall -Wextra -pedantic -std=c99

SRCS = main.c
OBJS = $(SRCS:.c=.o)

.PHONY: all clean

all: anim

anim: $(OBJS)
	$(CC) $(LDFLAGS) -o $@ $^

%.o: %.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<

clean:
	rm -f $(OBJS) anim

A main.c => main.c +41 -0
@@ 0,0 1,41 @@
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>

struct termios orig_termios;    /* Keeps the original attributes */

static inline void enable_raw_mode(void);
static inline void disable_raw_mode(void);

static inline void enable_raw_mode(void)
{
    struct termios raw;

    atexit(disable_raw_mode);   /* defer call to disable_raw_mode() */

    /* Fetch the current attributes and save it */
    tcgetattr(STDIN_FILENO, &orig_termios);
    raw = orig_termios;

    raw.c_lflag &= ~(ECHO); /* turn off echoing */

    tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
}

static inline void disable_raw_mode(void)
{
    tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios);
}

int main(void)
{
    char c;

    enable_raw_mode();

    /* keep reading until EOF or 'q' */
    while ( read(STDIN_FILENO, &c, 1) && c != 'q' );

    return EXIT_SUCCESS;
}