Commit | Line | Data |
---|---|---|
8de51304 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 | |
11 | function 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 | |
16 | function term_cls() { echo("\033[2J"); } //Clear screen | |
17 | function term_free_line() { echo("\033[K"); } //Delete line from cursor to end | |
18 | //Movement | |
19 | function term_return() { echo("\r"); } //Move cursor to 1st col | |
20 | function term_tab() { echo("\t"); } //Print TAB | |
21 | function term_newline() { echo("\n"); } //Move cursor to next line | |
22 | function term_up($n) { echo("\033[".$n.'A'); } //Move cursor $n rows up | |
23 | function term_down($n) { echo("\033[".$n.'B'); } //Move cursor $n rows down | |
24 | function term_right($n) { echo("\033[".$n.'C'); } //Move cursor $n cols right | |
25 | function term_left($n) { echo("\033[".$n.'D'); } //Move cursor $n cols left | |
26 | //Position | |
27 | function term_pos($row, $col) { echo('\033['.$row.';'.$col.'H'); } //Move cursor at $row and $col | |
28 | function term_fpos($row, $col) { echo('\033['.$row.';'.$col.'f'); } //Move cursor at $row and $col | |
29 | //Position saving | |
30 | function term_pos_save() { echo("\033[s"); } //Save cursor possition (maybe not supported) | |
31 | function term_pos_restore() { echo("\033[u"); } //Restore cursor possition (maybe not supported) | |
32 | //Info about terminal | |
33 | function term_name() { return getenv('TERM'); } //Returns terminal name as string | |
34 | function term_color_name() { return getenv('COLORTERM'); } //Returns color terminal name as string | |
35 | function term_shell() { return getenv('SHELL'); } //Returns running shell as string | |
36 | function term_directory() { return getenv('PWD'); } //Returns working directory as string | |
37 | function term_language() { return getenv('LANG'); } //Returns local settings (langue.codepage) as string | |
38 | //Showcase | |
39 | function 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(); |