LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1052|回复: 8

一个控制台显示时间的小玩意儿...

[复制链接]
发表于 2008-1-11 11:48:58 | 显示全部楼层 |阅读模式
可以在控制台下动态的显示时间 ... 定位于右上角 , 使用很简单 保存代码
  1. gcc -o showtime showtime.c
复制代码


代码如下 :

  1. /* file: showtime.c */
  2. #include <stdio.h>
  3. #include <time.h>

  4. #define ESC '\033'
  5. #define MOVETO "\033[%d;%d;H"
  6. #define SAVE "\0337"
  7. #define RESTORE "%c8",ESC
  8. #define ROW 1
  9. #define COL 50

  10. main()
  11. {
  12.   time_t i;
  13.   char * atime;

  14.   while (1) {
  15.     time(&i);
  16.     atime = asctime(localtime(&i));
  17.     atime[strlen(atime)-1] = '\0';
  18.     printf(SAVE);
  19.     printf(MOVETO,ROW,COL);
  20.     printf(" +--------------------------+ ");
  21.     printf(MOVETO,ROW+1,COL);
  22.     printf(" + %s +",atime);
  23.     printf(MOVETO,ROW+2,COL);
  24.     printf(" +--------------------------+ ");
  25.     printf(MOVETO,ROW+3,COL);
  26.     printf("                              ");
  27.     printf(RESTORE);
  28.     fflush(stdout); /**/
  29.     sleep(1);
  30.   }
  31. }
复制代码


附件是效果图

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
发表于 2008-1-11 12:09:23 | 显示全部楼层
very good,very strong
回复 支持 反对

使用道具 举报

发表于 2008-1-11 12:22:20 | 显示全部楼层
Funny.
回复 支持 反对

使用道具 举报

发表于 2008-1-11 12:39:01 | 显示全部楼层
似乎挺有趣的 :)
回复 支持 反对

使用道具 举报

发表于 2008-1-13 01:20:41 | 显示全部楼层
用 screen 就可以了:)。不过支持原创。嘿嘿。
回复 支持 反对

使用道具 举报

发表于 2008-1-13 08:27:59 | 显示全部楼层
用 screen 怎样玩,请赐教。
回复 支持 反对

使用道具 举报

发表于 2008-1-13 12:00:35 | 显示全部楼层
.screenrc 加入:
hardstatus string '%{= wK}%-Lw%{= KW}%50>%n%f* %t%{= wK}%+Lw%< %{= KW}%-=%D %d %M '
hardstatus alwayslastline

启动screen后,C-a t  就可以看到时间了。
回复 支持 反对

使用道具 举报

发表于 2008-1-13 13:28:15 | 显示全部楼层
謝謝,又學了一招 :thank
回复 支持 反对

使用道具 举报

发表于 2008-1-14 00:45:15 | 显示全部楼层
screen  很方便,我现在天天都用,比那个 konsole 的tab 好用多了。嘿嘿。:)
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表