Log In  


This function abuses Unicode and ANSI color codes to output a screenshot of the current screen to a text terminal such as xterm. You can record the PICO-8 rendering and replay it using “cat”! You can run PICO-8 over ssh! You can be anything you want.

I also set up a telnet service demonstrating the feature:

telnet lol.pm 12345

Here is how it looks like; this is PICO-8 (small window) launched from GNOME Terminal (large window) just after screenshot() was called:

And here is the code:

pico-8 cartridge // http://www.pico-8.com
version 8
__lua__
-- screenshot to console
-- by sam hocevar

function screenshot()
 local l={ 16, 17, 89, 29, 131, 240, 251, 230, 197, 214, 220, 47, 39, 103, 211, 223 }
 local e="\027["
 printh(e.."?25l") -- hide cursor
 for y=0,63 do
  local ofg,obg=-1,-1
  local s=e..(y+1)..";1\072" -- uppercase h
  for x=0,127 do
   fg,bg,ch=pget(x,y*2),pget(x,y*2+1),"\226\150\128"
   if bg>fg then
    fg,bg,ch=bg,fg,"\226\150\132"
   end
   if fg!=ofg or bg!=obg then
    s=s..e
    local t=""
    if (bg!=obg) s,t=s.."48;5;"..l[bg+1],";"
    if (fg!=ofg) s=s..t.."38;5;"..l[fg+1]
    s=s.."m"
   end
   s=s..ch
   ofg,obg=fg,bg
  end
  printh(s..e.."0m"..e.."\075") -- uppercase k
 end
 printh(e.."?25h") -- show cursor
end

The terminal must be UTF-8 and 256-color aware, so this will probably work in most Linux and OS X terminals. On Windows I could test it successfully with the MSYS2 terminal.

2


Wow, very cool!


applause



[Please log in to post a comment]