diff options
author | Shav Kinderlehrer <[email protected]> | 2023-08-09 15:05:26 -0400 |
---|---|---|
committer | Shav Kinderlehrer <[email protected]> | 2023-08-09 15:05:26 -0400 |
commit | 24c94e510ab9c016542b287e060c992c195d7987 (patch) | |
tree | b7cd353d3bf4a6a4220fde5c4b6a878c97c23022 /source | |
parent | dd5c94c3174cc0fee0cbae4b51d47589894d0e5d (diff) | |
download | prim-24c94e510ab9c016542b287e060c992c195d7987.tar.gz prim-24c94e510ab9c016542b287e060c992c195d7987.zip |
Start add basic prompt
Diffstat (limited to 'source')
-rw-r--r-- | source/app.d | 24 | ||||
-rw-r--r-- | source/comp/hr.d | 11 | ||||
-rw-r--r-- | source/prompt/preexec.d | 7 | ||||
-rw-r--r-- | source/prompt/ps1.d | 9 | ||||
-rw-r--r-- | source/style/color.d | 20 |
5 files changed, 58 insertions, 13 deletions
diff --git a/source/app.d b/source/app.d index 25bb8e9..ca934fa 100644 --- a/source/app.d +++ b/source/app.d @@ -2,20 +2,18 @@ import std.stdio; import std.getopt; import prompt.ps1; +import prompt.preexec; +import style.color; struct Opt { bool ps1; bool rps1; + bool preexec; int col; int row; } -void validate(Opt opts) { - if (!opts.col || !opts.row) - throw new Exception("--col and --row required"); -} - void main(string[] argv) { Opt opts; @@ -24,7 +22,11 @@ void main(string[] argv) { std.getopt.config.bundling, "ps1|p", "print PS1", &opts.ps1, "rps1|r", "print RPS1", &opts.rps1, + "preexec|x", "print preexec", &opts.preexec, + + std.getopt.config.required, "col", "terminal width", &opts.col, + std.getopt.config.required, "row", "terminal height", &opts.row, ); @@ -32,11 +34,13 @@ void main(string[] argv) { defaultGetoptPrinter("prim", args.options); } - try { - validate(opts); - } catch (Exception e) { - defaultGetoptPrinter(e.msg ~ "\n", args.options); + if (opts.ps1) { + ps1(opts.col).setColor(Color.black).write(); + } + + if (opts.preexec) { + preexec(opts.col).setColor(Color.black).write(); } - ps1(opts.col).write(); + write(setColor("", Color.reset)); } diff --git a/source/comp/hr.d b/source/comp/hr.d new file mode 100644 index 0000000..fa4d32b --- /dev/null +++ b/source/comp/hr.d @@ -0,0 +1,11 @@ +module comp.hr; + +string hr(int col) { + string ps; + + foreach (i; 0 .. col) { + ps ~= '—'; + } + + return ps; +} diff --git a/source/prompt/preexec.d b/source/prompt/preexec.d new file mode 100644 index 0000000..eb2d365 --- /dev/null +++ b/source/prompt/preexec.d @@ -0,0 +1,7 @@ +module prompt.preexec; + +import comp.hr; + +string preexec(int col) { + return hr(col); +} diff --git a/source/prompt/ps1.d b/source/prompt/ps1.d index 338afe8..9bf8021 100644 --- a/source/prompt/ps1.d +++ b/source/prompt/ps1.d @@ -1,11 +1,14 @@ module prompt.ps1; +import comp.hr; +import style.color; + string ps1(int col) { string ps; - foreach (i; 0 .. col) { - ps ~= '—'; - } + ps ~= hr(col); + + ps ~= "> ".setColor(Color.magenta); return ps; } diff --git a/source/style/color.d b/source/style/color.d new file mode 100644 index 0000000..3d788b8 --- /dev/null +++ b/source/style/color.d @@ -0,0 +1,20 @@ +module style.color; + +import std.conv; + +enum Color { + black = 30, + red, + green, + yellow, + blue, + magenta, + cyan, + white, + def, + reset = 0 +} + +string setColor(string s, int code) { + return "%{\x1b[" ~ to!string(code) ~ "m%}" ~ s; +} |