version 1.21, 2017/03/15 04:24:14 |
version 1.22, 2019/10/08 07:26:59 |
|
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <term.h> |
#include <term.h> |
#include <unistd.h> |
#include <unistd.h> |
|
#include <stdbool.h> |
|
|
#include "top.h" |
#include "top.h" |
#include "screen.h" |
#include "screen.h" |
#include "layout.h" |
#include "layout.h" |
#include "boolean.h" |
|
|
|
int screen_length, screen_width; |
int screen_length, screen_width; |
char ch_erase, ch_kill, smart_terminal; |
char ch_erase, ch_kill, smart_terminal; |
|
|
static struct termios old_settings, new_settings; |
static struct termios old_settings, new_settings; |
static char is_a_terminal = No; |
static char is_a_terminal = false; |
|
|
void |
void |
init_termcap(int interactive) |
init_termcap(int interactive) |
|
|
|
|
if (!interactive) { |
if (!interactive) { |
/* pretend we have a dumb terminal */ |
/* pretend we have a dumb terminal */ |
smart_terminal = No; |
smart_terminal = false; |
return; |
return; |
} |
} |
/* assume we have a smart terminal until proven otherwise */ |
/* assume we have a smart terminal until proven otherwise */ |
smart_terminal = Yes; |
smart_terminal = true; |
|
|
/* get the terminal name */ |
/* get the terminal name */ |
term_name = getenv("TERM"); |
term_name = getenv("TERM"); |
|
|
/* if there is no TERM, assume it's a dumb terminal */ |
/* if there is no TERM, assume it's a dumb terminal */ |
/* patch courtesy of Sam Horrocks at telegraph.ics.uci.edu */ |
/* patch courtesy of Sam Horrocks at telegraph.ics.uci.edu */ |
if (term_name == NULL) { |
if (term_name == NULL) { |
smart_terminal = No; |
smart_terminal = false; |
return; |
return; |
} |
} |
|
|
|
|
warnx("no termcap entry for a `%s' terminal", term_name); |
warnx("no termcap entry for a `%s' terminal", term_name); |
|
|
/* pretend it's dumb and proceed */ |
/* pretend it's dumb and proceed */ |
smart_terminal = No; |
smart_terminal = false; |
return; |
return; |
} |
} |
|
|
/* "hardcopy" immediately indicates a very stupid terminal */ |
/* "hardcopy" immediately indicates a very stupid terminal */ |
if (tgetflag("hc")) { |
if (tgetflag("hc")) { |
smart_terminal = No; |
smart_terminal = false; |
return; |
return; |
} |
} |
|
|
|
|
|
|
/* get necessary capabilities */ |
/* get necessary capabilities */ |
if (tgetstr("cl", NULL) == NULL || tgetstr("cm", NULL) == NULL) { |
if (tgetstr("cl", NULL) == NULL || tgetstr("cm", NULL) == NULL) { |
smart_terminal = No; |
smart_terminal = false; |
return; |
return; |
} |
} |
|
|
|
|
|
|
/* if stdout is not a terminal, pretend we are a dumb terminal */ |
/* if stdout is not a terminal, pretend we are a dumb terminal */ |
if (tcgetattr(STDOUT_FILENO, &old_settings) == -1) |
if (tcgetattr(STDOUT_FILENO, &old_settings) == -1) |
smart_terminal = No; |
smart_terminal = false; |
} |
} |
|
|
void |
void |
|
|
ch_erase = old_settings.c_cc[VERASE]; |
ch_erase = old_settings.c_cc[VERASE]; |
ch_kill = old_settings.c_cc[VKILL]; |
ch_kill = old_settings.c_cc[VKILL]; |
|
|
is_a_terminal = Yes; |
is_a_terminal = true; |
#if 0 |
#if 0 |
/* send the termcap initialization string */ |
/* send the termcap initialization string */ |
putcap(terminal_init); |
putcap(terminal_init); |
|
|
} |
} |
if (!is_a_terminal) { |
if (!is_a_terminal) { |
/* not a terminal at all---consider it dumb */ |
/* not a terminal at all---consider it dumb */ |
smart_terminal = No; |
smart_terminal = false; |
} |
} |
|
|
if (smart_terminal) |
if (smart_terminal) |