aboutsummaryrefslogtreecommitdiffstats
ModeNameSize
d---------1145logstatsplain
-rw-r--r--README922logstatsplain
d---------about37logstatsplain
-rw-r--r--analytics.php579logstatsplain
-rw-r--r--channels.html1774logstatsplain
d---------contribute129logstatsplain
d---------cs250logstatsplain
d---------de207logstatsplain
d---------donate37logstatsplain
-rw-r--r--donators.inc.php6309logstatsplain
-rw-r--r--downloads.ini2356logstatsplain
-rw-r--r--downloads.php2340logstatsplain
d---------downloads37logstatsplain
-rw-r--r--downloads_locales.php72742logstatsplain
d---------el207logstatsplain
d---------en404logstatsplain
d---------es207logstatsplain
d---------et207logstatsplain
d---------fi137logstatsplain
d---------fr241logstatsplain
d---------g164logstatsplain
-rw-r--r--index.php584logstatsplain
d---------it207logstatsplain
-rw-r--r--langs.inc.php1943logstatsplain
-rw-r--r--langs.php4698logstatsplain
d---------lib190logstatsplain
-rw-r--r--localeDetection.class.php2931logstatsplain
d---------lv137logstatsplain
-rw-r--r--mirrors.php3805logstatsplain
d---------nb142logstatsplain
d---------nl207logstatsplain
-rw-r--r--paypal.inc.php1006logstatsplain
-rw-r--r--people.html5073logstatsplain
d---------pl170logstatsplain
d---------pr37logstatsplain
-rw-r--r--press.html2510logstatsplain
d---------press37logstatsplain
d---------pt207logstatsplain
-rw-r--r--release_counter.php1918logstatsplain
d---------ro207logstatsplain
-rw-r--r--roadmap.php306logstatsplain
d---------ru207logstatsplain
d---------sl105logstatsplain
d---------support37logstatsplain
d---------tr207logstatsplain
d---------uk112logstatsplain
d---------zh-cn139logstatsplain
d---------zh-tw207logstatsplain
='n531' href='#n531'>531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
#include <slang.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/signal.h>
#include <sys/time.h>
#include <sys/types.h>
#include <termios.h>
#include <unistd.h>

#include "newt.h"
#include "newt_pr.h"

struct Window {
    int height, width, top, left;
    short * buffer;
    char * title;
};

struct keymap {
    char * str;
    int code;
    char * tc;
};

static struct Window windowStack[20];
static struct Window * currentWindow = NULL;

static char * helplineStack[20];
static char ** currentHelpline = NULL;

static int cursorRow, cursorCol;
static int needResize;
static int cursorOn = 1;

static const char * defaultHelpLine =
"  <Tab>/<Alt-Tab> between elements   |  <Space> selects   |  <F12> next screen"
;

const struct newtColors newtDefaultColorPalette = {
	  "cyan", "black", 			/* root fg, bg */
	  "black", "blue",			/* border fg, bg */
	  "white", "blue",			/* window fg, bg */
	  "white", "black",			/* shadow fg, bg */
	  "white", "blue",			/* title fg, bg */
	  "black", "cyan",			/* button fg, bg */
	  "yellow", "cyan",			/* active button fg, bg */
	  "yellow", "blue",			/* checkbox fg, bg */
	  "blue", "brown",			/* active checkbox fg, bg */
	  "yellow", "blue",			/* entry box fg, bg */
	  "white", "blue",			/* label fg, bg */
	  "black", "cyan",			/* listbox fg, bg */
	  "yellow", "cyan",			/* active listbox fg, bg */
	  "white", "blue",			/* textbox fg, bg */
	  "cyan", "black",			/* active textbox fg, bg */
	  "white", "blue",			/* help line */
	  "yellow", "blue",			/* root text */
	  "blue",					/* scale full */
	  "red",					/* scale empty */
	  "blue", "cyan",				/* disabled entry fg, bg */
	  "white", "blue",			/* compact button fg, bg */
	  "yellow", "red",			/* active & sel listbox */
	  "black", "brown"			/* selected listbox */
};

