From 0f25104ee0a32b909bbe732b544c1a9505338c03 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Fri, 16 Dec 2016 00:03:48 +0100 Subject: [PATCH] Lots of bugfixes, improvements --- bin/phpl-edit | 10 ++++------ bin/phpl-generate | 5 ++++- install.sh | 5 +++++ lib/generate.php | 9 +++++++-- modules/diskfree.php | 2 +- modules/text.php | 2 +- themes/default.theme | 33 ++++++++++++++++++++++++++++----- themes/gray.theme | 18 ++++++++++++++++-- 8 files changed, 66 insertions(+), 18 deletions(-) diff --git a/bin/phpl-edit b/bin/phpl-edit index 0e94ac0..eed4106 100755 --- a/bin/phpl-edit +++ b/bin/phpl-edit @@ -22,9 +22,7 @@ function print_help() { printf(" -a,--after Insert after specified item\n"); printf(" -s,--set = Configure php-powerline or an item (when with --edit)\n"); printf(" -n,--name Override name\n"); - printf(" --class Use theme class name for displaying item\n"); printf(" -n,--no-reload Don't reload the prompt after edit\n"); - printf(" -v[vv],--verbose Be verbose\n"); printf("\n"); printf("Examples: -igit -stag=true -sbranch=true -bstatus\n"); printf(" Add the git module to the prompt, include tag and branch, place before status\n"); @@ -32,7 +30,6 @@ function print_help() { $opts = cmdl_parse("hvi:d:e:a:b:s:t:n:lLE",[ "h" => "help", - "v" => "verbose", "i" => "insert:", "d" => "delete:", "e" => "edit:", @@ -56,6 +53,7 @@ if (cmdl_get($opts,'help')) { define("VERBOSE", (int)cmdl_get($opts,'verbose')); define("RELOAD", !cmdl_get($opts,'no-reload')); +define("QUIET", false); define("WORKING_DIR", cmdl_get($opts,'dir')?:getcwd()); define("LAST_STATUS", 0); @@ -80,13 +78,13 @@ if (cmdl_get($opts,'list')) { foreach ($item[2] as $k=>$v) { $attrs[] = sprintf("%s=%s", $k, $v); } - $attr = join("\n ",$attrs); - printf(" %-10s name:%-10s [%s]\n %s\n", $item[0], $item[1], demo($item), $attr); + $attr = join(" ",$attrs); + printf(" \e[1m%-15s\e[0m %-15s [\e[37;44m%s\e[0m]\n %s\n", $item[0], $item[1], demo($item), $attr); } } elseif (cmdl_get($opts,'list-modules')) { printf("Available modules:\n"); foreach ($_MODULES as $module) { - printf(" - %s: %s\n", $module->name, $module->info); + printf(" - \e[1m%s\e[0m: %s\n", $module->name, $module->info); foreach ($module->opts as $opt) { printf(" + <%s>%s - %s (default:%s)\n", $opt->type, $opt->name, $opt->descr, $opt->def); } diff --git a/bin/phpl-generate b/bin/phpl-generate index 280f68d..3e812e7 100755 --- a/bin/phpl-generate +++ b/bin/phpl-generate @@ -10,11 +10,13 @@ function print_help() { printf("Options: -h,--help Show this help\n"); printf(" -d,--dir Specify working directory\n"); printf(" -s,--status Status of last command\n"); + printf(" -r,--raw Don't escape ansi for PS1\n"); printf("\n"); } -$opts = cmdl_parse("hd:s:",[ +$opts = cmdl_parse("hd:s:r",[ "h" => "help", + "r" => "raw", "d" => "dir:", "s" => "status:", ]); @@ -23,6 +25,7 @@ if (cmdl_get($opts,'help')) { print_help(); exit(0); } +define("PROMPT_RAW", (cmdl_get($opts,'raw'))); define("WORKING_DIR", cmdl_get($opts,'dir')?:getcwd()); define("LAST_STATUS", max(0,(int)cmdl_get($opts,'status'))); diff --git a/install.sh b/install.sh index 9b2eb46..9442acd 100755 --- a/install.sh +++ b/install.sh @@ -2,6 +2,11 @@ INSTALL_DIR=~/.powerline +if [ -z "$(which php)" ]; then + echo "Error: PHP not found. Please install php-cli and try again." + exit 1 +fi + if [ ! -d $INSTALL_DIR ]; then echo "Creating directory: $INSTALL_DIR" mkdir -p $INSTALL_DIR diff --git a/lib/generate.php b/lib/generate.php index e8aac39..f6bf6bc 100644 --- a/lib/generate.php +++ b/lib/generate.php @@ -186,8 +186,13 @@ function style($fg=NONE,$bg=NONE,$attr=NONE) { if ($attr>0) { if (($attr & BOLD) == BOLD) $sgr[] = "1"; } - $pre = (count($sgr)>0)?"\[\e[".join(";",$sgr)."m\]":""; - $post = (count($sgr)>0)?"\[\e[0m\]":""; + if (defined('PROMPT_RAW') && PROMPT_RAW) { + $pre = (count($sgr)>0)?"\e[".join(";",$sgr)."m":""; + $post = (count($sgr)>0)?"\e[0m":""; + } else { + $pre = (count($sgr)>0)?"\[\e[".join(";",$sgr)."m\]":""; + $post = (count($sgr)>0)?"\[\e[0m\]":""; + } return function ($text) use ($pre,$post) { return "{$pre}{$text}{$post}"; }; diff --git a/modules/diskfree.php b/modules/diskfree.php index 5265e41..7f5cdca 100644 --- a/modules/diskfree.php +++ b/modules/diskfree.php @@ -8,7 +8,7 @@ function _diskfree(array $opts=[]) { $total = disk_total_space(WORKING_DIR); $pc = (100/$total)*$free; - $class = ($pc<5)?'low':'good'; + $class = ($pc<5)?'bad':'good'; $units = [ "B", "KB", "MB", "GB" ]; do { diff --git a/modules/text.php b/modules/text.php index 23974d0..b1db164 100644 --- a/modules/text.php +++ b/modules/text.php @@ -10,4 +10,4 @@ function _text(array $opts) { } module("text", "Show a text"); option("text", TEXT_TEXT, "string", "The text to dispaly", "Text"); -option("class", TEXT_CLASS, "string", "The class to use", ""); \ No newline at end of file +option("class", TEXT_CLASS, "string", "The class to use", "info"); \ No newline at end of file diff --git a/themes/default.theme b/themes/default.theme index 4224edd..0861179 100644 --- a/themes/default.theme +++ b/themes/default.theme @@ -1,3 +1,4 @@ +// Defaults, applies to everything * { color: bright-white; background: cyan; @@ -5,23 +6,29 @@ pad-after: 1; } +// Style the path panel path { background: cyan; } +// Style the loadavg panel loadavg { color: bright-yellow; background: gray; } -.vcs { - background: blue; -} - -.system { +// Style the diskfree panel, with health indicator +diskfree { background: gray; } +diskfree.good { + color: green; +} +diskfree.bad { + color: bright-red; +} +// Style the status panel, with health indicator status { color: bright-white; } @@ -32,3 +39,19 @@ status.bad { background: red; } +// This is the default class for vcs modules like git, svn, hg, .. +.vcs { + background: blue; +} + +// This is the default class for system information (if not good or bad) +.system { + background: gray; +} + +// This is the default class for informatin items (text, time, etc) +.info { + background: gray; +} + + diff --git a/themes/gray.theme b/themes/gray.theme index 0186b99..c4ee5ce 100644 --- a/themes/gray.theme +++ b/themes/gray.theme @@ -4,8 +4,22 @@ pad-before: 1; pad-after: 1; } - path { background: gray; color: bright-white; -} \ No newline at end of file +} +.vcs { + color: black; +} +.good { + color: gray; +} +.bad { + color: red; +} +.system { + color: gray; +} +.info { + color: gray; +}