#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
-#include <locale.h>
-#include <pty.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <termios.h>
#include <wchar.h>
-
+#ifdef __linux__
+# include <pty.h>
+#elif defined(__FreeBSD__)
+# include <libutil.h>
+#elif defined(__OpenBSD__)
+# include <util.h>
+#endif
#include "madtty.h"
+#ifndef NCURSES_ATTR_SHIFT
+# define NCURSES_ATTR_SHIFT 8
+#endif
+
#define IS_CONTROL(ch) !((ch) & 0xffffff60UL)
static int has_default = 0;
if (t->elen + 1 >= (int)sizeof(t->ebuf)) {
cancel:
+#ifndef NDEBUG
+ fprintf(stderr, "cancelled: \\033");
+ for (int i = 0; i < (int)t->elen; i++) {
+ if (isprint(t->ebuf[i])) {
+ fputc(t->ebuf[i], stderr);
+ } else {
+ fprintf(stderr, "\\%03o", t->ebuf[i]);
+ }
+ }
+ fputc('\n', stderr);
+#endif
cancel_escape_sequence(t);
}
}
0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3, 0x00b7, // 78-7e
};
-void madtty_putc(madtty_t *t, wchar_t wc)
+static void madtty_putc(madtty_t *t, wchar_t wc)
{
int width = 0;
}
}
-void madtty_initialize(void)
+void madtty_init_colors(void)
{
- setlocale(LC_ALL, "");
- initscr();
- start_color();
- noecho();
- raw();
- nodelay(stdscr, TRUE);
- keypad(stdscr, TRUE);
- curs_set(0);
- ESCDELAY=50;
-
- if (COLORS > 8) {
+ if (COLOR_PAIRS > 64) {
use_default_colors();
assume_default_colors(-1, -1);
has_default = 1;
}
}
}
+
+int madtty_color_pair(int fg, int bg)
+{
+ if (has_default) {
+ if (fg < -1)
+ fg = -1;
+ if (bg < -1)
+ bg = -1;
+ return COLOR_PAIR((fg + 1) * 16 + bg + 1);
+ }
+ if (fg < 0)
+ fg = COLOR_WHITE;
+ if (bg < 0)
+ bg = COLOR_BLACK;
+ return COLOR_PAIR((7 - fg) * 8 + bg);
+}