Compare commits

..

4 Commits

View File

@ -27,14 +27,17 @@
#include <poll.h> #include <poll.h>
#include <termios.h> #include <termios.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <glob.h>
#include <curses.h> #include <curses.h>
#include <term.h> #include <term.h>
#define CSI "\x1b[" #define CSI "\x1b["
#define OSC "\x1b]" #define OSC "\x1b]"
#define DCS "\x1bP"
#define ST "\x1b\\"
#define ST8 "\x9c"
#define BEL "\x07" #define BEL "\x07"
#define ST "\x9c"
extern char **environ; extern char **environ;
static struct termios saved_termios; static struct termios saved_termios;
@ -202,7 +205,7 @@ int main(int argc, char *argv[]) {
// - see acolors.sh from xterm's vttests, it changes terminal colours // - see acolors.sh from xterm's vttests, it changes terminal colours
// (and urxvt passed that, at least apparently) // (and urxvt passed that, at least apparently)
printf("-- Blink attribute\n"); printf("-- Bold and blink attributes\n");
bool bbc_supported = enter_bold_mode && enter_blink_mode bool bbc_supported = enter_bold_mode && enter_blink_mode
&& set_a_foreground && set_a_background && exit_attribute_mode; && set_a_foreground && set_a_background && exit_attribute_mode;
printf("Terminfo: %d\n", bbc_supported); printf("Terminfo: %d\n", bbc_supported);
@ -255,30 +258,34 @@ int main(int argc, char *argv[]) {
const char *windowid = getenv("WINDOWID"); const char *windowid = getenv("WINDOWID");
if (windowid) { if (windowid) {
printf("WINDOWID=%s\n", windowid); printf("WINDOWID=%s\n", windowid);
printf("There should be a picture. Press a key.\n");
poll(NULL, 0, 50 /* wait for a refresh */);
char buf[1000] = ""; char buf[1000] = "";
snprintf(buf, sizeof buf, "/usr/lib/w3m:%s", getenv("PATH")); snprintf(buf, sizeof buf, "/usr/lib/w3m:%s", getenv("PATH"));
setenv("PATH", buf, true /* replace */); setenv("PATH", buf, true /* replace */);
// TODO: glob_t gb;
// - run w3mimgdisplay now, hardcoded visual check glob("/usr/share/pixmaps/*.xpm", 0, NULL, &gb);
// - I guess I'll need a picture to show glob("/usr/share/pixmaps/*.png", GLOB_APPEND, NULL, &gb);
// - /usr/share/pixmaps/debian-logo.png
// - /usr/share/icons/HighContrast/48x48/stock/gtk-yes.png FILE *fp = popen("w3mimgdisplay >/dev/null", "w");
// - we get run from a relative path, so not sure about local fprintf(fp, "0;1;0;0;%d;%d;;;;;%s\n4;\n3;", 100, 100, gb.gl_pathv[0]);
// - or we can create our own picture, something easily compressible pclose(fp);
// - can even pass that as an fd during fork and use /dev/fd/N globfree(&gb);
comm("", true);
} }
printf("-- Sixel graphics\n"); printf("-- Sixel graphics\n");
// TODO: comm(CSI "4c" DCS "0;0;0;q??~~??~~??iTiTiT" ST, false);
// - hardcoded visual check
printf("-- Mouse protocol\n"); printf("-- Mouse protocol\n");
printf("Maximise the terminal window and click the rightmost column.\n"); while (!ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) && ws.ws_col < 223)
// TODO: Bug the user into resizing it wide enough, or at least making comm("Your terminal needs to be at least 223 columns wide.\n"
// the font smaller. Or maybe just warn, and say how many columns there "Press a key once you've made it wide enough.\n", true);
// need to be (255 - 32 + 1 = 224). printf("Click the rightmost column, if it's possible.\n");
int mouses[] = { 1005, 1006, 1015, 1016 }; int mouses[] = { 1005, 1006, 1015, 1016 };
for (size_t i = 0; i < sizeof mouses / sizeof *mouses; i++) { for (size_t i = 0; i < sizeof mouses / sizeof *mouses; i++) {
if (decrqm_supported) if (decrqm_supported)
@ -296,10 +303,10 @@ int main(int argc, char *argv[]) {
if (!strncmp(selection, OSC "52;", 5)) { if (!strncmp(selection, OSC "52;", 5)) {
printf("We have received the selection from the terminal!" CSI "1m\n"); printf("We have received the selection from the terminal!" CSI "1m\n");
char *semi = strrchr(selection, ';'); char *semi = strrchr(selection, ';');
*strpbrk(semi, BEL ST) = 0; *strpbrk(semi, BEL ST8) = 0;
FILE *fp = popen("base64 -d", "w"); FILE *fp = popen("base64 -d", "w");
fprintf(fp, "%s", semi + 1); fprintf(fp, "%s", semi + 1);
fclose(fp); pclose(fp);
printf(CSI "m\n"); printf(CSI "m\n");
} }