1 /* 2 * hunt-console eases the creation of beautiful and testable command line interfaces. 3 * 4 * Copyright (C) 2018-2019, HuntLabs 5 * 6 * Website: https://www.huntlabs.net 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 12 module hunt.console.output.StreamOutput; 13 14 import hunt.console.formatter.OutputFormatter; 15 16 import hunt.stream.Common; 17 import hunt.stream.FileOutputStream; 18 // import hunt.io.PrintWriter; 19 import hunt.console.output.AbstractOutput; 20 import hunt.console.output.Verbosity; 21 import hunt.console.output.Output; 22 import std.stdio; 23 24 class StreamOutput : AbstractOutput 25 { 26 private OutputStream stream; 27 private FileOutputStream writer; 28 29 public this(OutputStream stream) 30 { 31 super(); 32 initialize(stream); 33 } 34 35 public this(OutputStream stream, Verbosity verbosity) 36 { 37 super(verbosity); 38 initialize(stream); 39 } 40 41 public this(OutputStream stream, Verbosity verbosity, bool decorated) 42 { 43 super(verbosity, decorated); 44 initialize(stream); 45 } 46 47 public this(OutputStream stream, Verbosity verbosity, bool decorated, OutputFormatter formatter) 48 { 49 super(verbosity, decorated, formatter); 50 initialize(stream); 51 } 52 53 public OutputStream getStream() 54 { 55 return stream; 56 } 57 58 private void initialize(OutputStream stream) 59 { 60 this.stream = stream; 61 writer = new FileOutputStream(stdout); 62 } 63 64 override protected void doWrite(string message, bool newline) 65 { 66 writer.write(cast(byte[])message); 67 68 if (newline) { 69 writer.write('\n'); 70 } 71 72 writer.flush(); 73 } 74 }