浏览代码

Drop tabs and trailing spaces.

tags/v0.99.beta18
Alex Foulon alxf 13 年前
父节点
当前提交
d70c958c8c
共有 2 个文件被更改,包括 133 次插入133 次删除
  1. +1
    -1
      python/caca/canvas.py
  2. +132
    -132
      src/cacaclock.c

+ 1
- 1
python/caca/canvas.py 查看文件

@@ -1545,7 +1545,7 @@ class Canvas(_Canvas):
return ctypes.string_at(ret, p.value) return ctypes.string_at(ret, p.value)


def set_figfont(self, filename): def set_figfont(self, filename):
""" Load a figfont and attach it to a canvas. """ Load a figfont and attach it to a canvas.


filename -- the figfont file to load. filename -- the figfont file to load.
""" """


+ 132
- 132
src/cacaclock.c 查看文件

@@ -25,157 +25,157 @@


static void usage(int argc, char **argv) static void usage(int argc, char **argv)
{ {
fprintf(stderr, "Usage: %s [OPTIONS]...\n", argv[0]); fprintf(stderr, "Usage: %s [OPTIONS]...\n", argv[0]);
fprintf(stderr, "Display current time in text mode (q to quit)\n"); fprintf(stderr, "Display current time in text mode (q to quit)\n");
fprintf(stderr, "Example : %s -d '%%R'\n\n", argv[0]); fprintf(stderr, "Example : %s -d '%%R'\n\n", argv[0]);
fprintf(stderr, "Options:\n"); fprintf(stderr, "Options:\n");
fprintf(stderr, " -h, --help\t\t\tThis help\n"); fprintf(stderr, " -h, --help\t\t\tThis help\n");
fprintf(stderr, " -v, --version\t\t\tVersion of the program\n"); fprintf(stderr, " -v, --version\t\t\tVersion of the program\n");
fprintf(stderr, " -f, --font=FONT\t\tUse FONT for time display\n"); fprintf(stderr, " -f, --font=FONT\t\tUse FONT for time display\n");
fprintf(stderr, " -d, --dateformat=FORMAT\tUse FORMAT as strftime argument (default %%R:%%S)\n"); fprintf(stderr, " -d, --dateformat=FORMAT\tUse FORMAT as strftime argument (default %%R:%%S)\n");
} }




static void version(void) static void version(void)
{ {
printf( printf(
"cacaclock Copyright 2011 Jean-Yves Lamoureux\n" "cacaclock Copyright 2011 Jean-Yves Lamoureux\n"
"Internet: <jylam@lnxscene.org> Version: %s (libcaca %s), date: %s\n" "Internet: <jylam@lnxscene.org> Version: %s (libcaca %s), date: %s\n"
"\n" "\n"
"cacaclock, along with its documentation, may be freely copied and distributed.\n" "cacaclock, along with its documentation, may be freely copied and distributed.\n"
"\n" "\n"
"The latest version of cacaclock is available from the web site,\n" "The latest version of cacaclock is available from the web site,\n"
" http://caca.zoy.org/wiki/libcaca in the libcaca package.\n" " http://caca.zoy.org/wiki/libcaca in the libcaca package.\n"
"\n", "\n",
CACACLOCKVERSION, caca_get_version(), __DATE__); CACACLOCKVERSION, caca_get_version(), __DATE__);
} }




static char* get_date(char *format) { static char* get_date(char *format) {
time_t currtime; time_t currtime;
char *charTime = malloc(101); char *charTime = malloc(101);


time(&currtime); time(&currtime);
strftime(charTime, 100,format,localtime(&currtime)); strftime(charTime, 100,format,localtime(&currtime));


return charTime; return charTime;
} }