static const struct keymap keymap[] = {
	{ "\033OA", 		NEWT_KEY_UP, 		"kh" },
	{ "\033[A", 		NEWT_KEY_UP, 		"ku" },
	{ "\033OB", 		NEWT_KEY_DOWN, 		"kd" },
	{ "\033[B", 		NEWT_KEY_DOWN, 		"kd" },
	{ "\033[C", 		NEWT_KEY_RIGHT, 	"kr" },
	{ "\033OC", 		NEWT_KEY_RIGHT, 	"kr" },
	{ "\033[D", 		NEWT_KEY_LEFT, 		"kl" },
	{ "\033OD", 		NEWT_KEY_LEFT, 		"kl" },
	{ "\033[H",		NEWT_KEY_HOME, 		"kh" },
	{ "\033[1~",		NEWT_KEY_HOME, 		"kh" },
	{ "\033Ow",		NEWT_KEY_END, 		"kH" },
	{ "\033[4~",		NEWT_KEY_END, 		"kH" },

	{ "\033[3~",		NEWT_KEY_DELETE,	"kl" },
	{ "\033[2~", 		NEWT_KEY_INSERT,	NULL },

	{ "\033\t",		NEWT_KEY_UNTAB,		NULL },

	{ "\033[5~",		NEWT_KEY_PGUP,		NULL },
	{ "\033[6~",		NEWT_KEY_PGDN,		NULL },
	{ "\033V",		NEWT_KEY_PGUP, 		"kH" },
	{ "\033v",		NEWT_KEY_PGUP, 		"kH" },

	{ "\033[[A",		NEWT_KEY_F1,		NULL },
	{ "\033[[B",		NEWT_KEY_F2,		NULL },
	{ "\033[[C",		NEWT_KEY_F3,		NULL },
	{ "\033[[D",		NEWT_KEY_F4,		NULL },
	{ "\033[[E",		NEWT_KEY_F5,		NULL },

	{ "\033OP",		NEWT_KEY_F1,		NULL },
	{ "\033OQ",		NEWT_KEY_F2,		NULL },
	{ "\033OR",		NEWT_KEY_F3,		NULL },
	{ "\033OS",		NEWT_KEY_F4,		NULL },

	{ "\033[11~",		NEWT_KEY_F1,		NULL },
	{ "\033[12~",		NEWT_KEY_F2,		NULL },
	{ "\033[13~",		NEWT_KEY_F3,		NULL },
	{ "\033[14~",		NEWT_KEY_F4,		NULL },
	{ "\033[15~",		NEWT_KEY_F5,		NULL },
	{ "\033[17~",		NEWT_KEY_F6,		NULL },
	{ "\033[18~",		NEWT_KEY_F7,		NULL },
	{ "\033[19~",		NEWT_KEY_F8,		NULL },
	{ "\033[20~",		NEWT_KEY_F9,		NULL },
	{ "\033[21~",		NEWT_KEY_F10,		NULL },
	{ "\033[23~",		NEWT_KEY_F11,		NULL },
	{ "\033[24~",		NEWT_KEY_F12,		NULL },

	{ NULL, 	0, 			NULL },	/* LEAVE this one */
};
static char keyPrefix = '\033';

static const char * version = "Newt windowing library version " VERSION
			" - (C) 1996-2000 Red Hat Software. "
		        "Redistributable under the term of the Library "
		        "GNU Public License. "
			"Written by Erik Troan\n";

static newtSuspendCallback suspendCallback = NULL;
static void * suspendCallbackData = NULL;

void newtSetSuspendCallback(newtSuspendCallback cb, void * data) {
    suspendCallback = cb;
    suspendCallbackData = data;
}

static void handleSigwinch(int signum __attribute__ ((unused))) {
    needResize = 1;
}

static int getkeyInterruptHook(void) {
    return -1;
}

void newtFlushInput(void) {
    while (SLang_input_pending(0)) {
	SLang_getkey();
    }
}

