scottmada [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=12577 ANSI escape codes (or &quot;how to add color to my printh()&quot;) <p>This maybe not new for some users, but I did search the forums and I didn't found any post about this, so...</p> <p><strong>ANSI escape codes do work on Pico-8!<em></strong><br /> <em></em>when using</em> printh()</p> <p>Let me explain. ANSI escape codes are sets of commands to use in terminals to <a href="https://en.wikipedia.org/wiki/ANSI_escape_code">&quot;control the formatting, color, and other output options on video text terminals&quot;</a>.</p> <p>Yes. And what? (you say)</p> <p>It means a lot! Look at this piece of code. It clears the screen on _init(). And it sets text to green, then resets it to the default color afterwards. (PSST... It may be useful for debugging purposes!)</p> <div> <div style="max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> function _init() init_console() printh(&quot;what is this? color??&quot;) end function init_console() -- note: ansi escape codes -- are case-sensitive. -- note: printh still adds a -- new line each time you -- call it, even if it only -- contains escape codes. -- clear the screen -- (&quot;\27&quot; is esc char) -- (&quot;\74&quot; is capital j) a_clear = &quot;\27[2\74&quot; -- reset the cursor top left -- (&quot;\72&quot; is capital h) a_cur_tl = &quot;\27[1;1\72&quot; -- set to green a_col_gr = &quot;\27[32m&quot; -- reset color to default a_col_df = &quot;\27[39;49m&quot; -- let's print some text printh( a_clear .. a_cur_tl .. a_col_gr .. &quot;==&gt; console initialized...&quot; .. a_col_df ) end </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>It should work out-of-the-box on Linux. For Windows, Wikipedia says it should work on a Windows 10 command line prompt. Here's the result on a OS X terminal:</p> <img style="" border=0 src="https://www.lexaloffle.com/bbs/files/12577/ansi-pico8-whatisthis.png" width=682 height=548 alt="" /> <p>There you go. I hope it helps.</p> https://www.lexaloffle.com/bbs/?tid=3956 https://www.lexaloffle.com/bbs/?tid=3956 Fri, 29 Jul 2016 16:07:41 UTC Pico8 Missing Builtins <p> <table><tr><td> <a href="/bbs/?pid=22824#p"> <img src="/bbs/thumbs/pico23349.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=22824#p"> Pico8 Missing Builtins v0.2.0</a><br><br> by <a href="/bbs/?uid=12577"> scottmada</a> <br><br><br> <a href="/bbs/?pid=22824#p"> [Click to Play]</a> </td></tr></table> </p> <p><a href="https://github.com/adamscott/pico8-missing-builtins">View on Github.com</a></p> <p>You miss built-in lua functions such as ipairs or getmetatable in pico-8? Well, fear no more.</p> <p><strong>Currently supported Lua &quot;built-in&quot; functions</strong></p> <div> <div style="max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> getmetatable setmetatable rawget unpack ipairs table.pack table.unpack as an alias to unpack table.insert table.remove table.sort </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p><strong>Tested to imitate their counterparts</strong></p> <p>Travis-CI is set to test missing.lua against test.lua, which compares results of this library functions with the built-in ones. Well, tests may be incomplete, so do not hesitate to flag a bug to the issue tracker if something goes wrong.</p> <p><strong>How to use</strong></p> <p>Heads up to the <a href="https://github.com/adamscott/pico8-missing-builtins/releases/latest">latest release</a>. Then, there's two options:</p> <pre><span style=" display:inline-block; background-color:#eee; padding:2px; margin: 4px; padding-left: 8px; padding-right: 8px; color:#222">[box=ffeedd]Either you download </pre> <div> <div style="max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> missing.lua </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>then copy the file contents into your .p8 project file, preferably before the rest of your code; or[/box]<br /> <table style="width:640px" cellspacing=0 cellpadding=10><tr><td bgcolor=#ffeedd><span style="color: #101010;">you load missing.p8 in pico-8 to test it out first.<br></span></td></tr></table></p> <p><strong>About this license</strong></p> <p>This library is under creative commons license <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC4-BY-NC-SA</a>. See <a href="https://github.com/adamscott/pico8-missing-builtins/blob/master/LICENSE.md">LICENSE.md</a>. It's the same license as the optional one on Lexaloffle's website if you choose to publish a cart.</p> <p>So, if you happen to publish a cart using this library, it would be nice if you mention it.</p> <p><strong>Thanks</strong></p> <p>To Lexaloffle, which this library would not exist without pico-8.</p> <p><strong>Changes</strong></p> <p><table style="width:640px" cellspacing=0 cellpadding=10><tr><td bgcolor=#ffeedd><span style="color: #101010;"><br /> <strong>0.2</strong><br /> Add some table functions.</p> <div> <div style="max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> table.pack table.unpack as an alias to unpack table.insert table.remove table.sort </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>Refactor </p> <div> <div style="max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> ipairs </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>to make it return an iter function, as the native one does.<br /> <br></span></td></tr></table></p> <p><table style="width:640px" cellspacing=0 cellpadding=10><tr><td bgcolor=#ffeedd><span style="color: #101010;"><br /> <strong>0.1</strong><br /> Add</p> <div> <div style="max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> getmetatable setmetatable rawget unpack ipairs </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p><br></span></td></tr></table></p> https://www.lexaloffle.com/bbs/?tid=3599 https://www.lexaloffle.com/bbs/?tid=3599 Mon, 13 Jun 2016 06:11:11 UTC