Add getopt
This commit is contained in:
parent
dfb28899ad
commit
dd5c94c317
8
hook.zsh
Normal file
8
hook.zsh
Normal file
@ -0,0 +1,8 @@
|
||||
setopt promptsubst
|
||||
|
||||
prompt_precmd() {
|
||||
export PS1=`prim --ps1 --col $COLUMNS --row $LINES`
|
||||
export RPS1=`prim --rps1 --col $COLUMNS --row $LINES`
|
||||
}
|
||||
|
||||
add-zsh-hook precmd prompt_precmd
|
42
source/app.d
42
source/app.d
@ -1,6 +1,42 @@
|
||||
import std.stdio;
|
||||
import std.getopt;
|
||||
|
||||
void main()
|
||||
{
|
||||
writeln("Edit source/app.d to start your project.");
|
||||
import prompt.ps1;
|
||||
|
||||
struct Opt {
|
||||
bool ps1;
|
||||
bool rps1;
|
||||
|
||||
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;
|
||||
|
||||
GetoptResult args = getopt(
|
||||
argv,
|
||||
std.getopt.config.bundling,
|
||||
"ps1|p", "print PS1", &opts.ps1,
|
||||
"rps1|r", "print RPS1", &opts.rps1,
|
||||
"col", "terminal width", &opts.col,
|
||||
"row", "terminal height", &opts.row,
|
||||
);
|
||||
|
||||
if (args.helpWanted) {
|
||||
defaultGetoptPrinter("prim", args.options);
|
||||
}
|
||||
|
||||
try {
|
||||
validate(opts);
|
||||
} catch (Exception e) {
|
||||
defaultGetoptPrinter(e.msg ~ "\n", args.options);
|
||||
}
|
||||
|
||||
ps1(opts.col).write();
|
||||
}
|
||||
|
11
source/prompt/ps1.d
Normal file
11
source/prompt/ps1.d
Normal file
@ -0,0 +1,11 @@
|
||||
module prompt.ps1;
|
||||
|
||||
string ps1(int col) {
|
||||
string ps;
|
||||
|
||||
foreach (i; 0 .. col) {
|
||||
ps ~= '—';
|
||||
}
|
||||
|
||||
return ps;
|
||||
}
|
Loading…
Reference in New Issue
Block a user