int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {


caca_canvas_t *cv; caca_canvas_t *cv;
caca_canvas_t *figcv; caca_canvas_t *figcv;
caca_display_t *dp; caca_display_t *dp;
uint32_t w, h, fw, fh; uint32_t w, h, fw, fh;
char *format = "%R:%S";
char *format = "%R:%S"; char *font = "/usr/share/figlet/mono12.tlf";
char *font = "/usr/share/figlet/mono12.tlf"; for(;;)
{
int option_index = 0;
for(;;) static struct caca_option long_options[] =
{ {
int option_index = 0; { "font", 1, NULL, 'f' },
static struct caca_option long_options[] = { "dateformat", 1, NULL, 'd' },
{ { "help", 0, NULL, 'h' },
{ "font", 1, NULL, 'f' }, { "version", 0, NULL, 'v' },
{ "dateformat", 1, NULL, 'd' }, };
{ "help", 0, NULL, 'h' }, int c = caca_getopt(argc, argv, "f:d:hv",
{ "version", 0, NULL, 'v' }, long_options, &option_index);
}; if(c == -1)
int c = caca_getopt(argc, argv, "f:d:hv", break;
long_options, &option_index); switch(c)
if(c == -1) {
break; case 'h': /* --help */
usage(argc, argv);
switch(c) return 0;
{ break;
case 'h': /* --help */ case 'v': /* --version */
usage(argc, argv); version();
return 0; return 0;
break; break;
case 'v': /* --version */ case 'f': /* --font */
version(); font = caca_optarg;
return 0; break;
break; case 'd': /* --dateformat */
case 'f': /* --font */ format = caca_optarg;
font = caca_optarg; break;
break; default:
case 'd': /* --dateformat */ return 1;
format = caca_optarg; break;
break; }
default: }
return 1; cv = caca_create_canvas(0, 0);
break; figcv = caca_create_canvas(0, 0);
} if(!cv || !figcv)
} {
fprintf(stderr, "%s: unable to initialise libcaca\n", argv[0]);
return 1;
}
cv = caca_create_canvas(0, 0); if(caca_canvas_set_figfont(figcv, font))
figcv = caca_create_canvas(0, 0); {
if(!cv || !figcv) fprintf(stderr, "Could not open font\n");
{ return -1;
fprintf(stderr, "%s: unable to initialise libcaca\n", argv[0]); }
return 1; dp = caca_create_display(cv);
} if(!dp) {
printf("Can't open window. CACA_DRIVER problem ?\n");
if(caca_canvas_set_figfont(figcv, font)) return -1;
{ }
fprintf(stderr, "Could not open font\n"); caca_set_color_ansi(figcv, CACA_DEFAULT, CACA_DEFAULT);
return -1; caca_clear_canvas(cv);
} for(;;) {
caca_event_t ev;
while(caca_get_event(dp, CACA_EVENT_KEY_PRESS
dp = caca_create_display(cv); | CACA_EVENT_QUIT, &ev, 1))
if(!dp) { {
printf("Can't open window. CACA_DRIVER problem ?\n"); if(caca_get_event_type(&ev))
return -1; goto end;
} }
char *d = get_date(format);
caca_set_color_ansi(figcv, CACA_DEFAULT, CACA_DEFAULT); uint32_t o = 0;
caca_clear_canvas(cv); // figfont API is not complete, and does not allow us to put a string
for(;;) { // at another position than 0,0
caca_event_t ev; // So, we have to create a canvas which will hold the figfont string,
// then blit this canvas to the main one at the desired position.
while(caca_get_event(dp, CACA_EVENT_KEY_PRESS caca_clear_canvas(cv);
| CACA_EVENT_QUIT, &ev, 1)) caca_clear_canvas(figcv);
{ while(d[o])
if(caca_get_event_type(&ev)) {
goto end; caca_put_figchar(figcv, d[o++]);
} }
char *d = get_date(format); caca_flush_figlet (figcv);
uint32_t o = 0; free(d);
w = caca_get_canvas_width (cv);
// figfont API is not complete, and does not allow us to put a string h = caca_get_canvas_height(cv);
// at another position than 0,0
// So, we have to create a canvas which will hold the figfont string,
// then blit this canvas to the main one at the desired position.
caca_clear_canvas(cv);
caca_clear_canvas(figcv);
while(d[o])
{
caca_put_figchar(figcv, d[o++]);
}
caca_flush_figlet (figcv);
free(d);
w = caca_get_canvas_width (cv);
h = caca_get_canvas_height(cv);
fw = caca_get_canvas_width (figcv); fw = caca_get_canvas_width (figcv);
fh = caca_get_canvas_height(figcv); fh = caca_get_canvas_height(figcv);


uint32_t x = (w/2) - (fw/2); uint32_t x = (w/2) - (fw/2);
uint32_t y = (h/2) - (fh/2); uint32_t y = (h/2) - (fh/2);


caca_blit(cv, x, y, figcv, NULL); caca_blit(cv, x, y, figcv, NULL);
caca_refresh_display(dp); caca_refresh_display(dp);
usleep(250000); usleep(250000);
} }
end: end:


caca_free_canvas(figcv); caca_free_canvas(figcv);
caca_free_canvas(cv); caca_free_canvas(cv);
caca_free_display(dp); caca_free_display(dp);


return 0; return 0;
} }

||||||
x
 
000:0
正在加载...
取消
保存