Last active
January 18, 2024 19:36
-
-
Save andreacfromtheapp/254cb01872a034222c6034826e4bdc61 to your computer and use it in GitHub Desktop.
chuck-nvim shred idea
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[chuck]: (VM) sporking incoming shred: 1 (test1.ck)... | |
[chuck]: (VM) sporking incoming shred: 2 (test2.ck)... | |
[chuck]: (VM) replacing shred 1 (test1.ck) with 1 (chant1.ck)... | |
mi0 97.998859 | |
mi0 97.998859 | |
mi0 97.998859 | |
ut1 77.781746 | |
ra1 82.406889 | |
ut1 77.781746 | |
ra1 82.406889 | |
ra1 82.406889 | |
ut1 77.781746 | |
ra1 82.406889 | |
ra1 82.406889 | |
ra1 82.406889 | |
[chuck]: (VM) replacing shred: no shred with id 3... | |
[chuck]: (VM) cannot remove: no shred with id 8... | |
ut1 77.781746 | |
ra1 82.406889 | |
ra1 82.406889 | |
ra1 82.406889 | |
ut1 77.781746 | |
ra1 82.406889 | |
mi0 97.998859 | |
mi0 97.998859 | |
ra1 82.406889 | |
mi0 97.998859 | |
ra0 82.406889 | |
ut0 77.781746 | |
[chuck]: (VM) removing shred: 1 (chant1.ck)... | |
[chuck]: (VM) sporking incoming shred: 3 (test3.ck)... | |
[chuck]: (VM) sporking incoming shred: 4 (test4.ck)... | |
[chuck]: (VM) sporking incoming shred: 5 (test5.ck)... | |
[chuck]: (VM) sporking incoming shred: 2 (test2.ck)... | |
[chuck]: (VM) replacing shred 2 (test2.ck) with 2 (chant2.ck)... | |
###### remove this line to see the effect of the above lines ###### | |
[chuck]: (VM) removing all (4) shreds... | |
################################################################### | |
[chuck]: (VM) EXIT received.... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- shreds table to build the Shred UI with NuiTable | |
local shreds_table = {} | |
-- split line into columns and return each word as line | |
local function column(line, n) | |
local p = string.rep("%s+.-", n - 1) .. "(%S+)" | |
return line:match(p) | |
end | |
-- if the log line matches a certain word/pattern we set an action | |
local function set_action(line) | |
local action | |
if string.match(line, "sporking incoming shred: %d") then | |
action = "add" | |
end | |
if string.match(line, "replacing shred %d") then | |
action = "replace" | |
end | |
if string.match(line, "removing shred: %d") then | |
action = "remove" | |
end | |
-- if clearing or exiting, empty the table and set action to nil | |
if string.match(line, "removing all shreds") then | |
for k in pairs(shreds_table) do | |
shreds_table[k] = nil | |
end | |
action = nil | |
end | |
return action | |
end | |
-- set the shreds table from raw ChucK data ["id"] = "value" | |
local function set_shreds_tbl(line) | |
local action = set_action(line) | |
-- if the log line matches a certain word/pattern | |
if action ~= nil then | |
local shred_id | |
local shred_name | |
-- get string length | |
local _, count = string.gsub(line, "% ", "") | |
-- iterate over the string | |
for n = 1, count + 1 do | |
-- split line to columns and match the last id and last filename | |
local id = column(line, n):match("%d+") | |
local name = column(line, n):match("%((.+)%).+") | |
-- if id is valid initialize shred_id | |
if id ~= nil then | |
shred_id = tostring(id) | |
end | |
-- if name is valid initialize shred_name | |
if name ~= nil then | |
shred_name = name | |
end | |
-- if shred_id and shred_name are valid | |
if shred_id ~= nil and shred_name ~= nil and shred_name:match(".ck") then | |
-- if adding/replacing set shred as: id is key -> shred_name is value | |
if action == "add" or "replace" then | |
shreds_table[shred_id] = shred_name | |
end | |
-- if removing set shred as nil: id is key -> nil | |
if action == "remove" then | |
shreds_table[shred_id] = nil | |
end | |
end | |
end | |
end | |
end | |
local function peaceout() | |
for k, v in pairs(shreds_table) do | |
print(string.format("%d %s", k, v)) | |
end | |
end | |
local function shred_lines(logfile) | |
local cmd = string.format("tail -f %s", logfile) | |
local pipe = assert(io.popen(cmd)) | |
repeat | |
local line = pipe:read(1) | |
if line then | |
set_shreds_tbl(line) | |
io.write(line) | |
io.flush() | |
end | |
until not line | |
pipe:close() | |
peaceout() | |
end | |
shred_lines("chuck.log") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
notes from discord: