Skip to content

Commit

Permalink
More modules, theme improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
noccy80 committed Dec 15, 2016
1 parent 0f25104 commit 3beb2b7
Show file tree
Hide file tree
Showing 14 changed files with 772 additions and 18 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions bin/phpl-reload
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ function reload_theme() {
} elseif (preg_match("/\\\$set\((.+?),(.+?)\)/", $line, $match)) {
$vars[$match[1]] = $match[2];
} elseif (strpos($line,'{')!==false) {
$rule = trim($line,'{ ');
$rules[$rule] = [];
$rule = explode(' ',trim($line,'{ '));
foreach ($rule as $r) {
$rules[$r] = [];
}
} elseif ($line == '}') {
$rule = null;
} else {
Expand All @@ -136,7 +138,9 @@ function reload_theme() {
if ($val[0]=='"') { $val = trim($val,'"'); }
elseif ($val[0]=="'") { $val = trim($val,"'"); }
elseif ($val[0]=="%") { $val = $vars[substr($val,1)]; }
$rules[$rule][$k] = $val;
foreach ($rule as $r) {
$rules[$r][$k] = $val;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function demo($item) {
foreach ($attr as $k=>$v) {
if (array_key_exists($k,$type)) {
switch ($type[$k]) {
case 'bool':
case 'boolean':
$attr[$k] = (bool)$v;
break;
case 'int':
Expand Down
5 changes: 3 additions & 2 deletions lib/generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ public function __construct(array $rules) {
$this->rules = $rules;
}
public function __invoke(Panel $panel) {
$applied = [];
$applied = ['background'=>'none','color'=>'none'];
foreach ($this->rules as $rule=>$apply) {
if ($rule=='*') {
$applied = array_merge($applied, $apply);
continue;
}
$class = $panel->get('class');
$status = $panel->get('status');
$type = $panel->type();
if (preg_match('/^('.$type.'){0,1}(\.'.$class.'){0,1}$/', $rule)) {
if (preg_match('/^('.$type.'){0,1}(\.'.$class.'){0,1}(\:'.$status.'){0,1}$/', $rule)) {
$applied = array_merge($applied, $apply);
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions modules/diskfree.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ function _diskfree(array $opts=[]) {
$total = disk_total_space(WORKING_DIR);
$pc = (100/$total)*$free;

$class = ($pc<5)?'bad':'good';
$status = ($pc<5)?'bad':'good';

$units = [ "B", "KB", "MB", "GB" ];
do {
$unit = array_shift($units);
if (($free < 1024) || (count($units)==0)) {
$icon = ""; // 

return panel(sprintf("{$icon} %.1f%s", $free, $unit), [ 'class'=>$class ], 'diskfree' );
return panel(sprintf("{$icon} %.1f%s", $free, $unit), [ 'class'=>'system', 'status'=>$status ], 'diskfree' );
}
$free /= 1024;
} while (true);
Expand Down
14 changes: 14 additions & 0 deletions modules/ip.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

define("IP_INTERFACE", "interface");

function _ip(array $opts) {
$ip = exec("ifconfig {$opts['interface']} | awk '/inet addr/{print substr($2,6)}'");
$attr = [
'class' => 'network',
'status' => (!!$ip)?'up':'down'
];
return panel($ip, $attr, 'ip');
}
module("ip", "Show the IP of a network device");
option("interface", IP_INTERFACE, "string", "The interface to dispaly", "eth0");
2 changes: 1 addition & 1 deletion modules/status.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function _status(array $opts=[]) {
$character = (posix_getuid()==0)?$opts[STATUS_CHARACTER_ROOT]:$opts[STATUS_CHARACTER];
$style = (LAST_STATUS)?$opts[STATUS_STYLE_BAD]:$opts[STATUS_STYLE_GOOD];

return panel( $character, [ 'class' => ((LAST_STATUS>0)?'bad':'good') ], 'status' );
return panel( $character, [ 'class'=>'shell', 'status' => ((LAST_STATUS>0)?'bad':'good') ], 'status' );
}

module("status", "Command status and root indicator");
22 changes: 22 additions & 0 deletions modules/time.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

define("TIME_FORMAT", "format");
define("TIME_CLASS", "class");
define("TIME_ANALOG", "analog");

function _time(array $opts) {
$attr = [];
if ($opts[TIME_ANALOG]) {
$analog = [ '🕛','🕧','🕐','🕜','🕑','🕝','🕒','🕞','🕓','🕟','🕔','🕠','🕕','🕡','🕖','🕢','🕗','🕣','🕘','🕤','🕙','🕥','🕚','🕦' ];
$hour = (int)date('h'); $minute = (int)date('i'); $ti = $hour * 2 + ($minute>30?1:0);
$time = $analog[$ti%24]." ";
} else {
$time = null;
}
if ($opts[TIME_CLASS]) $attr['class'] = $opts[TIME_CLASS];
return panel($time.@date($opts['format']), $attr, 'time');
}
module("time", "Show the current time and/or date");
option("format", TIME_FORMAT, OPT_TYPE_STRING, "The time format", "H:i");
option("class", TIME_CLASS, OPT_TYPE_STRING, "The class to use", "info");
option("analog", TIME_ANALOG, OPT_TYPE_BOOL, "Show an analog watch", false);
3 changes: 3 additions & 0 deletions themes/THEMES-HOWTO.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ Themes HowTo
Y - any item of type Y
Y:Z - any item of type Y with status Z
Y.X - any item of type Y with class X
.X:Z - any of class X with status Z
...

Examples:

.vcs // Any item having class 'vcs'
git.vcs // A git panel having the class 'vcs'
status:good // Status ($) when all went ok
status:bad // Status ($) when someting failed
:good // Everything that is good


## Attributes
Expand Down
15 changes: 15 additions & 0 deletions themes/blues.theme
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
* {
background: blue;
color: white;
pad-before: 1;
pad-after: 1;
}

vcs {
background: bright-blue;
}

.system .info {
background: bright-blue;
color: bright-white;
}
8 changes: 4 additions & 4 deletions themes/default.theme
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ loadavg {
diskfree {
background: gray;
}
diskfree.good {
diskfree:good {
color: green;
}
diskfree.bad {
diskfree:bad {
color: bright-red;
}

// Style the status panel, with health indicator
status {
color: bright-white;
}
status.good {
status:good {
background: green;
}
status.bad {
status:bad {
background: red;
}

Expand Down
4 changes: 2 additions & 2 deletions themes/gray.theme
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ path {
.vcs {
color: black;
}
.good {
:good {
color: gray;
}
.bad {
:bad {
color: red;
}
.system {
Expand Down
11 changes: 11 additions & 0 deletions themes/mono.theme
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,14 @@
pad-before: 1;
pad-after: 1;
}

.system {
color: bright-white;
}
.info {
color: white;
}
status:bad {
color: black;
background: white;
}
16 changes: 13 additions & 3 deletions themes/solarized.theme
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,26 @@ path {
}

loadavg {
background: %base01;
background: %base02;
color: %base2;
}

.vcs {
background: %base01;
color: %base1;
}

.sys {
.system {
background: %base01;
color: %base2
}
.info {
background: %base02;
color: %base2
}
status {
background: %base03;
}

status:bad {
color: %red;
}

0 comments on commit 3beb2b7

Please sign in to comment.