Esempio n. 1
0
SCREEN *_terminfo_new_screen(const char *term_type, FILE *out, FILE *in)
{
	SCREEN *_newscr;
	ggLock(ncurses_lock);
        if ( term_type == NULL ) {
                term_type = getenv("TERM");
                if ( term_type == NULL ) {
                        term_type = "vt100";
                }
        }
	{ char *temp;
		temp = (char *)malloc(sizeof(char) * ( strlen(term_type) + 1 ));
		strcpy(temp, term_type);
		_newscr = newterm(temp, out, in);
		free(temp);
	}
	if ( _newscr == NULL ) {
		ggUnlock(ncurses_lock);
	} else {
		ncurses_screen = _newscr;
		set_term(_newscr);
		start_color();
		cbreak();
		noecho();
		nonl();
		timeout(0);
		meta(stdscr, TRUE);
		keypad(stdscr, TRUE);
	}
	return _newscr;
}
Esempio n. 2
0
static void ncurses_install_terminal(caca_display_t *dp)
{
    char *term, *colorterm;

    dp->drv.p->term = NULL;

    term = getenv("TERM");
    colorterm = getenv("COLORTERM");

    if(!term || strcmp(term, "xterm"))
        return;

    /* If we are using gnome-terminal, it's really a 16 colour terminal.
     * Ditto if we are using xfce4-terminal, or Konsole. */
    if((colorterm && (!strcmp(colorterm, "gnome-terminal")
                       || !strcmp(colorterm, "Terminal")))
         || getenv("KONSOLE_DCOP_SESSION"))
    {
        SCREEN *screen;
        screen = newterm("xterm-16color", stdout, stdin);
        if(screen == NULL)
            return;
        endwin();
        (void)putenv("TERM=xterm-16color");
        dp->drv.p->term = strdup(term);
        return;
    }
}
Esempio n. 3
0
int
main(int argc, char *argv[])
{
    int ch;
    char buffer[80];
    attr_t underline;
    bool i_option = FALSE;

    setlocale(LC_ALL, "");

    while ((ch = getopt(argc, argv, "i")) != -1) {
	switch (ch) {
	case 'i':
	    i_option = TRUE;
	    break;
	default:
	    usage();
	}
    }

    printf("starting filter program using %s...\n",
	   i_option ? "initscr" : "newterm");
    filter();
    if (i_option) {
	initscr();
    } else {
	(void) newterm((char *) 0, stdout, stdin);
    }
    cbreak();
    keypad(stdscr, TRUE);

    if (has_colors()) {
	int background = COLOR_BLACK;
	start_color();
#if HAVE_USE_DEFAULT_COLORS
	if (use_default_colors() != ERR)
	    background = -1;
#endif
	init_pair(1, COLOR_CYAN, (short) background);
	underline = (attr_t) COLOR_PAIR(1);
    } else {
	underline = A_UNDERLINE;
    }

    while (new_command(buffer, sizeof(buffer) - 1, underline) != ERR
	   && strlen(buffer) != 0) {
	reset_shell_mode();
	printf("\n");
	fflush(stdout);
	IGNORE_RC(system(buffer));
	reset_prog_mode();
	touchwin(stdscr);
	erase();
	refresh();
    }
    printw("done");
    refresh();
    endwin();
    ExitProgram(EXIT_SUCCESS);
}
Esempio n. 4
0
WINDOW * initscr(void) {
	if (NULL == newterm("", stdout, stdin)) {
		return NULL;
	}

	return stdscr;
}
Esempio n. 5
0
static bool ui_curses_init(UiTerm *tui, char *term) {
	if (!newterm(term, stderr, stdin)) {
		snprintf(tui->info, sizeof(tui->info), "Warning: unknown term `%s'", term);
		if (!newterm(strstr(term, "-256color") ? "xterm-256color" : "xterm", stderr, stdin))
			return false;
	}
	start_color();
	use_default_colors();
	cbreak();
	noecho();
	nonl();
	keypad(stdscr, TRUE);
	meta(stdscr, TRUE);
	curs_set(0);
	return true;
}
Esempio n. 6
0
void split_open(void)
{
  int i;
#if DEBUG
  printf("split_open()\n");
#endif
  LineCount = -1;
  for (i=0; i<MAX_LINE_COUNT; i++) {
    strcpy(Lines[i], "");
  }
#ifndef NO_CURSES
  FILE *stdout2 = fopen("/dev/tty", "w");
  if (!stdout2)
    fprintf(stderr, "split_open(): fopen() failed\n");
  else {
    SCREEN *screen;
    if ((screen = newterm(NULL, stdout2, stdin))) {
      set_term(screen);
      raw();
      noecho();
    } else
      fprintf(stderr, "split_open(): newterm() failed\n");
  }
#endif
}
Esempio n. 7
0
/*
 * initscr --
 *	Initialize the current and standard screen.
 */
