From b5625c2bad31625caf9ea0cb203e58b1aee26270 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Sat, 17 Dec 2016 03:40:16 +0100 Subject: [PATCH] Fixed padding bug, true color support --- bin/phpl-reload | 18 +++++++++++++++++- {modules => docs}/MODULES-HOWTO.md | 0 {themes => docs}/THEMES-HOWTO.md | 0 lib/generate.php | 29 ++++++++++++++++++++++++----- 4 files changed, 41 insertions(+), 6 deletions(-) rename {modules => docs}/MODULES-HOWTO.md (100%) rename {themes => docs}/THEMES-HOWTO.md (100%) diff --git a/bin/phpl-reload b/bin/phpl-reload index d77e13b..d368b99 100755 --- a/bin/phpl-reload +++ b/bin/phpl-reload @@ -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; @@ -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]; @@ -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, "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; @@ -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 { @@ -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); } @@ -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; @@ -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; } }