Skip to content

Commit

Permalink
Lots of bugfixes, improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
noccy80 committed Dec 15, 2016
1 parent 3223961 commit 0f25104
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 18 deletions.
10 changes: 4 additions & 6 deletions bin/phpl-edit
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ function print_help() {
printf(" -a,--after <name> Insert after specified item\n");
printf(" -s,--set <key>=<val> Configure php-powerline or an item (when with --edit)\n");
printf(" -n,--name <name> Override name\n");
printf(" --class <name> 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");
}

$opts = cmdl_parse("hvi:d:e:a:b:s:t:n:lLE",[
"h" => "help",
"v" => "verbose",
"i" => "insert:",
"d" => "delete:",
"e" => "edit:",
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion bin/phpl-generate
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ function print_help() {
printf("Options: -h,--help Show this help\n");
printf(" -d,--dir <path> Specify working directory\n");
printf(" -s,--status <code> 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:",
]);
Expand All @@ -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')));
Expand Down
5 changes: 5 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions lib/generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
};
Expand Down
2 changes: 1 addition & 1 deletion modules/diskfree.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion modules/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -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", "");
option("class", TEXT_CLASS, "string", "The class to use", "info");
33 changes: 28 additions & 5 deletions themes/default.theme
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
// Defaults, applies to everything
* {
color: bright-white;
background: cyan;
pad-before: 1;
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;
}
Expand All @@ -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;
}


18 changes: 16 additions & 2 deletions themes/gray.theme
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@
pad-before: 1;
pad-after: 1;
}

path {
background: gray;
color: bright-white;
}
}
.vcs {
color: black;
}
.good {
color: gray;
}
.bad {
color: red;
}
.system {
color: gray;
}
.info {
color: gray;
}

0 comments on commit 0f25104

Please sign in to comment.