|
8 | 8 | +/ |
9 | 9 | module reloadedvibes.action; |
10 | 10 |
|
11 | | -import std.stdio : stderr; |
| 11 | +import std.stdio : stderr, stdout; |
12 | 12 | import std.process : spawnShell, wait; |
13 | 13 | import reloadedvibes.watcher; |
14 | 14 |
|
@@ -36,21 +36,47 @@ final class ActionWatcherClient : WatcherClient |
36 | 36 |
|
37 | 37 | ActionWatcherClient fromCommandLines(Watcher w, string[] commandLines) |
38 | 38 | { |
| 39 | + enum sepLine = "-------------------------------------------------------------------------------"; |
| 40 | + enum segmentPre = "----{ "; |
| 41 | + enum segmentPost = " }"; |
| 42 | + enum segmentsLength = (segmentPre.length + segmentPost.length); |
| 43 | + enum embeddedCMDMaxLength = 79 - segmentsLength; |
| 44 | + |
| 45 | + string[] sep = new string[commandLines.length]; |
| 46 | + |
| 47 | + foreach (idx, cmd; commandLines) |
| 48 | + { |
| 49 | + if (cmd.length >= embeddedCMDMaxLength) |
| 50 | + { |
| 51 | + sep[idx] = sepLine ~ "\n" ~ cmd ~ "\n" ~ sepLine ~ "\n"; |
| 52 | + continue; |
| 53 | + } |
| 54 | + |
| 55 | + immutable rest = embeddedCMDMaxLength - cmd.length; |
| 56 | + sep[idx] = segmentPre ~ cmd ~ segmentPost ~ sepLine[0 .. rest] ~ "\n"; |
| 57 | + } |
| 58 | + |
39 | 59 | return new ActionWatcherClient(w, delegate() @trusted { |
40 | | - foreach (cmd; commandLines) |
| 60 | + foreach (idx, cmd; commandLines) |
41 | 61 | { |
42 | 62 | try |
43 | 63 | { |
| 64 | + stdout.writeln("\n", sep[idx]); |
44 | 65 | immutable exitCode = spawnShell(cmd).wait(); |
45 | 66 |
|
46 | 67 | if (exitCode != 0) |
47 | 68 | { |
48 | | - stderr.writeln("Action {" ~ cmd ~ "} failed with exit code ", exitCode); |
| 69 | + stderr.writeln("\n", sepLine, |
| 70 | + "\nAction {" ~ cmd ~ "} failed with exit code ", exitCode); |
49 | 71 | } |
50 | 72 | } |
51 | 73 | catch (Exception ex) |
52 | 74 | { |
53 | | - stderr.writeln("Action {" ~ cmd ~ "} failed: ", ex.msg); |
| 75 | + stderr.writeln("\n", sepLine, "\nAction {" ~ cmd ~ "} failed: ", ex.msg); |
| 76 | + } |
| 77 | + finally |
| 78 | + { |
| 79 | + stdout.writeln("\n"); |
54 | 80 | } |
55 | 81 | } |
56 | 82 | }); |
|
0 commit comments