summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShav Kinderlehrer <[email protected]>2023-08-09 16:01:15 -0400
committerShav Kinderlehrer <[email protected]>2023-08-09 16:01:15 -0400
commit85f830ce4730da0489bc14d8726de7fb2dd0fc38 (patch)
tree811707c736ce7098b5655f018219c5093518f0a0
parent24c94e510ab9c016542b287e060c992c195d7987 (diff)
downloadprim-85f830ce4730da0489bc14d8726de7fb2dd0fc38.tar.gz
prim-85f830ce4730da0489bc14d8726de7fb2dd0fc38.zip
Add styles
-rw-r--r--hook.zsh6
-rwxr-xr-xprimbin1381217 -> 1384817 bytes
-rw-r--r--source/app.d32
-rw-r--r--source/opt.d12
-rw-r--r--source/prompt/preexec.d5
-rw-r--r--source/prompt/ps1.d17
-rw-r--r--source/prompt/rps1.d19
-rw-r--r--source/style/color.d28
-rw-r--r--source/style/font.d12
-rw-r--r--source/style/package.d9
10 files changed, 116 insertions, 24 deletions
diff --git a/hook.zsh b/hook.zsh
index 999b689..31aa142 100644
--- a/hook.zsh
+++ b/hook.zsh
@@ -1,12 +1,12 @@
setopt promptsubst
prompt_precmd() {
- export PS1=`prim --ps1 --col $COLUMNS --row $LINES`
- export RPS1=`prim --rps1 --col $COLUMNS --row $LINES`
+ export PS1=`prim --ps1 --col $COLUMNS --row $LINES --status $?`
+ export RPS1=`prim --rps1 --col $COLUMNS --row $LINES --status $?`
}
prompt_preexec() {
- print -P `prim --preexec --col $COLUMNS --row $LINES`
+ print -P `prim --preexec --col $COLUMNS --row $LINES --status $?`
}
add-zsh-hook precmd prompt_precmd
diff --git a/prim b/prim
index 9fbb91d..9d75862 100755
--- a/prim
+++ b/prim
Binary files differ
diff --git a/source/app.d b/source/app.d
index ca934fa..d1b18b9 100644
--- a/source/app.d
+++ b/source/app.d
@@ -1,21 +1,17 @@
import std.stdio;
import std.getopt;
+import prim.opt;
+
import prompt.ps1;
+import prompt.rps1;
import prompt.preexec;
-import style.color;
-
-struct Opt {
- bool ps1;
- bool rps1;
- bool preexec;
- int col;
- int row;
-}
+import style;
+import style.color;
void main(string[] argv) {
- Opt opts;
+ Opts opts;
GetoptResult args = getopt(
argv,
@@ -26,21 +22,31 @@ void main(string[] argv) {
std.getopt.config.required,
"col", "terminal width", &opts.col,
+
std.getopt.config.required,
"row", "terminal height", &opts.row,
+
+ std.getopt.config.required,
+ "status", "previous command exit code", &opts.status,
);
if (args.helpWanted) {
defaultGetoptPrinter("prim", args.options);
}
+ dorun(opts);
+}
+
+void dorun(Opts opts) {
if (opts.ps1) {
- ps1(opts.col).setColor(Color.black).write();
+ ps1(opts).write();
}
if (opts.preexec) {
- preexec(opts.col).setColor(Color.black).write();
+ preexec(opts.col).write();
}
- write(setColor("", Color.reset));
+ if (opts.rps1) {
+ rps1(opts).write();
+ }
}
diff --git a/source/opt.d b/source/opt.d
new file mode 100644
index 0000000..1236ac9
--- /dev/null
+++ b/source/opt.d
@@ -0,0 +1,12 @@
+module prim.opt;
+
+struct Opts {
+ bool ps1;
+ bool rps1;
+ bool preexec;
+
+ int col;
+ int row;
+
+ int status;
+}
diff --git a/source/prompt/preexec.d b/source/prompt/preexec.d
index eb2d365..3904a2b 100644
--- a/source/prompt/preexec.d
+++ b/source/prompt/preexec.d
@@ -2,6 +2,9 @@ module prompt.preexec;
import comp.hr;
+import style;
+import style.color;
+
string preexec(int col) {
- return hr(col);
+ return hr(col).set(Color.black);
}
diff --git a/source/prompt/ps1.d b/source/prompt/ps1.d
index 9bf8021..5b8bafa 100644
--- a/source/prompt/ps1.d
+++ b/source/prompt/ps1.d
@@ -1,14 +1,25 @@
module prompt.ps1;
+import std.conv;
+
+import prim.opt;
import comp.hr;
+
+import style;
import style.color;
+import style.font;
-string ps1(int col) {
+string ps1(Opts opt) {
string ps;
- ps ~= hr(col);
+ // divider
+ ps ~= hr(opt.col).set(Color.black);
+
+ // previous command status
+ ps ~= ("(" ~ to!string(opt.status) ~ ") ").set(Color.black);
- ps ~= "> ".setColor(Color.magenta);
+ // prompt char
+ ps ~= "|> ".set(Font.bold).set(opt.status == 0 ? Color.green : Color.red);
return ps;
}
diff --git a/source/prompt/rps1.d b/source/prompt/rps1.d
new file mode 100644
index 0000000..5ee5d2c
--- /dev/null
+++ b/source/prompt/rps1.d
@@ -0,0 +1,19 @@
+module prompt.rps1;
+
+import std.conv;
+
+import prim.opt;
+
+import style;
+import style.color;
+import style.font;
+
+string rps1(Opts opt) {
+ string ps;
+
+ // previous command status
+ ps ~= ("(" ~ to!string(opt.status) ~ ") ").set(Color.black);
+
+ return ps;
+}
+
diff --git a/source/style/color.d b/source/style/color.d
index 3d788b8..8576e56 100644
--- a/source/style/color.d
+++ b/source/style/color.d
@@ -1,7 +1,5 @@
module style.color;
-import std.conv;
-
enum Color {
black = 30,
red,
@@ -15,6 +13,28 @@ enum Color {
reset = 0
}
-string setColor(string s, int code) {
- return "%{\x1b[" ~ to!string(code) ~ "m%}" ~ s;
+enum Bright {
+ black = 90,
+ red,
+ green,
+ yellow,
+ blue,
+ magenta,
+ cyan,
+ white,
+ def,
+ reset = 0
+}
+
+enum Bg {
+ black = 40,
+ red,
+ green,
+ yellow,
+ blue,
+ magenta,
+ cyan,
+ white,
+ def,
+ reset = 0
}
diff --git a/source/style/font.d b/source/style/font.d
new file mode 100644
index 0000000..ae605b9
--- /dev/null
+++ b/source/style/font.d
@@ -0,0 +1,12 @@
+module style.font;
+
+enum Font {
+ bold = 1,
+ dim,
+ italic,
+ underline,
+ blinking,
+ hidden,
+ strikethrough,
+ reset = 0
+}
diff --git a/source/style/package.d b/source/style/package.d
new file mode 100644
index 0000000..76aa044
--- /dev/null
+++ b/source/style/package.d
@@ -0,0 +1,9 @@
+module style;
+
+import std.conv;
+
+import style.color;
+
+string set(string s, int code) {
+ return ("%{\x1b[" ~ to!string(code) ~ "m%}") ~ s ~ ("%{\x1b[0m%}");
+}