< Homepage

DM Puzzle - Terminal ASCII Clock

Objective

Build a clock in your terminal that will display the time in ASCII art.

Steps:

  1. Make a script that write the time in your terminal that updates itself every seconds.
  2. Use a module from npm to display the time in some beautiful ASCII art.
  3. Bonus step: center the clock vertically and horizontally.
  4. Bonus Bonus step: do the same thing in ruby!

It should look like this:

How

These docs should be enough to resolve the puzzle.

Prerequisites

Instructions

  1. Use Figlet for the ASCII art part.
  2. Do it quick and dirty. But still, if you can do things clean with a package.json it would be cool.

Expected time to resolution

Less than 1 hour

Expected number of lines

Around 50

Lost?

  • To clear your terminal, you can execute shell commands with the native child_process` module. There is a catch to be sure the command has been executed:

    var spawn = require('child_process').spawn
    
    var clear = function clear(cb) {
      var out = spawn('clear', [], {stdio: 'inherit'})
      out.on('close', cb)
    }
  • To center the time in your terminal, you will need several things: the size of your terminal and the size of the text you display.

    • You can get the size of your terminal from the process.stdout object. Run node -p 'process.stdout' and see what you can use.
    • To get the size of the text, you'll need to split the output of figlet. The module returns a multiline string, which means every lines are separated with \n. If you split the string into an array, you'll get the number of lines and the number of characters per line. Math will be your friend from here.

Definitely lost?

Show solution in NodeJS

Show solution in ruby