Skip to content

Instantly share code, notes, and snippets.

@thekid
Created June 19, 2016 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thekid/d1a38a0743733d2270968d7eac8f43c9 to your computer and use it in GitHub Desktop.
Save thekid/d1a38a0743733d2270968d7eac8f43c9 to your computer and use it in GitHub Desktop.
A clock using xp-forge/terminal
<?php namespace clock;
use util\cmd\Console;
use util\cmd\term\Terminal;
use lang\Runtime;
use lang\Runnable;
use Packaged\Figlet\Figlet;
$figlet= new Figlet(isset($argv[1]) ? $argv[1] : null);
$time= explode("\n", $figlet->render(date('H:i')));
$dim= Terminal::size();
$width= strlen($time[0]);
$height= sizeof($time);
// dim(W,H) -> pos(X,Y)
$clock= [($dim[0] - $width) / 2, ($dim[1] - $height) / 2];
$progress= [($dim[0] - 60) / 2, $clock[1] + $height + 1];
do {
Terminal::clear('white@dark-blue');
Terminal::write($clock[0], $clock[1], $time);
Terminal::write($progress[0], $progress[1], '<black>'.str_repeat('#', 59).'</>');
Terminal::styled('white', function() use($progress) {
for ($i= idate('s'); $i < 60; $i++) {
Terminal::write($progress[0] + $i, $progress[1], '#');
sleep(1);
}
});
$time= explode("\n", $figlet->render(date('H:i')));
} while (true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment