1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
#include "tweak.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#if defined(unix) && !defined(GO32)
#include <signal.h>
#include <sys/ioctl.h>
#endif
#include <slang.h>
#if defined(unix) && !defined(GO32)
static int sigwinch (int sigtype)
{
extern void schedule_update(void);
schedule_update();
signal (SIGWINCH, (void *) sigwinch);
return 0;
}
#endif
int display_rows, display_cols;
void display_beep(void)
{
SLtt_beep();
}
static void get_screen_size (void) {
int r = 0, c = 0;
#ifdef TIOCGWINSZ
struct winsize wind_struct;
if ((ioctl(1,TIOCGWINSZ,&wind_struct) == 0)
|| (ioctl(0, TIOCGWINSZ, &wind_struct) == 0)
|| (ioctl(2, TIOCGWINSZ, &wind_struct) == 0)) {
c = (int) wind_struct.ws_col;
r = (int) wind_struct.ws_row;
}
#elif defined(MSDOS)
union REGS regs;
regs.h.ah = 0x0F;
int86 (0x10, ®s, ®s);
c = regs.h.ah;
regs.x.ax = 0x1130, regs.h.bh = 0;
int86 (0x10, ®s, ®s);
r = regs.h.dl + 1;
#endif
if ((r <= 0) || (r > 200)) r = 24;
if ((c <= 0) || (c > 250)) c = 80;
display_rows = SLtt_Screen_Rows = r;
display_cols = SLtt_Screen_Cols = c;
}
void display_setup(void)
{
SLtt_get_terminfo();
if (SLang_init_tty (ABORT, 1, 0) == -1) {
fprintf(stderr, "tweak: SLang_init_tty: returned error code\n");
exit (1);
}
SLang_set_abort_signal (NULL);
SLtt_Use_Ansi_Colors = TRUE;
get_screen_size ();
if (SLsmg_init_smg () < 0) {
fprintf(stderr, "tweak: SLsmg_init_smg: returned error code\n");
SLang_reset_tty ();
exit (1);
}
#if defined(unix) && !defined(GO32)
signal (SIGWINCH, (void *) sigwinch);
#endif
}
void display_cleanup(void)
{
SLsmg_reset_smg ();
SLang_reset_tty ();
}
void display_moveto(int y, int x)
{
SLsmg_gotorc(y, x);
}
void display_refresh(void)
{
SLsmg_refresh();
}
void display_write_str(char *str)
{
SLsmg_write_nchars(str, strlen(str));
}
void display_write_chars(char *str, int len)
{
SLsmg_write_nchars(str, len);
}
void display_define_colour(int colour, int fg, int bg, int reverse)
{
static char *colours[16] = {
"black", "red", "green", "brown",
"blue", "magenta", "cyan", "lightgray",
"gray", "brightred", "brightgreen", "yellow",
"brightblue", "brightmagenta", "brightcyan", "white",
};
char cname[40];
if (fg < 0 && bg < 0) {
/* FIXME: not sure how to support terminal default fg+bg */
fg = 7;
bg = 0;
}
snprintf(cname, sizeof(cname), "colour%d", colour);
SLtt_set_color(colour, cname, colours[fg], colours[bg]);
}
void display_set_colour(int colour)
{
SLsmg_set_color(colour);
}
void display_clear_to_eol(void)
{
SLsmg_erase_eol();
}
int display_getkey(void)
{
return SLang_getkey();
}
int display_input_to_flush(void)
{
return SLang_input_pending(0);
}
void display_post_error(void)
{
SLKeyBoard_Quit = 0;
SLang_Error = 0;
}
void display_recheck_size(void)
{
SLsmg_reset_smg ();
get_screen_size ();
SLsmg_init_smg ();
}
|