docs
[mirrors/Programs.git] / php / term.phps
CommitLineData
84aff5c8
H
1#!/usr/bin/php
2<?php
3/*
4 * Name: term.php
5 * Description: Linux terminal functions for PHP
6 * Author: <-Harvie 2oo7
7 * THX2Root.cz: http://www.root.cz/clanky/barvy-pro-shell/ (see for more help)
8 */
9
10//Font
11function term_font($atr1 = 0, $atr2 = -1) { //Set color of BG/FG and font
12 if($atr2 >= 0) { echo("\033[".trim($atr1).';'.trim($atr2).'m'); }
13 else { echo("\033[".trim($atr1).'m'); }
14}
15//Screen clearing
16function term_cls() { echo("\033[2J"); } //Clear screen
17function term_free_line() { echo("\033[K"); } //Delete line from cursor to end
18//Movement
19function term_return() { echo("\r"); } //Move cursor to 1st col
20function term_tab() { echo("\t"); } //Print TAB
21function term_newline() { echo("\n"); } //Move cursor to next line
22function term_up($n) { echo("\033[".$n.'A'); } //Move cursor $n rows up
23function term_down($n) { echo("\033[".$n.'B'); } //Move cursor $n rows down
24function term_right($n) { echo("\033[".$n.'C'); } //Move cursor $n cols right
25function term_left($n) { echo("\033[".$n.'D'); } //Move cursor $n cols left
26//Position
27function term_pos($row, $col) { echo('\033['.$row.';'.$col.'H'); } //Move cursor at $row and $col
28function term_fpos($row, $col) { echo('\033['.$row.';'.$col.'f'); } //Move cursor at $row and $col
29//Position saving
30function term_pos_save() { echo("\033[s"); } //Save cursor possition (maybe not supported)
31function term_pos_restore() { echo("\033[u"); } //Restore cursor possition (maybe not supported)
32//Info about terminal
33function term_name() { return getenv('TERM'); } //Returns terminal name as string
34function term_color_name() { return getenv('COLORTERM'); } //Returns color terminal name as string
35function term_shell() { return getenv('SHELL'); } //Returns running shell as string
36function term_directory() { return getenv('PWD'); } //Returns working directory as string
37function term_language() { return getenv('LANG'); } //Returns local settings (langue.codepage) as string
38//Showcase
39function term_demo() { //Print demonstration
40 term_font();
41 echo("DEMOnstration of PHPTerm for Unixs' terminals\n".
42 term_name().' - '.term_color_name().' ('.term_shell().
43 ")\n\t\t\t\t<-Harvie 2oo7\n\n");
44 for($i = 0; $i <= 8; $i++) {
45 for($x = 30; $x <= 37; $x++) {
46 term_font($i,$x); echo("A");
47 }
48 term_font();
49 for($y = 40; $y <= 47; $y++) {
50 term_font($y); echo("A");
51 for($x = 30; $x <= 37; $x++) {
52 term_font($i,$x); echo("A");
53 }
54 }
55 term_font();
56 echo("\n");
57 }
58 term_font(); echo("\n");
59}
60
61
62//term_demo();
This page took 0.244942 seconds and 4 git commands to generate.