forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileConsole.cs
More file actions
80 lines (67 loc) · 1.78 KB
/
FileConsole.cs
File metadata and controls
80 lines (67 loc) · 1.78 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.IO;
using ScriptCs.Contracts;
namespace ScriptCs.Hosting
{
public class FileConsole : IConsole
{
private readonly string _path;
private readonly IConsole _innerConsole;
public FileConsole(string path, IConsole innerConsole)
{
Guard.AgainstNullArgument("innerConsole", innerConsole);
_path = path;
_innerConsole = innerConsole;
}
public void Write(string value)
{
_innerConsole.Write(value);
this.Append(value);
}
public void WriteLine()
{
_innerConsole.WriteLine();
this.AppendLine(string.Empty);
}
public void WriteLine(string value)
{
_innerConsole.WriteLine(value);
this.AppendLine(value);
}
public string ReadLine(string prompt)
{
var line = _innerConsole.ReadLine("");
this.AppendLine(line);
return line;
}
public void Clear()
{
_innerConsole.Clear();
}
public void Exit()
{
_innerConsole.Exit();
}
public void ResetColor()
{
_innerConsole.ResetColor();
}
public ConsoleColor ForegroundColor
{
get { return _innerConsole.ForegroundColor; }
set { _innerConsole.ForegroundColor = value; }
}
private void Append(string text)
{
using (var writer = new StreamWriter(_path, true))
{
writer.Write(text);
writer.Flush();
}
}
private void AppendLine(string text)
{
this.Append(text + Environment.NewLine);
}
}
}