WINDOW *
initscr(void)
{
	const char *sp;

	/*
	 * If My_term is set, or can't find a terminal in the environment,
	 * use Def_term.
	 */
	if (My_term || (sp = getenv("TERM")) == NULL)
		sp = Def_term;

	/* LINTED const castaway; newterm does not modify sp! */
	if ((_cursesi_screen = newterm((char *) sp, stdout, stdin)) == NULL)
		return NULL;

	__echoit = _cursesi_screen->echoit;
        __pfast = _cursesi_screen->pfast;
	__rawmode = _cursesi_screen->rawmode;
	__noqch = _cursesi_screen->noqch;
	COLS = _cursesi_screen->COLS;
	LINES = _cursesi_screen->LINES;
	COLORS = _cursesi_screen->COLORS;
	COLOR_PAIRS = _cursesi_screen->COLOR_PAIRS;
	__GT = _cursesi_screen->GT;
	__NONL = _cursesi_screen->NONL;
	__UPPERCASE = _cursesi_screen->UPPERCASE;

	set_term(_cursesi_screen);
	wrefresh(curscr);

	return (stdscr);
}
Esempio n. 8
0
/*
 * Allocates and initializes a new Screen.
 */
Screen *ScreenInit(Model *model)
{
	const char *tty = "/dev/tty";
	const char *term_type = 0;

	Screen *self = pg_malloc(sizeof(Screen));
	memset(self, 0, sizeof(Screen));

	self->model = model;
	memset(&self->key, 0, sizeof(Row));

	/*
	 * Open /dev/tty and set that up as the ncurses terminal. We use newterm
	 * instead of initscr so that we can read row events from stdin.
	 */

	term_type = getenv("TERM");

	if (term_type == NULL || *term_type == '\0') {
		term_type = "unknown";
	}

	self->term_in = fopen(tty, "r");

	if (self->term_in == NULL) {
		FATAL_ERROR("could not open %s", tty);
	}

	self->fd = fileno(self->term_in);
	self->nterm = newterm(term_type, stdout, self->term_in);
	set_term(self->nterm);

	/* make ncurses non blocking */
	timeout(0);

	/* clear the tty internal state */
	clear();

	/* disable character echo */
	noecho();

	/* disable input line buffering */
	cbreak();

	/* hide cursor */
	curs_set(0);

	/* enable extra keys */
	keypad(stdscr, TRUE);

	/* updates the screen (should be blank now) */
	refresh();

	self->x_pos = 0;
	self->x_col = 0;
	self->pause = 0;

	return self;
}
Esempio n. 9
0
void configure_screen () {
    	SCREEN *s = newterm(NULL, stdin, stdout);
    	if (s == 0)
    		exit(-1);
    	cbreak();
    	noecho();
    	keypad(stdscr, TRUE);
	setbuf(stdout, NULL);

}
Esempio n. 10
0
static void setup_ncurses() {
    SCREEN* main_screen = newterm(term_type, stdout, term_in);
    set_term(main_screen);
    scrollok(stdscr, TRUE);  // If enabled the window is scrolled up one line when reaching bottom
    idlok(stdscr, TRUE);     // Use the hardware insert/delete line feature of terminals so equipped
    ncurses_active = TRUE;
    //printf("\t\t\t\t\tncurses set up.\n");
    if (signal(SIGWINCH, catch_sigwinch) == SIG_ERR) {
        fputs("\t\t\t\t\tAn error occurred when setting up SIGWINCH signal handler.\n", stderr);
    }
}    // Done setting up ncurses
Esempio n. 11
0
/* Signal handler for SIGWINCH. */
static void gli_sig_winsize(int val)
{
    endwin();

    newterm(getenv("TERM"), stdout, stdin);
    gli_setup_curses();
    gli_set_halfdelay();

    screen_size_changed = TRUE;
    signal(SIGWINCH, &gli_sig_winsize);
}
Esempio n. 12
0
initscr(void)
{
    WINDOW *result;

    START_TRACE();
    T((T_CALLED("initscr()")));

    _nc_init_pthreads();
    _nc_lock_global(curses);

    /* Portable applications must not call initscr() more than once */
    if (!_nc_globals.init_screen) {
	NCURSES_CONST char *name;

	_nc_globals.init_screen = TRUE;

	if ((name = getenv("TERM")) == 0
	    || *name == '\0')
	    name = "unknown";
#ifdef __CYGWIN__
	/*
	 * 2002/9/21
	 * Work around a bug in Cygwin.  Full-screen subprocesses run from
	 * bash, in turn spawned from another full-screen process, will dump
	 * core when attempting to write to stdout.  Opening /dev/tty
	 * explicitly seems to fix the problem.
	 */
	if (NC_ISATTY(fileno(stdout))) {
	    FILE *fp = fopen("/dev/tty", "w");
	    if (fp != 0 && NC_ISATTY(fileno(fp))) {
		fclose(stdout);
		dup2(fileno(fp), STDOUT_FILENO);
		stdout = fdopen(STDOUT_FILENO, "w");
	    }
	}
#endif
	if (newterm(name, stdout, stdin) == 0) {
	    fprintf(stderr, "Error opening terminal: %s.\n", name);
	    exit(EXIT_FAILURE);
	}

	/* def_shell_mode - done in newterm/_nc_setupscreen */
#if NCURSES_SP_FUNCS
	NCURSES_SP_NAME(def_prog_mode) (CURRENT_SCREEN);
#else
	def_prog_mode();
#endif
    }
    result = stdscr;
    _nc_unlock_global(curses);

    returnWin(result);
}
Esempio n. 13
0
Nscreen::Nscreen(){
    //default constructor uses stdin and out
    this->numwindows = 1;
    scrptr = newterm("xterm",stdin,stdout);    
    set_term(scrptr);
    getmaxyx(stdscr,MAX_Y, MAX_X);

    start_color();
    init_pair(1,COLOR_WHITE,COLOR_BLUE);

    init_windows();
    cw=0;
}
Esempio n. 14
0
static PyObject* py_newterm(PyObject *self, PyObject *args){
  int fd;
  SCREEN *screen;
  if (!PyArg_ParseTuple(args, "i", &fd))
    return NULL;

  Py_BEGIN_ALLOW_THREADS
  FILE *fp = fdopen(fd, "w+");
  screen = newterm(NULL, fp, fp);
  Py_END_ALLOW_THREADS

  return PyLong_FromVoidPtr(screen);
}
Esempio n. 15
0
int curs_initciolib(long inmode)
{
	short	fg, bg, pair=0;

#ifdef XCURSES
	char	*argv[2]={"ciolib",NULL};

	Xinitscr(1,argv);
#else
	char *term;
	SCREEN *tst;

	term=getenv("TERM");
	if(term==NULL)
		return(0);
	tst=newterm(term,stdout,stdin);
	if(tst==NULL)
		return(0);
	endwin();
	initscr();
#endif
	start_color();
	cbreak();
	noecho();
	nonl();
	keypad(stdscr, TRUE);
	scrollok(stdscr,FALSE);
	halfdelay(1);
	raw();
	timeout(10);
	atexit(curs_suspend);

	/* Set up color pairs */
	for(bg=0;bg<8;bg++)  {
		for(fg=0;fg<8;fg++) {
			init_pair(++pair,curses_color(fg),curses_color(bg));
		}
	}
	mode = inmode;
#ifdef NCURSES_VERSION_MAJOR
		if(mousemask(BUTTON1_PRESSED|BUTTON1_RELEASED|BUTTON2_PRESSED|BUTTON2_RELEASED|BUTTON3_PRESSED|BUTTON3_RELEASED|REPORT_MOUSE_POSITION,NULL)==(BUTTON1_PRESSED|BUTTON1_RELEASED|BUTTON2_PRESSED|BUTTON2_RELEASED|BUTTON3_PRESSED|BUTTON3_RELEASED|REPORT_MOUSE_POSITION)) {
			mouseinterval(0);
			cio_api.mouse=1;
		}
		else
			mousemask(0,NULL);
#endif

	curs_textmode(0);
	return(1);
}
Esempio n. 16
0
int main(void)
{
	SCREEN *s;

	s = newterm(NULL, stdout, stdin);
	set_term(s);

	addstr("Hello!");

	refresh();
	getch();

	endwin();
	return 0;
}
Esempio n. 17
0
char		init_window(t_wrk *wrk)
{
  if ((wrk->screen = newterm(NULL, stderr, stdin)) == NULL)
    return (1);
  set_term(wrk->screen);
  wrk->selecta = 0;
  curs_set(0);
  keypad(stdscr, TRUE);
  wrk->arg->cursor = 1;
  wrk->cur = wrk->arg;
  wrk->x = 0;
  wrk->y = 0;
  wrk->pos = 0;
  return (0);
}
Esempio n. 18
0
initscr(void)
{
    static bool initialized = FALSE;
    NCURSES_CONST char *name;
    int value;

    START_TRACE();
    T((T_CALLED("initscr()")));
    /* Portable applications must not call initscr() more than once */
    if (!initialized) {
	initialized = TRUE;

	if ((name = getenv("TERM")) == 0
	    || *name == '\0')
	    name = "unknown";
#ifdef __CYGWIN__
	/*
	 * 2002/9/21
	 * Work around a bug in Cygwin.  Full-screen subprocesses run from
	 * bash, in turn spawned from another full-screen process, will dump
	 * core when attempting to write to stdout.  Opening /dev/tty
	 * explicitly seems to fix the problem.
	 */
	if (isatty(fileno(stdout))) {
	    FILE *fp = fopen("/dev/tty", "w");
	    if (fp != 0 && isatty(fileno(fp))) {
		fclose(stdout);
		dup2(fileno(fp), STDOUT_FILENO);
		stdout = fdopen(STDOUT_FILENO, "w");
	    }
	}
#endif
	if (newterm(name, stdout, stdin) == 0) {
	    fprintf(stderr, "Error opening terminal: %s.\n", name);
	    exit(EXIT_FAILURE);
	}

	/* allow user to set maximum escape delay from the environment */
	if ((value = _nc_getenv_num("ESCDELAY")) >= 0) {
	    ESCDELAY = value;
	}

	/* def_shell_mode - done in newterm/_nc_setupscreen */
	def_prog_mode();
    }
    returnWin(stdscr);
}
Esempio n. 19
0
File: xxx.c Progetto: yaomoon/GT2440
static void init(void)
{
    int x, y;

#ifdef yaomoon
moon_log = fopen("moon_log","w+");
#endif
    /* Initialize the curses library */
    if (isatty(STDIN_FILENO)) {
        cursed = !!initscr();
    } else {
    /* Leave stdin and stdout alone when acting as a pager. */
        FILE *io = fopen("/dev/tty", "r+");

        cursed = !!newterm(NULL, io, io);
    }

    if (!cursed)
        die("Failed to initialize curses");

	nonl();         /* tell curses not to do NL->CR/NL on output */
	cbreak();       /* take input chars one at a time, no wait for \n */
	noecho();       /* don't echo input */
    leaveok(stdscr, TRUE);

	if (has_colors())
    {
		init_colors();
    }

    getmaxyx(stdscr, y, x);
#ifdef yaomoon
fprintf(moon_log,"getmaxyx y=%d\n",y);
fprintf(moon_log,"getmaxyx x=%d\n",x);

#endif

    status_win = newwin(1, 0, y - 10, 0);
    if (!status_win)
        die("failed to create status window");

    keypad(status_win, TRUE);
    wbkgdset(status_win, get_line_attr(LINE_STATUS));

}
Esempio n. 20
0
bool nCurse::Activate() {
    if (running) refresh();
    else {
        s = newterm((char *) 0,stdout,stdin);
        if (s != NULL) {
            set_term(s);
            width = COLS;
            height = LINES;
            curs_set(0); //uncomment it to get rid of the cursor
            noecho();
            cbreak();// Line buffering disabled. pass on everything
            nodelay(stdscr,1);
            keypad(stdscr, TRUE);
            running = true;
        }
    }
    return running;
}
Esempio n. 21
0
// setup
void setup() {
  fdfile = fopen("/dev/lft0", "r+");
  fullScreen=newterm("linux", fdfile, fdfile);
  set_term(fullScreen);

  simWin = newwin(SIMWINHEIGHT, 400, ySimPos, xSimPos);
  scrollok(simWin, TRUE);
  waddstr(simWin, "** Hang on a sec... just waiting for the uvm boat anchor demo to compile\n");
  wmove(simWin, ++ySimPos, xSimPos);
  waddstr(simWin, "** and start running. You'll see something happen shortly...\n\n");
  wmove(simWin, ++ySimPos, xSimPos);
  wrefresh(simWin);

  guiWin = newwin(GUIWINHEIGHT, 400, SIMWINHEIGHT+1, xSimPos);
  boat_anchor.setWindow(guiWin);
  boat_anchor.startingScene();
  wrefresh(guiWin);
}
Esempio n. 22
0
bool setup_screen()
{
	//ncurses screen setup:
	//initscr();
	fd = fopen("/dev/tty", "r+");
	if (fd == NULL)
	{
		std::cerr << "Cannot open screen." << std::endl;
		return false;
	}
	scr = newterm(NULL, fd, fd);
	if (scr == NULL)
	{
		std::cerr << "Cannot open screen." << std::endl;
		close_screen();
		return false;
	}

	newfd = open("/dev/null", O_WRONLY);
	if (newfd == -1)
	{
		std::cerr << "Cannot open screen." << std::endl;
		close_screen();
		return false;
	}

	fflush(stdout);
	fflush(stderr);

	saved_stdout = dup(fileno(stdout));
	saved_stderr = dup(fileno(stderr));

	dup2(newfd, fileno(stdout));
	dup2(newfd, fileno(stderr));
	setvbuf(stdout, NULL, _IONBF, 0);

	clear();
	noecho();
	cbreak();
	keypad(stdscr, TRUE);
	timeout(10); //ms

	return true;
}
Esempio n. 23
0
int TermWidth()
{
  int cols = 0;
  SCREEN *screen;

  if( cols != 0) return cols;

  // original line follows:
  // initscr();

  screen = newterm((char *) NULL, stdout, stdin);
  if((void *)screen == NULL)
    cols = 80;
  else
    cols = COLS;

  endwin();

  return cols;
}
Esempio n. 24
0
/* Set up a curses window for our display
*/
void initcurses(void) {
    if (!using_curses)
        return;
    term = newterm(NULL, stdout, stdin);
    if (term != NULL) {
        int screen_width, screen_height;
        int window_width = linelen+2;
        int window_height = LINE_COUNT+2;
        int org_x, org_y;

        using_curses = 1;

        cbreak();
        noecho();
        nonl();

        nodelay(stdscr, TRUE);
        intrflush(stdscr, FALSE);
        keypad(stdscr, TRUE);
        leaveok(stdscr, TRUE);
        curs_set(0);

        getmaxyx(stdscr, screen_height, screen_width);
        org_x = (screen_width - window_width) / 2;
        org_y = (screen_height - window_height - 1) / 2;

        slimwin = subwin(stdscr, window_height, window_width, org_y, org_x);
        box(slimwin, 0, 0);

        if (screen_height > LINE_COUNT+2) {
            /* create one-line error message subwindow */
            errwin = subwin(stdscr, 1, screen_width, org_y+window_height, 0);
        }

        wrefresh(curscr);
    } else {
        using_curses = 0;
    }
}
Esempio n. 25
0
int main(void)
{
	FILE *termin,*termout;
	SCREEN *tp1,*tp2;
	char name[81];

/* Open terminal one for reading
   Open terminal two for writing */
	termin = fopen(INTERM,"r");
	termout = fopen(OUTTERM,"w");
	if( termin==NULL || termout==NULL )
	{
			puts("Unable to open terminal.");
			return(1);
	}

/* set up the new terminal in NCurses */
	tp2 = newterm(NULL,termout,termin);
	if( tp2 == NULL)
	{ 
		puts("Unable to open terminal window.");
		return(2);
	}

/* NCurses is now started for the new terminal */
	tp1 = set_term(tp2);
	printw("Welcome to Curses output on terminal %s.\n",OUTTERM);
	printw("You can type on terminal %s, and see it here.\n",INTERM);
	addstr("What is your name: ");
	refresh();
	getnstr(name,80);
	printw("%s, glad to have you aboard!",name);
	refresh();
	getch();

	endwin();
	return 0;
}
Esempio n. 26
0
static void get_newterm_aux(void)
{
  if((screenp=newterm(NULL,stdout,stdin))!=NULL)
    return ;
#if defined(TARGET_BSD)
  if((screenp=newterm("cons25",stdout,stdin))!=NULL)
    return ;
#elif defined(TARGET_LINUX)
  if((screenp=newterm("linux",stdout,stdin))!=NULL)
    return ;
#elif defined(__CYGWIN__)
  if((screenp=newterm("cygwin",stdout,stdin))!=NULL)
    return ;
#elif defined(__OS2__)
  if((screenp=newterm("ansi",stdout,stdin))!=NULL)
    return ;
#elif defined(__APPLE__)
  if((screenp=newterm("xterm-color",stdout,stdin))!=NULL)
    return ;
#endif
}
Esempio n. 27
0
static int
brl_construct (BrailleDisplay *brl, char **parameters, const char *device) {
  unsigned int ttyBaud = 9600;
  char *ttyType = "vt100";
  int windowLines = 1;
  int windowColumns = 40;

#ifdef HAVE_ICONV_H
  const char *characterSet = getLocaleCharset();
#endif /* HAVE_ICONV_H */

  if (!isSerialDevice(&device)) {
    unsupportedDevice(device);
    return 0;
  }

  {
    unsigned int baud = ttyBaud;
    if (serialValidateBaud(&baud, "TTY baud", parameters[PARM_BAUD], NULL))
      ttyBaud = baud;
  }

#ifdef USE_CURSES
  if (*parameters[PARM_TERM])
    ttyType = parameters[PARM_TERM];
#endif /* USE_CURSES */

  {
    static const int minimum = 1;
    static const int maximum = MAX_WINDOW_LINES;
    int lines = windowLines;
    if (validateInteger(&lines, parameters[PARM_LINES], &minimum, &maximum)) {
      windowLines = lines;
    } else {
      logMessage(LOG_WARNING, "%s: %s", "invalid line count", parameters[PARM_LINES]);
    }
  }

  {
    static const int minimum = 1;
    static const int maximum = MAX_WINDOW_COLUMNS;
    int columns = windowColumns;
    if (validateInteger(&columns, parameters[PARM_COLUMNS], &minimum, &maximum)) {
      windowColumns = columns;
    } else {
      logMessage(LOG_WARNING, "%s: %s", "invalid column count", parameters[PARM_COLUMNS]);
    }
  }

#ifdef HAVE_ICONV_H
  if (*parameters[PARM_CHARSET])
    characterSet = parameters[PARM_CHARSET];
#endif /* HAVE_ICONV_H */

  if (*parameters[PARM_LOCALE])
    classificationLocale = parameters[PARM_LOCALE];

#ifdef HAVE_ICONV_H
  if ((conversionDescriptor = iconv_open(characterSet, "WCHAR_T")) != (iconv_t)-1) {
#endif /* HAVE_ICONV_H */
    if ((ttyDevice = serialOpenDevice(device))) {
      if (serialRestartDevice(ttyDevice, ttyBaud)) {
#ifdef USE_CURSES
        if ((ttyStream = serialGetStream(ttyDevice))) {
          if ((ttyScreen = newterm(ttyType, ttyStream, ttyStream))) {
            cbreak();
            noecho();
            nonl();

            nodelay(stdscr, TRUE);
            intrflush(stdscr, FALSE);
            keypad(stdscr, TRUE);

            clear();
            refresh();
#endif /* USE_CURSES */

            brl->textColumns = windowColumns;
            brl->textRows = windowLines; 

            logMessage(LOG_INFO, "TTY: type=%s baud=%u size=%dx%d",
                       ttyType, ttyBaud, windowColumns, windowLines);
            return 1;
#ifdef USE_CURSES
          } else {
            logSystemError("newterm");
          }

          ttyStream = NULL;
        }
#endif /* USE_CURSES */
      }

      serialCloseDevice(ttyDevice);
      ttyDevice = NULL;
    }

#ifdef HAVE_ICONV_H
    iconv_close(conversionDescriptor);
  } else {
    logSystemError("iconv_open");
  }
  conversionDescriptor = NULL;
#endif /* HAVE_ICONV_H */

  return 0;
}
Esempio n. 28
0
/**
 * Ncurses Text User Interface
 * open_ncurses	    - open text window
 * close_ncurses    - close text window
 */
