Mock Terminal

I’m not really sure what this would be useful for in practice, but it was pretty interesting to make and write for; it supports most standard terminal capabilities (colors/background inversion, input/output, etc.)

I’ll be making a tutorial for io/coroutines later, but the basics are:

function example()
    -- Reads text
    term.read("Enter some text: ")
    coroutine.yield()
    
    -- Prints text
    term.print("You typed: " .. term.getInput())

    -- Alternate read, for passwords
    -- Passing true as the second parameter to term.read causes characters to be hidden
    term.read("Enter your password: ", true)
    coroutine.yield()

    -- Prints text again
    term.print("Your password is: " .. term.getInput())
end

term.coroutine = coroutine.create(example)

To download, paste this code into a new project and run it:

function setup()
    spriteMode(CORNER)
    http.request("https://www.dropbox.com/s/r0t447nv4hwx98r/fdata.png?dl=1", function(im) 
    local i = image(im.width/2,im.height/2) setContext(i) sprite(im, 0,0,im.width/2, im.height/2) setContext() saveImage("Documents:FDATA_MODES", i) print("Font saved") end, print)
    http.request("https://github.com/FeynmanTech/codea-terminal/raw/master/terminal.lua", 
    function(data)
        for tab, src in data:gmatch("%-%-%[=%[TAB:(.-)%]=%]\
(.-)%-%-%[=%[END_TAB%]=%]") do
            saveProjectTab(tab, src)
        end
        print("Done")
        restart()
    end)
end

You can also download the command repo I use:

function setup()
    http.request("https://github.com/FeynmanTech/codea-terminal/raw/master/cmd.lua", 
    function(data)
        for tab, src in data:gmatch("%-%-%[=%[TAB:(.-)%]=%]\
(.-)%-%-%[=%[END_TAB%]=%]") do
            saveProjectTab(tab, src)
        end
    end)
end

After creating that project, set it as the cmd project during setup, and it will be loaded on startup. There’s a wide variety of programs there, encompassing the entirety of the terminal’s capabilities, so it could be a good starter for boilerplate code

EDIT: I’ve updated the main source and the font, adding bolded text and fixing a few things.

I added a basic tutorial in the command repo, devhelp. Since there are no arrow keys on the iOS keyboard, press p or q to move the cursor up in the selection menu, and a or l to move it down.

This looks pretty good @FLCode , but I get an error went starting the project. I can press resume and it continues to run, but I’m not sure if it is working properly. The error is:

error: [string: "--cl.ALL.ERR.CRITICAL = false...]:
150: attempt to index a nil value (global 'ic')

Just wondering if this is my iPad, or the project.

Jonathon

No worries, that’s a legacy feature from when I still used individual charsprites for text rendering.
EDIT: At line 150 of the Terminal tab, there should be a function that looks like this:

function loadChars()
    ic, ici = readImage("Documents:char"), readImage("Documents:ichar")
    
    for n = 0, 255 do
        chr[string.char(n)] = ic:copy(n*(chx), 0, chx, chy)
        ichr[string.char(n)] = ici:copy(n*(chx), 0, chx, chy)
        mod[string.char(n)] = 0
    end
end

Comment out some of the lines so it looks like this:

function loadChars()
    --ic, ici = readImage("Documents:char"), readImage("Documents:ichar")
    
    for n = 0, 255 do
        --chr[string.char(n)] = ic:copy(n*(chx), 0, chx, chy)
        --ichr[string.char(n)] = ici:copy(n*(chx), 0, chx, chy)
        mod[string.char(n)] = 0
    end
end

Then it should run without complaint.

Awesome thanks! @FLCode

No problem. I’ve made some changes since then, I might be updating it soon.

I’ve made lots of changes, including isolated user profiles with elevation; I should be making an update soon.
EDIT: Update’s released, to download it run the setup code again. I’ve also updated the command repo; the main update is in the log command, which has added more functionality and individual log storage for each user.

Another update coming soon, I’ll be improving the way user accounts are created!
(Just curious, does it run fine for you guys? It works for me but there could be bugs on a fresh setup)