1 Star 0 Fork 4

calvinlin/vcc

forked from rain/vcc 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
pretty.c 4.00 KB
一键复制 编辑 原始数据 按行查看 历史
rain 提交于 2022-04-16 20:07 . vcc: remove libreadline
/* vcc/pretty.c
*
* This file is part of vcc.
*
* vcc is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* vcc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with vcc. If not, see <https://www.gnu.org/licenses/>
*/
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/times.h>
#include <vcc/vcc.h>
#include <vcc/version.h>
#include <vcc/pretty.h>
extern int current_sid;
extern char *usrname;
/* main.c */
void do_handle_command(char *);
struct theme theme_def = {
.usrname = {
.fg = FG_LIGHTBLUE,
.bg = BG_BLACK,
.mode = MODE_LINE
},
.sysusername = {
.fg = FG_RED,
.bg = BG_BLACK,
.mode = MODE_LINE
},
.msg = {
.fg = FG_YELLOW,
.bg = BG_BLACK,
.mode = MODE_HIGHLIGHT
},
.sysmsg = {
.fg = FG_GREEN,
.bg = BG_BLACK,
.mode = MODE_HIGHLIGHT
},
.sid = {
.fg = FG_RED,
.bg = BG_BLACK ,
.mode = MODE_HIGHLIGHT
},
.lvl = {
.fg = FG_YELLOW,
.bg = BG_BLACK,
.mode = MODE_LINE
},
.time = {
.fg = FG_YELLOW,
.bg = BG_BLACK,
.mode = MODE_HIGHLIGHT
},
.errmsg = {
.fg = FG_RED,
.bg = BG_BLACK,
.mode = MODE_HIGHLIGHT
},
.helpcmd = {
.fg = FG_LIGHTBLUE,
.bg = BG_BLACK,
.mode = MODE_HIGHLIGHT
},
.helpmsg = {
.fg = FG_WHITE,
.bg = BG_BLACK,
.mode = MODE_LINE
},
.cqd = {
.fg = FG_BLACK,
.bg = BG_RED,
.mode = MODE_BLINK
}
};
struct theme *current_theme = &theme_def;
int self_level;
#define curr_usrname (&current_theme->usrname)
#define curr_sysusername (&current_theme->sysusername)
#define curr_msg (&current_theme->msg)
#define curr_sysmsg (&current_theme->sysmsg)
#define curr_sid (&current_theme->sid)
#define curr_lvl (&current_theme->lvl)
#define curr_time (&current_theme->time)
#define curr_errmsg (&current_theme->errmsg)
#define curr_helpcmd (&current_theme->helpcmd)
#define curr_helpmsg (&current_theme->helpmsg)
#define curr_cqd (&current_theme->cqd)
int pretty_new_msg(char *usrname, char *buf, int sid) {
time_t time_now;
struct tm *tm_now;
ansi_csi_st(stdout, MODE_HIGHLIGHT, FG_BLACK, BG_BLACK);
setcolor(stdout, curr_time);
time_now = time(NULL);
tm_now = localtime(&time_now);
printf("\r[%02d:%02d] ", tm_now->tm_hour, tm_now->tm_min);
setcolor(stdout, curr_sid);
printf("#%d ", sid);
if (unlikely(!strcmp(usrname, "system"))) {
setcolor(stdout, curr_sysusername);
printf("system");
}
else {
setcolor(stdout, curr_usrname);
printf("%s", usrname);
}
ansi_csi_ed(stdout);
printf("@: ");
if (unlikely(!strcmp(usrname, "system"))) {
setcolor(stdout, curr_sysmsg);
printf("%s\n", buf);
}
else {
setcolor(stdout, curr_msg);
printf("%s\n", buf);
}
ansi_csi_ed(stdout);
return 0;
}
int pretty_prompt(char *usrname) {
ansi_csi_st(stderr, MODE_HIGHLIGHT, FG_BLACK, BG_BLACK);
setcolor(stderr, curr_sid);
fprintf(stderr, "#%03d ", current_sid);
setcolor(stderr, curr_lvl);
fprintf(stderr, "lvl%d ", self_level);
setcolor(stderr, curr_usrname);
fprintf(stderr, "%s", usrname);
ansi_csi_ed(stderr);
fprintf(stderr, "$: ");
return 0;
}
int pretty_unknown_cmd(char *s) {
fprintf(stderr, "unknown command: ");
setcolor(stderr, curr_errmsg);
fputs(s, stderr);
ansi_csi_ed(stderr);
return 0;
}
int pretty_cmd_help(char *cmdname, char *descr) {
setcolor(stdout, curr_helpcmd);
printf("%s:", cmdname);
setcolor(stdout, curr_helpmsg);
printf("\t%s\n", descr);
ansi_csi_ed(stdout);
return 0;
}
int pretty_cqd(char *username) {
printf("\n");
setcolor(stdout, curr_cqd);
printf("CQD");
ansi_csi_ed(stdout);
printf(" %s sent CQD. \n", username);
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/calvin-lin/vcc.git
[email protected]:calvin-lin/vcc.git
calvin-lin
vcc
vcc
master

搜索帮助