Goal:
Lua command line terminal
Rules:
-typed input via the keyboard
-execute commands by pressing enter
-delete characters via backspace
-do not use external files, system fonts or love's default embedded font
Extra credit:
-print results and errors on the screen
-upper and lowercase, caps
-allow printing in the terminal, ex: print("123") or print(1+2)
-shift modifier
-numeric keypad
-locals
1K Terminal challenge
1K Terminal challenge
Last edited by ivan on Mon Oct 17, 2016 7:26 pm, edited 9 times in total.
Re: 1K Terminal challange
Test with a large 8x8 font = 1,531 bytes:
Note: artifacts probably due to newImageData, no locals
Code: Select all
F=" 66 __ ` 66?c6f_ 0 63<_ 6?n ÿ? ? 0; <_ _ 6?f3 f 6cn _ _______ 8??_ 3+<+3_ 3;0060+?0?30> 0700330_?3+0+3 ??0 _____ __>?<?<3xgcccff6FFf30fwg6{3ff306oc{3>f?0k{c{?ffs336Fcsc3ff6Ff33ffcc63?<?|3gcc________???+cc3 f3f3-+cc+ f3f+c636 >3>+kc ;8+6F0_633wcc`_8g?cc@________ ÿ 8 _ 0 6 __ >0n6f7 0f3>33n6+ >f3?3fk+ 3f+>f6c+ n=n0ggc3___ _____ ___8n_____;;n>>+cc3? 6f36+c63 8 cf36+k3 c>>0,36>& c0n6c0?8 x___ ___"F=F:gsub("_"," "):gsub("+","33")O=""for a=1,#F do b=F:byte(a)for j=1,8 do h=b%2;O=O..(h>0 and"ÿÿÿÿ"or" y")b=(b-h)/2 end end;L=love;G=L.graphics;d=L.image.newImageData(128,48,O)I=G.newImage(d)Q={}for c=0,5 do for f=0,15 do Q[#Q+1]=G.newQuad(f*8,c*8,8,8,128,48)end end;function W(g,f,c)for a=1,#g do b=g:byte(a)-31;if Q[b]then G.draw(I,Q[b],f+(a-1)*8,c)else W(g:sub(a+1),f,c+8)break end end end;O=""function L.draw()W(O.."_",0,0)end;function print(i)O=O.."\n"..tostring(i)end;Z='~!@#$%^&*()_+|{}:"<>?'z="`1234567890-=\\[];',./"function L.keypressed(k)if k=="space"then O=O.." "elseif k=="backspace"then O=O:sub(1,-2)elseif k=="return"then e=O:match("[^\n]-$")r,t=pcall(loadstring(e))O=O.."\n"..(t or"").."\n"elseif#k<2 then if L.keyboard.isScancodeDown('lshift')then j=z:find(k,1,true)k=j and Z:sub(j,j)or k;k=k:upper()end;O=O..k end end
- Attachments
-
1kterminal.love
- version 1
- (1.1 KiB) Downloaded 346 times
Last edited by ivan on Sun May 22, 2016 5:30 am, edited 5 times in total.
Re: 1K Terminal challange
It's so hard. I couldn't do it. I use your code, optimize it a bit, and now can use right shift for caps, with 3 bytes in extra (1,528 bytes).
Code: Select all
F=(" 66 __ ` 66?c6f_ 0 63<_ 6?n ÿ? ? 0; <_ _ 6?f3 f 6cn _ _______ 8??_ 3+<+3_ 3;0060+?0?30> 0700330_?3+0+3 ??0 _____ __>?<?<3xgcccff6FFf30fwg6{3ff306oc{3>f?0k{c{?ffs336Fcsc3ff6Ff33ffcc63?<?|3gcc________???+cc3 f3f3-+cc+ f3f+c636 >3>+kc ;8+6F0_633wcc`_8g?cc@________ ÿ 8 _ 0 6 __ >0n6f7 0f3>33n6+ >f3?3fk+ 3f+>f6c+ n=n0ggc3___ _____ ___8n_____;;n>>+cc3? 6f36+c63 8 cf36+k3 c>>0,36>& c0n6c0?8 x___ ___"):gsub("_"," "):gsub("+","33")O=""for a=1,#F do b=F:byte(a)for j=1,8 do h=b%2 O=O..(h>0 and"ÿÿÿÿ"or" y")b=(b-h)/2 end end L=love G=L.graphics K=L.keyboard.isScancodeDown I=G.newImage(L.image.newImageData(128,48,O)) Q={}for c=0,5 do for f=0,15 do Q[#Q+1]=G.newQuad(f*8,c*8,8,8,128,48) end end function W(g,f,c) for a=1,#g do b=g:byte(a)-31 if Q[b]then G.draw(I,Q[b],f+(a-1)*8,c)else W(g:sub(a+1),f,c+8)break end end end O=""function L.draw()W(O.."_",0,0)end function print(i)O=O.."\n"..tostring(i)end Z='~!@#$%^&*()_+|{}:"<>?'z="`1234567890-=\\[];',./"function L.keypressed(k)k=k:gsub("space"," ")if k=="back "then O=O:sub(1,-2)elseif k=="return"then e=O:match("[^\n]-$")r,t=pcall(loadstring(e))O=O.."\n"..(t or"").."\n"elseif#k<2 then if K('lshift')or K('rshift') then j=z:find(k,1,true)k=(j and Z:sub(j,j)or k):upper()end O=O..k end end
Re: 1K Terminal challange
Great, I'll use your version in future revisions.
It's possible to get it under 1k, if we use a smaller font - as you see from the image in the previous post 8x8 px per character is a lot.
Also, there is a "bug" with: r,t=pcall(loadstring(e)) - it doesn't print the exact Lua error, I'll see if I can fix it in the future.
Thanks for taking a look!
It's possible to get it under 1k, if we use a smaller font - as you see from the image in the previous post 8x8 px per character is a lot.
Also, there is a "bug" with: r,t=pcall(loadstring(e)) - it doesn't print the exact Lua error, I'll see if I can fix it in the future.
Thanks for taking a look!
- DeltaF1
- Citizen
- Posts: 64
- Joined: Mon Apr 27, 2015 4:12 pm
- Location: The Bottom of the Stack
- Contact:
Re: 1K Terminal challange
I can't run this, it says "The size of the raw byte string must match the imageData's actual size in bytes."
Re: 1K Terminal challange
Instructions ambiguous. Here's my entry.
Code: Select all
local buffer = ''
function love.draw ()
love.graphics.printf(buffer, 0, 0, 800)
end
function love.textinput (text)
buffer = buffer .. text
end
function love.keypressed (key)
if key == 'backspace' then
buffer = buffer:gsub('[^\n]$', '')
elseif key == 'return' then
buffer = buffer .. '\n' ..
io.popen(buffer:match('[^\n]*$') .. ' 2>&1'):read('*a') .. '\n'
end
end
Re: 1K Terminal challange
Might have something to do with the encoding of the .lua file so I've included a .love.DeltaF1 wrote:I can't run this, it says "The size of the raw byte string must match the imageData's actual size in bytes."
The point of the challenge is to make a terminal without using external/system fonts. In 1K or less.Instructions ambiguous
![Smile :)](./images/smilies/ms-smile.png)
Re: 1K Terminal challange
I guess I did that, then.ivan wrote:The point of the challenge is to make a terminal without using external/system fonts. In 1K or less.
Re: 1K Terminal challange
Unfortunately, you used love.graphics.printf which doesn't comply with the rules.
The embedded Love2D font is around 400 k in its non-compiled form.
The embedded Love2D font is around 400 k in its non-compiled form.
Re: 1K Terminal challange
The rules don't restrict the use of love.graphics.printf or the use of the font that's packaged with love as far as I can tell. They also don't mention what the terminal is supposed to do (mine runs shell commands). The rules also don't mention anything about counting the size of assets packaged with love against the 1k character count. That's not something I'd expect given that those assets were not part of my submission. As far as I can tell, my entry complies with the rules as written.ivan wrote:Unfortunately, you used love.graphics.printf which doesn't comply with the rules.
The embedded Love2D font is around 400 k in its non-compiled form.
Who is online
Users browsing this forum: Ahrefs [Bot] and 72 guests