void newtRefresh(void) {
    SLsmg_refresh();
}

void newtSuspend(void) {
    SLtt_set_cursor_visibility (1);
    SLsmg_suspend_smg();
    SLang_reset_tty();
    SLtt_set_cursor_visibility (cursorOn);
}

void newtResume(void) {
    SLsmg_resume_smg ();
    SLsmg_refresh();
    SLang_init_tty(0, 0, 0);
}

void newtCls(void) {
    SLsmg_set_color(NEWT_COLORSET_ROOT);
    SLsmg_gotorc(0, 0);
    SLsmg_erase_eos();

    newtRefresh();
}

#if defined(THIS_DOESNT_WORK)
void newtResizeScreen(int redraw) {
    newtPushHelpLine("");

    SLtt_get_screen_size();
    SLang_init_tty(0, 0, 0);

    SLsmg_touch_lines (0, SLtt_Screen_Rows - 1);

    /* I don't know why I need this */
    SLsmg_refresh();

    newtPopHelpLine();

    if (redraw)
	SLsmg_refresh();
}
#endif

int newtInit(void) {
    char * MonoValue, * MonoEnv = "NEWT_MONO";

    /* use the version variable just to be sure it gets included */
    strlen(version);

    SLtt_get_terminfo();
    SLtt_get_screen_size();

    MonoValue = getenv(MonoEnv);
    if ( MonoValue == NULL ) {
	SLtt_Use_Ansi_Colors = 1;
    } else {
	SLtt_Use_Ansi_Colors = 0;
    }

    SLsmg_init_smg();
    SLang_init_tty(0, 0, 0);

    newtSetColors(newtDefaultColorPalette);
    newtCursorOff();
    /*initKeymap();*/

    /*memset(&sa, 0, sizeof(sa));
    sa.sa_handler = handleSigwinch;
    sigaction(SIGWINCH, &sa, NULL);*/

    SLsignal_intr(SIGWINCH, handleSigwinch);
    SLang_getkey_intr_hook = getkeyInterruptHook;



    return 0;
}

int newtFinished(void) {
    SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
    newtCursorOn();
    SLsmg_refresh();
    SLsmg_reset_smg();
    SLang_reset_tty();

    return 0;
}

void newtSetColors(struct newtColors colors) {
    SLtt_set_color(NEWT_COLORSET_ROOT, "", colors.rootFg, colors.rootBg);
    SLtt_set_color(NEWT_COLORSET_BORDER, "", colors.borderFg, colors.borderBg);
    SLtt_set_color(NEWT_COLORSET_WINDOW, "", colors.windowFg, colors.windowBg);
    SLtt_set_color(NEWT_COLORSET_SHADOW, "", colors.shadowFg, colors.shadowBg);
    SLtt_set_color(NEWT_COLORSET_TITLE, "", colors.titleFg, colors.titleBg);
    SLtt_set_color(NEWT_COLORSET_BUTTON, "", colors.buttonFg, colors.buttonBg);
    SLtt_set_color(NEWT_COLORSET_ACTBUTTON, "", colors.actButtonFg,
			colors.actButtonBg);
    SLtt_set_color(NEWT_COLORSET_CHECKBOX, "", colors.checkboxFg,
			colors.checkboxBg);
    SLtt_set_color(NEWT_COLORSET_ACTCHECKBOX, "", colors.actCheckboxFg,
			colors.actCheckboxBg);
    SLtt_set_color(NEWT_COLORSET_ENTRY, "", colors.entryFg, colors.entryBg);
    SLtt_set_color(NEWT_COLORSET_LABEL, "", colors.labelFg, colors.labelBg);
    SLtt_set_color(NEWT_COLORSET_LISTBOX, "", colors.listboxFg,
			colors.listboxBg);
    SLtt_set_color(NEWT_COLORSET_ACTLISTBOX, "", colors.actListboxFg,
			colors.actListboxBg);
    SLtt_set_color(NEWT_COLORSET_TEXTBOX, "", colors.textboxFg,
			colors.textboxBg);
    SLtt_set_color(NEWT_COLORSET_ACTTEXTBOX, "", colors.actTextboxFg,
			colors.actTextboxBg);
    SLtt_set_color(NEWT_COLORSET_HELPLINE, "", colors.helpLineFg,
			colors.helpLineBg);
    SLtt_set_color(NEWT_COLORSET_ROOTTEXT, "", colors.rootTextFg,
			colors.rootTextBg);

    SLtt_set_color(NEWT_COLORSET_EMPTYSCALE, "", "black",
			colors.emptyScale);
    SLtt_set_color(NEWT_COLORSET_FULLSCALE, "", "black",
			colors.fullScale);
    SLtt_set_color(NEWT_COLORSET_DISENTRY, "", colors.disabledEntryFg,
			colors.disabledEntryBg);

    SLtt_set_color(NEWT_COLORSET_COMPACTBUTTON, "", colors.compactButtonFg,
			colors.compactButtonBg);

    SLtt_set_color(NEWT_COLORSET_ACTSELLISTBOX, "", colors.actSelListboxFg,
		   colors.actSelListboxBg);
    SLtt_set_color(NEWT_COLORSET_SELLISTBOX, "", colors.selListboxFg,
		   colors.selListboxBg);
}

