aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn/TerminalTextWriter.cs
blob: b36c13ae7bd39f5b085c22e3696578b98b606aa8 (plain) (blame)
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Forms;

namespace ShiftOS.Engine
{
    public class TerminalTextWriter : TextWriter
    {
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        public static extern bool LockWindowUpdate(IntPtr hWndLock);
        

        public override Encoding Encoding
        {
            get
            {
                return Encoding.Unicode;
            }
        }

        public ITerminalWidget UnderlyingControl
        {
            get
            {
                return AppearanceManager.ConsoleOut;
            }
        }

        public void select()
        {
            Desktop.InvokeOnWorkerThread(new Action(() =>
            {
                UnderlyingControl.SelectBottom();
                
            }));
        }

        public override void Write(char value)
        {
            Desktop.InvokeOnWorkerThread(new Action(() =>
            {
                UnderlyingControl.Write(value.ToString());
                select();
            }));
        }

        public override void WriteLine(string value)
        {
            Desktop.InvokeOnWorkerThread(new Action(() =>
            {
                UnderlyingControl.WriteLine(value);
                select();
            }));
        }

        public void SetLastText()
        {
        }

        public override void Write(string value)
        {
            Desktop.InvokeOnWorkerThread(new Action(() =>
            {
                UnderlyingControl.Write(value.ToString());
                select();
            }));
        }


    }
}