Skip to content

Instantly share code, notes, and snippets.

@gajus
Created June 16, 2015 16:57
Show Gist options
  • Select an option

  • Save gajus/2f2d7cb9c674a8b8e86c to your computer and use it in GitHub Desktop.

Select an option

Save gajus/2f2d7cb9c674a8b8e86c to your computer and use it in GitHub Desktop.
Erase the scrollback history.
/**
* Erase the scrollback history.
*/
function clearScrollback () {
if (php_sapi_name() !== 'cli') {
throw new Exception('Use of function in invalid interface context.');
}
$term_program = getenv('TERM_PROGRAM');
// https://en.wikipedia.org/wiki/Terminal_(OS_X)
if (strpos($term_program, 'Apple_Terminal') === 0) {
echo chr(27) . '[3J';
// https://en.wikipedia.org/wiki/ITerm2
} else if (strpos($term_program, 'iTerm') === 0) {
echo chr(27) . ']50;ClearScrollback' . chr(7);
} else {
throw new Exception('Unknown Termimanl program.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment