今天完成了twilc的filter display部分,添加了三个filter:mention(黄色),RT(红色分行)和URL(蓝色),效果如下:

不过这张图里面urxvt的配色没调,显示效果有点囧_,=||
filter机制的实现主要使用到C函数指针,
typedef struct filter{
char *pattern;
char *(*get_pattern_end)(char *);
void (*before_filter)(WINDOW *);
void (*after_filter)(WINDOW *);
} display_filter;
char *pattern;
char *(*get_pattern_end)(char *);
void (*before_filter)(WINDOW *);
void (*after_filter)(WINDOW *);
} display_filter;
这里pattern是该filter的特征字符串(比如mention是”@”, URL就是”http://”),get_pattern_end用于返回该filter的显示效果生效的终止位置,before_filter和after_filter函数配合使用开启和关闭显示效果。
下面是mention filter的实现:
void before_mention(WINDOW *win){
init_pair(1, COLOR_YELLOW, COLOR_BLACK);
wattron(win,COLOR_PAIR(1));
}
void after_mention(WINDOW *win){
wattroff(win, COLOR_PAIR(1));
}
char *get_mention_end(char *begin){
if((*begin) != '@')
return 0;
char *p = begin + 1;
int x = *p;
while(x != '�' && ((x>='a' && x<='z')||(x>='A' && x<='Z')
|| (x >= '0' && x <= '9')|| x=='_'))
x = *(++p);
return p;
}
init_pair(1, COLOR_YELLOW, COLOR_BLACK);
wattron(win,COLOR_PAIR(1));
}
void after_mention(WINDOW *win){
wattroff(win, COLOR_PAIR(1));
}
char *get_mention_end(char *begin){
if((*begin) != '@')
return 0;
char *p = begin + 1;
int x = *p;
while(x != '�' && ((x>='a' && x<='z')||(x>='A' && x<='Z')
|| (x >= '0' && x <= '9')|| x=='_'))
x = *(++p);
return p;
}
这样要增加filter的话就比较方便了。
struct filter *mention_filter = malloc(sizeof(struct filter));
mention_filter->pattern = "@";
mention_filter->get_pattern_end = get_mention_end;
mention_filter->before_filter = before_mention;
mention_filter->after_filter = after_mention;
mention_filter->pattern = "@";
mention_filter->get_pattern_end = get_mention_end;
mention_filter->before_filter = before_mention;
mention_filter->after_filter = after_mention;
另外昨天注册了SegmentFault,貌似是推友做的StackOverflow的中文版本,感觉还不错。试着用GAS回答了一下猫猫姑娘提的用各种编程语言写HelloWorld的问题才发现GAS几乎都忘光了_,=
再PS,Gnome3进Arch的extra了,上两张图:


Posted from Beijing, Beijing, China.
If you enjoyed this post, make sure you subscribe to my RSS feed!



咦,居然是C,不是Python么
@wayne
一直就是C阿…
求源码
@SteamedFish
还没写完呢…
要有头像啊头像啊
@Tim喵
无视无理要求~
居然是C的…
@pipitu
其实可以显示头像的阿啦兔兔
我也想试试 Gnome 3 了.