All pastes #151670 Raw Edit

coldfyre

public text v1 · immutable
#151670 ·published 2006-08-28 07:55 UTC
rendered paste body
#include <ncurses.h>
#include <time.h>
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string);
WINDOW *create_newwin(int height, int width, int starty, int startx);


int main(int argc, char *argv[])
{	initscr();			
	int row,col;	
	char linefiller[255] = " ";
	char time[255];
	//char nul;
	//nul = "";
	getmaxyx(stdscr, row, col);


	
	if(has_colors() == FALSE)
	{	endwin();
		printf("Your terminal does not support color\n");
		exit(1);
	}
	start_color();			
	init_pair(1, COLOR_YELLOW, COLOR_BLUE);
	init_pair(2, COLOR_BLACK, COLOR_WHITE);

	WINDOW *my_win;
	int startx, starty, width, height;
	int ch;
 

	initscr();		
	cbreak();			
					 
	keypad(stdscr, TRUE);		

	height = 25;
	width = COLS -1;
	memset(linefiller, ' ', width);
	starty = (LINES - height) / 2;	
	startx = (COLS - width) / 2;	
	attron(COLOR_PAIR(1) | A_BOLD);
	mvprintw(1,startx,linefiller);
	mvprintw(2,startx,linefiller);
	mvprintw(1,1,"AutoIF 1.0 by ColdFyre");
	mvprintw(2,1,"http://cfyre.myip.org");
	refresh();
	attron(COLOR_PAIR(2));
	my_win = create_newwin(height - 1,width, 3, 1);
	mvprintw(LINES -2,startx,linefiller);
	//while (getc(stdin) == "") {
	mvprintw(LINES -2,startx,"SysTime: ");
	//printf(time);
	//}
	
	//printf(strftime);	

	attroff(COLOR_PAIR(2));
	endwin();	
	
	print_in_middle(stdscr, LINES - 1, 1, 1, "");
	attroff(COLOR_PAIR(1));
    	
;


getchar();
	endwin();
}
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string)
{	int length, x, y;
	float temp;

	if(win == NULL)
		win = stdscr;
	getyx(win, y, x);
	if(startx != 0)
		x = startx;
	if(starty != 0)
		y = starty;
	if(width == 0)
		width = 80;

	length = strlen(string);
	temp = (width - length)/ 2;
	x = startx + (int)temp;
	mvwprintw(win, y, x, "%s", string);
	refresh();
}

WINDOW *create_newwin(int height, int width, int starty, int startx)
{	WINDOW *local_win;

	local_win = newwin(height, width, starty, startx);
	box(local_win, 0 , 0);		
					
					 
	wrefresh(local_win);		

	return local_win;
}