1 Star 7 Fork 2

炕头哥 / clock

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
clock.c 1.09 KB
一键复制 编辑 原始数据 按行查看 历史
炕头哥 提交于 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);
}
}
C
1
https://gitee.com/brisk/clock.git
git@gitee.com:brisk/clock.git
brisk
clock
clock
master

搜索帮助