int newtGetKey(void) {
    int key;
    char buf[10], * chptr = buf;
    const struct keymap * curr;

    do {
	key = SLang_getkey();
	if (key == 0xFFFF) {
	    if (needResize)
		return NEWT_KEY_RESIZE;

	    /* ignore other signals */
	    continue;
	}

	if (key == NEWT_KEY_SUSPEND && suspendCallback)
	    suspendCallback(suspendCallbackData);
    } while (key == NEWT_KEY_SUSPEND);

    switch (key) {
      case 'v' | 0x80:
      case 'V' | 0x80:
	return NEWT_KEY_PGUP;

      case 22:
	return NEWT_KEY_PGDN;

	return NEWT_KEY_BKSPC;
      case 0x7f:
	return NEWT_KEY_BKSPC;

      case 0x08:
	return NEWT_KEY_BKSPC;

      default:
	if (key != keyPrefix) return key;
    }

    memset(buf, 0, sizeof(buf));

    *chptr++ = key;
    while (SLang_input_pending(5)) {
	key = SLang_getkey();
	if (key == keyPrefix) {
	    /* he hit unknown keys too many times -- start over */
	    memset(buf, 0, sizeof(buf));
	    chptr = buf;
	}

	*chptr++ = key;

	/* this search should use bsearch(), but when we only look through
	   a list of 20 (or so) keymappings, it's probably faster just to
	   do a inline linear search */

	for (curr = keymap; curr->code; curr++) {
	    if (curr->str) {
		if (!strcmp(curr->str, buf))
		    return curr->code;
	    }
	}
    }

    for (curr = keymap; curr->code; curr++) {
	if (curr->str) {
	    if (!strcmp(curr->str, buf))
		return curr->code;
	}
    }

    /* Looks like we were a bit overzealous in reading characters. Return
       just the first character, and put everything else back in the buffer
       for later */

    chptr--;
    while (chptr > buf)
	SLang_ungetkey(*chptr--);

    return *chptr;
}

void newtWaitForKey(void) {
    newtRefresh();

    SLang_getkey();
    newtClearKeyBuffer();
}

void newtClearKeyBuffer(void) {
    while (SLang_input_pending(1)) {
	SLang_getkey();
    }
}

int newtOpenWindow(int left, int top, int width, int height,
			  const char * title) {
    int j, row, col;
    int n;
    int i;

    newtFlushInput();

    if (!currentWindow) {
	currentWindow = windowStack;
    } else {
	currentWindow++;
    }

    currentWindow->left = left;
    currentWindow->top = top;
    currentWindow->width = width;
    currentWindow->height = height;
    currentWindow->title = title ? strdup(title) : NULL;

    currentWindow->buffer = malloc(sizeof(short) * (width + 3) * (height + 3));

    row = top - 1;