summaryrefslogtreecommitdiff
path: root/source/app.d
blob: 25bb8e9165e2f984b0e9f975fb6c08adb6629445 (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
import std.stdio;
import std.getopt;

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