index — thing @ 2c3a0ee83d01236273cc62964cd8f1b3788050a5

A little something I'm working on

term.c (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
#include <stdio.h>
#include <termios.h>
#include <unistd.h>

void setup_term(struct termios *old) {
  struct termios new;

  tcgetattr(STDIN_FILENO, old);

  new = *old;

  new.c_lflag &= ~(ECHO | ICANON);
  new.c_cc[VMIN] = 0;  // bytes read to return
  new.c_cc[VTIME] = 0; // time before return

  printf("\x1B[?1049h"); // enter alt buffer
  tcsetattr(STDIN_FILENO, TCSANOW, &new);
}

void return_term(struct termios *old) {
  tcsetattr(STDIN_FILENO, TCSANOW, old);
  printf("\x1B[?1049l"); // exit alt buffer
}