Skip to main content
  1. Posts/

Day 64 - ANSI happiness

OldDays seitan-spin cucumber ruby

Ah, the good old days.
Ah, the good old days.

In which we handle some escape codes, or rather have someone else handle them.

Ring completeness

So first we write the other three tests to complete the RequireMakeRecallReagent tests: We need the reagent but don’t have it, we don’t need it but do have it, and we do need it and do have it. Not too difficult.

A truly sad path:

And I cast the warmed spell
Then My spellbook exploded
And I do not have a recall ring in my "left" hand
And I do not have a recall ring in my "right" hand

And now:

29 scenarios (29 passed)
213 steps (213 passed)

Process that output

Paging through the debug output from some of these tests, it’s clear that I need to start handling the ANSI escape codes.

expected "cast\n\e[2J\e[1;1f\e[3;6H  \e[3;8H  \e[3;10H  \e[3;12H  \e[3;14H  \e[3;16H  \e[3;18H  
\e[4;6H  \e[4;8H\e[44m\e[1;30m~~\e[0m\e[4;10H\e[44m\e[1;30m~~\e[0m\e[4;12H\e[44m\e[1;30m~~\e[0m
\e[5;8H\e[44m\e[1;30m~~\e[0m\e[5;10H. \e[5;12H. \e[5;14H. \e[5;16H. \e[5;18H. \e[6;6H  \e[6;8H
\e[44m\e[1;30m~~\e[0m\e[6;10H. \e[6;12H. \e[6;14H. \e[6;16H. \e[6;18H. \e[7;6H  \e[7;8H\e[44m
\e[1;30m~~\e[0m\e[7;10H. \e[7;12H. \e[7;14H. \e[7;16H. \e[7;18H. \e[8;6H  \e[8;8H\e[44m\e[1;30m~~
\e[0m\e[8;10H. \e[8;12H. \e[8;14H. \e[8;16H. \e[8;18H. \e[9;6H  \e[9;8H\e[44m\e[1;30m~~\e[0m
\e[9;10H. \e[9;12H. \e[9;14H. \e[9;16H. \e[9;18H. \e[2;24H A dog\e[8;16HA\e[6;12Hv
\e[23;1H                             \e[23;1H \e[1;32mR spellbook\e[0m
\e[24;1H                             \e[24;1H \e[1;32mL ring\e[0m\e[23;42H      \e[23;30H
\e[35mHits       : 36/36    \e[0m\e[23;72H      \e[23;60H\e[35mHits Taken : 0\e[0m\e[25;42H     
\e[25;30H\e[35mStamina    : 10\e[0m\e[24;42H        \e[24;30H\e[35mExperience : 4996  
\e[0m\e[24;72H     \e[24;60H\e[35mMagic Points: 4\e[0m\e[11;1H\e[21;1H ->" to include "Your spellbook explodes!"

Ruby gems to the rescue: turns out there’s an ansi-sys gem that handles the escape codes. With the latest version being published in 2007, I wondered if it would actually work with modern Ruby; and in fact it did not. But I found a more modern fork which did work when I downloaded and installed it.

                              A dog
             ~~. . . . . 
             ~~. v . . . 
             ~~. . . . . 
             ~~. . . A . 
             ~~. . . . . 
      Your spellbook explodes!                                                        
       R                           Hits       : 20/36            Hits Taken : 16   
       L                           Experience : 4996             Magic Points: 4  
                                   Stamina    : 10  

With a small amount of tweaking, not too bad for embedding in blog posts and/or html test results. I’ll have to figure out how to fold it into my test process in a portable way. Tomorrow.

Useful Stuff

More to come
More to come

Day 64 code - tests