Skip to content

Commit bd00121

Browse files
committed
Enhance action log printing
Fixes #2.
1 parent 7557411 commit bd00121

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

source/reloadedvibes/action.d

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
+/
99
module reloadedvibes.action;
1010

11-
import std.stdio : stderr;
11+
import std.stdio : stderr, stdout;
1212
import std.process : spawnShell, wait;
1313
import reloadedvibes.watcher;
1414

@@ -36,21 +36,47 @@ final class ActionWatcherClient : WatcherClient
3636

3737
ActionWatcherClient fromCommandLines(Watcher w, string[] commandLines)
3838
{
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+
3959
return new ActionWatcherClient(w, delegate() @trusted {
40-
foreach (cmd; commandLines)
60+
foreach (idx, cmd; commandLines)
4161
{
4262
try
4363
{
64+
stdout.writeln("\n", sep[idx]);
4465
immutable exitCode = spawnShell(cmd).wait();
4566

4667
if (exitCode != 0)
4768
{
48-
stderr.writeln("Action {" ~ cmd ~ "} failed with exit code ", exitCode);
69+
stderr.writeln("\n", sepLine,
70+
"\nAction {" ~ cmd ~ "} failed with exit code ", exitCode);
4971
}
5072
}
5173
catch (Exception ex)
5274
{
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");
5480
}
5581
}
5682
});

source/reloadedvibes/app.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ int main(string[] args)
127127
// Initial execution
128128
// Since the action is usually some preprocessor or something,
129129
// it should also get executed on application launch
130-
doInit ~= { awcl.notify(); };
130+
doInit ~= { stdout.writeln("\nPre-executing actions..."); awcl.notify(); };
131131

132132
if (optDisableService)
133133
{

source/reloadedvibes/server.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ HTTPListener registerService(Socket s, Watcher w)
9595
return listenHTTP(settings, router);
9696
}
9797

98-
HTTPListener registerStaticWebserver(Socket s, string docroot)
98+
HTTPListener registerStaticWebserver(Socket s, string docroot) @safe
9999
{
100100
auto settings = new HTTPServerSettings();
101101
settings.port = s.port;
102102
settings.bindAddresses = [s.address];
103103
return listenHTTP(settings, serveStaticFiles(docroot));
104104
}
105105

106-
HTTPListener registerStaticWebserver(Socket s, string docroot, Socket nfService)
106+
HTTPListener registerStaticWebserver(Socket s, string docroot, Socket nfService) @safe
107107
{
108108
immutable htd = NativePath(docroot);
109109

0 commit comments

Comments
 (0)