int open_ncurses() {
#ifdef HAVE_LIBNCURSESW
	int debug = 1;

	FILE *in = fopen( "/dev/stderr", "r" );
	FILE *out = fopen( "/dev/stderr", "w" );
	int terminal_x = 0;
	int terminal_y = 0;

	ptclscr = newterm(NULL, out, in);
	refresh();
	if (!ptclscr)
		log_mesg(0, 1, 1, debug, "partclone ncurses initial error\n");
	if (!set_term(ptclscr))
		log_mesg(0, 1, 1, debug, "partclone ncurses set term error\n");
	ptclscr_win = newwin(LINES, COLS, 0, 0);

	// check terminal width and height
	getmaxyx(ptclscr_win, terminal_y, terminal_x);

	// set window position
	int log_line = 12;
	int log_row = 60;
	int log_y_pos = (terminal_y-24)/2+2;
	int log_x_pos = (terminal_x-log_row)/2;
	int gap = 0;
	int p_line = 8;
	int p_row = log_row;
	int p_y_pos = log_y_pos+log_line+gap;
	int p_x_pos = log_x_pos;

	int size_ok = 1;

	if (terminal_y < (log_line+gap+p_line+3))
		size_ok = 0;
	if (terminal_x < (log_row+2))
		size_ok = 0;

	if (size_ok == 0) {
		log_mesg(0, 0, 0, debug, "Terminal width(%i) or height(%i) too small\n", terminal_x, terminal_y);
		return 0;
	}

	/// check color pair
	if (!has_colors()) {
		log_mesg(0, 0, 0, debug, "Terminal color error\n");
		return 0;
	}

	if (start_color() != OK){
		log_mesg(0, 0, 0, debug, "Terminal can't start color mode\n");
		return 0;
	}

	/// define color
	init_pair(1, COLOR_WHITE, COLOR_BLUE); ///stdscr
	init_pair(2, COLOR_RED, COLOR_WHITE); ///sub window
	init_pair(3, COLOR_BLUE, COLOR_WHITE); ///sub window

	/// write background color
	bkgd(COLOR_PAIR(1));
	wbkgd(ptclscr_win,COLOR_PAIR(2));
	touchwin(ptclscr_win);
	refresh();

	/// init main box
	attrset(COLOR_PAIR(2));
	box_win = subwin(ptclscr_win, (log_line+gap+p_line+2), log_row+2, log_y_pos-1, log_x_pos-1);
	box(box_win, ACS_VLINE, ACS_HLINE);
	wrefresh(box_win);
	wbkgd(box_win, COLOR_PAIR(2));
	mvprintw((log_y_pos-1), ((terminal_x-9)/2), " Partclone ");
	attroff(COLOR_PAIR(2));

	attrset(COLOR_PAIR(3));

	/// init log window
	log_win = subwin(ptclscr_win, log_line, log_row, log_y_pos, log_x_pos);
	wbkgd(log_win, COLOR_PAIR(3));
	touchwin(log_win);
	refresh();

	// init progress window
	p_win = subwin(ptclscr_win, p_line, p_row, p_y_pos, p_x_pos);
	wbkgd(p_win, COLOR_PAIR(3));
	touchwin(p_win);
	refresh();

	// init progress window
	bar_win = subwin(ptclscr_win, 1, p_row-10, p_y_pos+4, p_x_pos);
	wbkgd(bar_win, COLOR_PAIR(1));
	touchwin(bar_win);
	refresh();

	// init total block progress window
	tbar_win = subwin(ptclscr_win, 1, p_row-10, p_y_pos+7, p_x_pos);
	wbkgd(tbar_win, COLOR_PAIR(1));
	touchwin(tbar_win);
	refresh();

	scrollok(log_win, TRUE);

	if (touchwin(ptclscr_win) == ERR)
		return 0;

	refresh();

#endif
	return 1;
}
Esempio n. 29
0
File: display.c Progetto: JakeSc/tig
void
init_display(void)
{
    const char *term;
    int x, y;

    die_callback = done_display;
    /* XXX: Restore tty modes and let the OS cleanup the rest! */
    if (atexit(done_display))
        die("Failed to register done_display");

    /* Initialize the curses library */
    if (isatty(STDIN_FILENO)) {
        cursed = !!initscr();
        opt_tty = stdin;
    } else {
        /* Leave stdin and stdout alone when acting as a pager. */
        opt_tty = fopen("/dev/tty", "r+");
        if (!opt_tty)
            die("Failed to open /dev/tty");
        cursed = !!newterm(NULL, opt_tty, opt_tty);
    }

    if (!cursed)
        die("Failed to initialize curses");

    nonl();		/* Disable conversion and detect newlines from input. */
    cbreak();       /* Take input chars one at a time, no wait for \n */
    noecho();       /* Don't echo input */
    leaveok(stdscr, FALSE);

    if (has_colors())
        init_colors();

    getmaxyx(stdscr, y, x);
    status_win = newwin(1, x, y - 1, 0);
    if (!status_win)
        die("Failed to create status window");

    /* Enable keyboard mapping */
    keypad(status_win, TRUE);
    wbkgdset(status_win, get_line_attr(NULL, LINE_STATUS));
    enable_mouse(opt_mouse);

#if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20080119)
    set_tabsize(opt_tab_size);
#else
    TABSIZE = opt_tab_size;
#endif

    term = getenv("XTERM_VERSION") ? NULL : getenv("COLORTERM");
    if (term && !strcmp(term, "gnome-terminal")) {
        /* In the gnome-terminal-emulator, the message from
         * scrolling up one line when impossible followed by
         * scrolling down one line causes corruption of the
         * status line. This is fixed by calling wclear. */
        use_scroll_status_wclear = TRUE;
        use_scroll_redrawwin = FALSE;

    } else if (term && !strcmp(term, "xrvt-xpm")) {
        /* No problems with full optimizations in xrvt-(unicode)
         * and aterm. */
        use_scroll_status_wclear = use_scroll_redrawwin = FALSE;

    } else {
        /* When scrolling in (u)xterm the last line in the
         * scrolling direction will update slowly. */
        use_scroll_redrawwin = TRUE;
        use_scroll_status_wclear = FALSE;
    }
}
Esempio n. 30
0
void init(void){
     struct sigaction sig;
     ttyclock->bg = COLOR_BLACK;

     /* Init ncurses */
     if (ttyclock->tty) {
	     FILE *ftty = fopen(ttyclock->tty, "r+");
	     if (!ftty) {
		     fprintf(stderr, "tty-clock: error: '%s' couldn't be opened: %s.\n",
				     ttyclock->tty, strerror(errno));
		     exit(EXIT_FAILURE);
	     }
	     ttyclock->ttyscr = newterm(NULL, ftty, ftty);
	     assert(ttyclock->ttyscr != NULL);
	     set_term(ttyclock->ttyscr);
     } else
	     initscr();

     cbreak();
     noecho();
     keypad(stdscr, True);
     start_color();
     curs_set(False);
     clear();

     /* Init default terminal color */
     if(use_default_colors() == OK)
          ttyclock->bg = -1;

     /* Init color pair */
     init_pair(0, ttyclock->bg, ttyclock->bg);
     init_pair(1, ttyclock->bg, ttyclock->option.color);
     init_pair(2, ttyclock->option.color, ttyclock->bg);
     refresh();

     /* Init signal handler */
     sig.sa_handler = signal_handler;
     sig.sa_flags   = 0;
     sigaction(SIGWINCH, &sig, NULL);
     sigaction(SIGTERM,  &sig, NULL);
     sigaction(SIGINT,   &sig, NULL);
     sigaction(SIGSEGV,  &sig, NULL);

     /* Init global struct */
     ttyclock->running = True;
     if(!ttyclock->geo.x)
          ttyclock->geo.x = 0;
     if(!ttyclock->geo.y)
          ttyclock->geo.y = 0;
     if(!ttyclock->geo.a)
          ttyclock->geo.a = 1;
     if(!ttyclock->geo.b)
          ttyclock->geo.b = 1;
     ttyclock->geo.w = (ttyclock->option.second) ? SECFRAMEW : NORMFRAMEW;
     ttyclock->geo.h = 7;
     ttyclock->tm = localtime(&(ttyclock->lt));
     if(ttyclock->option.utc) {
         ttyclock->tm = gmtime(&(ttyclock->lt));
     }
     ttyclock->lt = time(NULL);
     update_hour();

     /* Create clock win */
     ttyclock->framewin = newwin(ttyclock->geo.h,
                                 ttyclock->geo.w,
                                 ttyclock->geo.x,
                                 ttyclock->geo.y);
     if(ttyclock->option.box) {
           box(ttyclock->framewin, 0, 0);
     }

     if (ttyclock->option.bold)
     {
          wattron(ttyclock->framewin, A_BLINK);
     }

     /* Create the date win */
     ttyclock->datewin = newwin(DATEWINH, strlen(ttyclock->date.datestr) + 2,
                                ttyclock->geo.x + ttyclock->geo.h - 1,
                                ttyclock->geo.y + (ttyclock->geo.w / 2) -
                                (strlen(ttyclock->date.datestr) / 2) - 1);
     if(ttyclock->option.box) {
          box(ttyclock->datewin, 0, 0);
     }
     clearok(ttyclock->datewin, True);

     set_center(ttyclock->option.center);

     nodelay(stdscr, True);

     if (ttyclock->option.date)
     {
          wrefresh(ttyclock->datewin);
     }

     wrefresh(ttyclock->framewin);

     /* Initialize the start timer */
     start_time = time(0);

     return;
}