diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..8dd2b7f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "source_location": "c" + } +} \ No newline at end of file diff --git a/logfoo.c b/logfoo.c index 85e895f..cc39c77 100644 --- a/logfoo.c +++ b/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); } -// const char* luaColor(lua_State *L) { -// size_t textParaLen; -// const char *textParaStr; -// int colorPara; -// size_t textColorLen; -// char *textColorStr; - -// textParaStr = luaL_checklstring(L, 1, &textParaLen); -// colorPara = luaL_checkinteger(L, 2); - -// switch (colorPara) { -// case COLOR_RED: - -// //lua_pushlstring(); -// break; -// default: -// fprintf(stderr, "LUA function 'format' did not return a string\n"); -// exit(EXIT_LUAFILE_HANDLING); -// } -// } - +static int luaColor(lua_State *L) { + size_t strLen, colorLen; + const char *str, *color; + str = luaL_checklstring(L, 1, &strLen); + color = luaL_checklstring(L, 2, &colorLen); + int retLen = strLen + colorLen + 7; + char ret[retLen]; + sprintf(ret, "\033[%sm%s\033[0m", color, str); + + lua_pushlstring(L, ret, retLen); + return 1; +} int main(int argc, char *argv[]) { if (argc != 3) { @@ -111,6 +102,9 @@ int main(int argc, char *argv[]) { return EXIT_LUAFILE_HANDLING; } + lua_pushcfunction(L, luaColor); + lua_setglobal(L, "color"); + while ((bytesRead = getline(&line, &len, fp)) != -1) { size_t formatLen; const char *formatLine; diff --git a/lua/messages.lua b/lua/messages.lua index 9965ebf..376016c 100644 --- a/lua/messages.lua +++ b/lua/messages.lua @@ -3,5 +3,7 @@ function filter (line) end function format (line) + line = line:gsub("(IMAGE)", color("%1", "31;1;4")) + line = line:gsub("(gentoo)", color("%1", "32")) return line:match("\"([^\"]+)\"") end \ No newline at end of file