Skip to content

Commit

Permalink
Fixed padding bug, true color support
Browse files Browse the repository at this point in the history
  • Loading branch information
noccy80 committed Dec 17, 2016
1 parent becc840 commit b5625c2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
18 changes: 17 additions & 1 deletion bin/phpl-reload
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ function reload_theme() {
$vars = [];
$rules = [];
$rule = null;

$pragma_256color = false;
$pragma_truecolor = false;

foreach ($data as $line) {
if (substr($line,0,2)=="//") {
continue;
Expand All @@ -118,6 +121,11 @@ function reload_theme() {
case '256color':
$pragma_256color = true;
break;
case 'truecolor':
$pragma_truecolor = true;
break;
default:
printf("Warning: Unrecognized pragma %s\n", $match[1]);
}
} elseif (preg_match("/\\\$set\((.+?),(.+?)\)/", $line, $match)) {
$vars[$match[1]] = $match[2];
Expand All @@ -144,9 +152,17 @@ function reload_theme() {
}
}

if ($pragma_truecolor) {
$head = 'define("PRAGMA_TRUECOLOR", true);';
} elseif ($pragma_256color) {
$head = 'define("PRAGMA_256COLOR", true);';
} else {
$head = null;
}

$style = '$_THEME = new Theme('.var_export($rules,true).');';

file_put_contents(PHPL_CACHE_THEME, "<?php {$style}");
file_put_contents(PHPL_CACHE_THEME, "<?php {$head} {$style}");

}

Expand Down
File renamed without changes.
File renamed without changes.
29 changes: 24 additions & 5 deletions lib/generate.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php
/*
* This file is used to support the generation of prompts. It provides the main
* functions used for theming etc.
*
*
**************************************************************************************/

class Panel {
private $text;
Expand All @@ -17,14 +23,14 @@ public function __toString() {
$text = $this->text;
if (!$text) return "";
if (($before = $this->attr['before'])) {
if (is_int($before)) {
if (is_numeric($before)) {
$text = str_repeat(" ",$before).$text;
} else {
$text = $before.$text;
}
}
if (($after = $this->attr['after'])) {
if (is_int($after)) {
if (is_numeric($after)) {
$text = $text.str_repeat(" ",$after);
} else {
$text = $text.$after;
Expand All @@ -47,7 +53,13 @@ public function type() {
}

class Style {

const BOLD = 0x01;
const ITALIC = 0x02;
const UNDERLINE = 0x04;
const REVERSE = 0x08;
protected $color;
protected $background;
protected $style;
}

class Theme {
Expand All @@ -71,6 +83,9 @@ public function __invoke(Panel $panel) {
}
}
extract($applied, EXTR_PREFIX_ALL, "attr");
if (array_key_exists('pad-before', $applied)) $panel->set('before', $applied['pad-before']);
if (array_key_exists('pad-after', $applied)) $panel->set('after', $applied['pad-after']);

$fg = color($attr_color); $bg = color($attr_background);
return style($fg,$bg);
}
Expand Down Expand Up @@ -124,6 +139,7 @@ function generate(...$items) {
function color($string) {
if (is_int($string)) return $string;
switch ($string) {
case null:
case 'none': return NONE;
case 'black': return BLACK;
case 'red': return RED;
Expand All @@ -146,8 +162,11 @@ function color($string) {
$r = hexdec(substr($string,1,2));
$g = hexdec(substr($string,3,2));
$b = hexdec(substr($string,5,2));
//$a = COLOR256 + 16 + 36*floor($r/42) + 6*floor($g/42) + floor($b/42);
$a = [$r,$g,$b];
if (defined("PRAGMA_TRUECOLOR")) {
$a = [$r,$g,$b];
} else {
$a = COLOR256 + 16 + 36*floor($r/42) + 6*floor($g/42) + floor($b/42);
}
return $a;
}
}
Expand Down

0 comments on commit b5625c2

Please sign in to comment.