-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdout.php
More file actions
130 lines (105 loc) · 2.65 KB
/
stdout.php
File metadata and controls
130 lines (105 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
class stdOut
{
//--------------------------------------------------------------------------
private $style_vars = array(
'reset' => 0,
'bold' => 1,
'underline' => 4,
'blink' => 5,
'reverse' => 7,
'concealed' => 8,
'bg_black' => 40,
'bg_red' => 41,
'bg_green' => 42,
'bg_yellow' => 43,
'bg_blue' => 44,
'bg_magenta' => 45,
'bg_cyan' => 46,
'bg_white' => 47,
'black' => 30,
'red' => 31,
'green' => 32,
'yellow' => 33,
'blue' => 34,
'magenta' => 35,
'cyan' => 36,
'white' => 37,
);
private $_def_str = array(
'hr' => "--------------------------------------------------------------------------\n",
'br' => "\n",
);
//--------------------------------------------------------------------------
public function _print($msg)
{
fputs(STDOUT, $msg);
}
//--------------------------------------------------------------------------
public function &clear()
{
$this->_print(`clear`);
return $this;
}
//--------------------------------------------------------------------------
public function &reset()
{
$this->style();
return $this;
}
//--------------------------------------------------------------------------
public function &style($style = 'reset')
{
$this->_print("\33[K\33[" . str_replace(array_keys($this->style_vars), $this->style_vars, $style) . "m");
return $this;
}
//--------------------------------------------------------------------------
public function &pos($left = 0, $top = 0)
{
$this->_print("\33[" . $left . ';' . $top . "H");
return $this;
}
//--------------------------------------------------------------------------
public function &put($message, $style = FALSE)
{
if ($style) $this->style($style);
$this->_print($message);
$this->reset();
return $this;
}
//--------------------------------------------------------------------------
public function &pad($message, $chars = 0)
{
$this->_print( str_pad($message, $chars));
$this->reset();
return $this;
}
//--------------------------------------------------------------------------
public function &color($color)
{
$this->style($color);
return $this;
}
//--------------------------------------------------------------------------
public function &__call($method, $args)
{
if (isset($this->_def_str[$method]))
{
$this->_print($this->_def_str[$method]);
}
elseif (isset($this->style_vars[$method]))
{
if (isset($args[0]))
{
$this->put($args[0], $method);
$this->reset();
}
else
{
$this->style($method);
}
}
return $this;
}
//--------------------------------------------------------------------------
}