1 /**
2 * Copyright © DiamondMVC 2019
3 * License: MIT (https://github.com/DiamondMVC/Diamond/blob/master/LICENSE)
4 * Author: Jacob Jensen (bausshf)
5 */
6 module diamond.core.io;
7 
8 import stdio = std.stdio : writeln, writefln, readln;
9 
10 /// Mixin template to handle files at compile-time.
11 mixin template handleCTFEFile(string fileName, string fileHandler)
12 {
13   /// Function that must be called to handle the file.
14   void handle()
15   {
16     static if (__traits(compiles, { auto s = import(fileName); }))
17     {
18       mixin("{
19         enum __fileResult = import(fileName);
20         " ~ fileHandler ~
21       "}");
22     }
23   }
24 }
25 
26 /**
27 * Prints a message to the standard output.
28 * Params:
29 *   msg = The message to print.
30 */
31 void print(string msg)
32 {
33   stdio.writeln(msg);
34 }
35 
36 /**
37 * Prints a formatted message to the standard output.
38 * Params:
39 *   msg = The message to print.
40 *   args = The arguments to print.
41 */
42 void print(Args...)(string msg, Args args)
43 {
44   stdio.writefln(msg, args);
45 }
46 
47 /**
48 * Prints data to the standard output.
49 * Params:
50 *   data = The data to print.
51 */
52 void print(T)(T data)
53 {
54   print("Data: %s", data);
55 }
56 
57 void wait()
58 {
59   readInput();
60 }
61 
62 auto readInput()
63 {
64   return stdio.readln();
65 }