1 Star 7 Fork 1

炕头哥 / clock

Create your Gitee Account
Explore and code with more than 8 million developers,Free private repositories !:)
Sign up
Clone or Download
clock.c 1.09 KB
Copy Edit Web IDE Raw Blame History
炕头哥 authored 2013-12-19 01:03 . 第一次上传
#include <ncurses.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
#include <errno.h>
void error_quit(char *msg)
{
perror(msg);
exit(1);
}
void *normal_quit(void *win)
{
while(getchar()!='q')
continue;
delwin((WINDOW *)win);
endwin();
echo();
printf("Exit. . .\n");
printf("\nExit Clock Now. . .\n");
exit(0);
}
int main(void)
{
int x,y;
time_t t;
char buf[30];
pthread_t thread;
WINDOW *win;
initscr();
curs_set(0);
noecho();
if(has_colors())
{
start_color();
use_default_colors();
init_pair(1,COLOR_CYAN,-1);
}
getmaxyx(stdscr,y,x);
if((win=newwin(5,40,y/2-5/2,x/2-40/2))==NULL)
error_quit("Create New Window Error!");
refresh();
box(win,0,0);
wrefresh(win);
getmaxyx(win,y,x);
if(pthread_create(&thread,NULL,normal_quit,win)==-1)
error_quit("Create thread Error!");
wattron(win,COLOR_PAIR(1));
while(1)
{
t=time(NULL);
snprintf(buf,strlen(ctime(&t)),"%s",ctime(&t));
mvwprintw(win,y/2,x/2-(strlen(buf)+1)/2,buf/*ctime(&t)*/);
//mvwprintw(win,y/2,x-1,"%c",'|');
wrefresh(win);
sleep(1);
}
}

Comment ( 0 )

Sign in to post a comment

C
1
https://git.oschina.net/brisk/clock.git
git@git.oschina.net:brisk/clock.git
brisk
clock
clock
master

Search