summaryrefslogtreecommitdiff
path: root/source/app.d
blob: 68bf1147d8a935a55a5b4ddfbc02cc56e9227e53 (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
53
54
55
56
57
58
59
60
61
62
import std.stdio;
import std.getopt;

import prim.opt;

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

import style;
import style.color;

Opts defaultOpts() {
  Opts opts;

  opts.pathlen = 3;

  return opts;
}

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

  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,

    "pathlen", "set length of displayed path", &opts.pathlen,
  );

  if (args.helpWanted) {
    defaultGetoptPrinter("prim", args.options);
  }

  dorun(opts);
}

void dorun(Opts opts) {
  if (opts.ps1) {
    ps1(opts).write();
  }

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

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