Log In  

Here's my /appdata/system/startup.lua file (picotron automatically runs it on startup)

-- take str, delete all chars between
-- indices i0 and i1 (inclusive), and
-- insert newstr into that space
local function splice(str,i0,i1, newstr)
    return sub(str,1,max(1,i0)-1)..(newstr or "")..sub(str,i1+1)
end

-- use str:find to do sed-like file editing.
-- no lua patterns, just literal string matching
-- return str, but replace the first instance of cut with paste
local function _replace(str,cut,paste)
    local i0,i1 = str:find(cut,1,true) -- no pattern-matching
    if not i0 then
        return str,false
    end
    return splice(str,i0,i1,paste),true
end

local function sedish(fname,mods)
    local src = fetch(fname)
    if not src then
        printh("sedish: couldn't find file "..fname)
        return
    end

    for i,mod in ipairs(mods) do
        local cut,paste = unpack(mod)
        -- printh(cut.." "..paste)
        if not cut or not paste then
            printh("sedish: bad cut/paste data in "..fname)
            return
        end
        local changed
        src,changed = _replace(src,cut,paste)
        if not changed then
            printh("sedish: mod #"..i.." did nothing to "..fname)
        end
        if not src or #src==0 then
            printh("sedish: bad result in "..fname)
            return
        end
    end
    -- printh("storing "..fname..": "..sub(src,1,100):gsub("[\n\r]",""))
    store(fname,src)
end

sedish("/system/lib/gui_ed.lua",{
    { -- fix alt-tab annoyance (pressing alt-tab inserts tab character into code)
        [[if (keyp("tab")) then]],
        [[if keyp"tab" and not key"alt" then]],
    },
})

sedish("/system/apps/podtree.p64/main.lua",{
    { -- fix podtree bug (pressing enter crashes the program)
        [[if(key("shift")) return true]],
        [[if(_ENV.key("shift")) return true]],
    },
})

-- (you need to open a new gfx tab for these gfx.p64 edits to work)
sedish("/system/apps/gfx.p64/pal.lua",{
    { -- show pal numbers
        [[pcols[x + y*epr])]],
        [[pcols[x + y*epr])if pal_swatch==1 and x%2==0 then print(pcols[x + y*epr],x*ww+5,y*ww+1,0) end]],
    },
})
-- sedish("/system/apps/gfx.p64/nav.lua",{
--  { -- display sprite numbers in hex
--      [[string.format("%03d",current_item)]],
--      [[string.format("x%02x",current_item)]],
--  },
-- })
sedish("/system/apps/gfx.p64/update.lua",{
    { -- don't flip when you press ctrl-v (noticeable when undoing)
        [[if (keyp("v"))]],
        [[if (keyp"v" and not key"ctrl")]],
    },
})

sedish("/system/lib/gui_ed.lua",{
    { -- fix custom key callbacks in gui
        [[content.key_callback(k)]],
        [[content.key_callback[k](k)]],
    },
})

-- doesn't work for startup terminal
--   need to wait for it to regenerate, e.g. after running a fullscreen app
sedish("/system/apps/terminal.lua",{
    { -- add custom terminal_cd event (to let my z.lua util "run" cd for you)
        [[-- scroll down only if needed]],
        [[on_event("terminal_cd",function(msg) cd(msg.path) end)]],
    },
    { -- show slightly different terminal prompt when in upgraded terminal
        [[return result -- custom prompt goes here]],
        [[return "\f6"..pwd().."\f7 > "]],
    },
})

printh "sedish done"

what is this

I made this because picotron inserts a tab into my code whenever I alt-tab. I figured out how to edit the code editor itself to not do that, and then I made this script to automatically make the required edits. (you can't just edit the files on disk, because they get regenerated every time picotron boots)

this won't be necessary for too long hopefully, but it works great for now!

(the name "sedish" comes from the (loose) inspiration for this: sed)

post your tweaks

If anyone has other system tweaks like this one (fixing alt-tab), post them here!

P#143638 2024-03-18 04:05 ( Edited 2024-04-24 01:28)

1

This is great! I didn't know about gsub, which is awesome, and the idea of editing or replacing system files is great. This could open up all kinds of fun tweaks :) Plus the alt+tab behavior you noticed has been driving me nuts too ... if this fixes that, I'm very happy lol. Nice find!

P#143649 2024-03-18 05:32

updated: I removed gsub (too confusing) and now use string.find in literal mode. and I added some more tweaks!

P#143813 2024-03-19 08:04

Is this now fixed in 0.1.0c? I'm alt-tabbing on windows while in the code editor and it's not putting tabs into the code.

P#144418 2024-03-25 14:43

@Diablothe2nd it still inserts a tab for me on 0.1.0c. I'm on linux, maybe its an OS difference?

P#144488 2024-03-26 02:52

@pancelor Ah! Yep, when I tested the linux version on my steam deck the bug still exists. There definitely is a disparity between OS versions.
I'm curious if this affects Mac users too?

P#144510 2024-03-26 10:18 ( Edited 2024-03-26 10:19)
1

Here's one to fix my own pet peeve: Currently if you press CtrlShiftZ the GUI acts as if you just pressed CtrlZ... which might not be noticeable if you're used to CtrlY instead, but I'm used to CtrlShiftZ (most drawing programs use this one, it's a lot more comfortable than reaching over to Y)

sedish("/system/lib/gui_ed.lua",{
    { -- fix ctrl-shift-z acting like normal ctrl-z
        [[undo_stack:undo()]],
        [[if key"shift" then undo_stack:redo() else undo_stack:undo() end]],
    },
})
P#150068 2024-06-18 04:54
1

Filenav deliberately prevents you from renaming files from the desktop. There's probably a really important reason for this, but I don't know what it is. So here's a small fix for that:

sedish("/system/apps/filenav.p64/finfo.lua", {
    {-- Mod: Enable renaming files on desktop
    [[      -- rename 
        if (mode ~= "desktop") then]],
    [[
            -- rename 
        if (true) then]] -- This is lazy, but it gets it done in the fewest amount of lines
    }
})
P#150921 2024-07-06 07:15

[Please log in to post a comment]