summaryrefslogtreecommitdiff
path: root/source/app.d
blob: d1b18b9e758a7158ffbea6d7e264a31ce3c9123d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import std.stdio;
import std.getopt;

import prim.opt;

import prompt.ps1;
import prompt.rps1;
import prompt.preexec;

import style;
import style.color;

void main(string[] argv) {
  Opts opts;

  GetoptResult args = getopt(
    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,

    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).write();
  }

  if (opts.preexec) {
    preexec(opts.col).write();
  }

  if (opts.rps1) {
    rps1(opts).write();
  }
}