colorizing
This commit is contained in:
parent
6ac0ea9b35
commit
72bffca489
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"source_location": "c"
|
||||||
|
}
|
||||||
|
}
|
36
logfoo.c
36
logfoo.c
@ -59,28 +59,19 @@ const char* luaFormatCall(lua_State *L, char *line, size_t len, size_t *formatLe
|
|||||||
return lua_tolstring(L, -1 , formatLen);
|
return lua_tolstring(L, -1 , formatLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
// const char* luaColor(lua_State *L) {
|
static int luaColor(lua_State *L) {
|
||||||
// size_t textParaLen;
|
size_t strLen, colorLen;
|
||||||
// const char *textParaStr;
|
const char *str, *color;
|
||||||
// int colorPara;
|
str = luaL_checklstring(L, 1, &strLen);
|
||||||
// size_t textColorLen;
|
color = luaL_checklstring(L, 2, &colorLen);
|
||||||
// char *textColorStr;
|
int retLen = strLen + colorLen + 7;
|
||||||
|
char ret[retLen];
|
||||||
// textParaStr = luaL_checklstring(L, 1, &textParaLen);
|
sprintf(ret, "\033[%sm%s\033[0m", color, str);
|
||||||
// colorPara = luaL_checkinteger(L, 2);
|
|
||||||
|
lua_pushlstring(L, ret, retLen);
|
||||||
// switch (colorPara) {
|
|
||||||
// case COLOR_RED:
|
|
||||||
|
|
||||||
// //lua_pushlstring();
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// fprintf(stderr, "LUA function 'format' did not return a string\n");
|
|
||||||
// exit(EXIT_LUAFILE_HANDLING);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
@ -111,6 +102,9 @@ int main(int argc, char *argv[]) {
|
|||||||
return EXIT_LUAFILE_HANDLING;
|
return EXIT_LUAFILE_HANDLING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lua_pushcfunction(L, luaColor);
|
||||||
|
lua_setglobal(L, "color");
|
||||||
|
|
||||||
while ((bytesRead = getline(&line, &len, fp)) != -1) {
|
while ((bytesRead = getline(&line, &len, fp)) != -1) {
|
||||||
size_t formatLen;
|
size_t formatLen;
|
||||||
const char *formatLine;
|
const char *formatLine;
|
||||||
|
@ -3,5 +3,7 @@ function filter (line)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function format (line)
|
function format (line)
|
||||||
|
line = line:gsub("(IMAGE)", color("%1", "31;1;4"))
|
||||||
|
line = line:gsub("(gentoo)", color("%1", "32"))
|
||||||
return line:match("\"([^\"]+)\"")
|
return line:match("\"([^\"]+)\"")
|
||||||
end
|
end
|
Loading…
x
Reference in New Issue
Block a user