blob: 478c652064a6ad10f5e72f8ec1e693b7ad59376e (
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ShiftOS.Engine;
using backend = ShiftOS.Engine.TerminalBackend;
namespace ShiftOS.Wpf
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
[Launcher("Terminal", false)]
public partial class Terminal : UserControl, IShiftOSWindow
{
public Terminal()
{
InitializeComponent();
Startup.ConsoleOut = this.txtterm;
if (SaveSystem.CurrentSave == null)
{
Startup.InitiateEngine(new WpfTerminalTextWriter());
SaveSystem.GameReady += () =>
{
try
{
Dispatcher.Invoke(new Action(() =>
{
txtterm.Text = "";
backend.PrefixEnabled = true;
backend.InStory = false;
if (SaveSystem.CurrentSave.StoryPosition != 8)
{
Story.RunFromInternalResource("sys_shiftoriumstory");
SaveSystem.CurrentSave.StoryPosition = 8;
}
Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ");
txtterm.Background = SkinEngine.LoadedSkin.TerminalBackColor.CreateBrush();
txtterm.Foreground = SkinEngine.LoadedSkin.TerminalForeColor.CreateBrush();
txtterm.SetFont(SkinEngine.LoadedSkin.TerminalFont);
}));
}
catch { }
};
}
else
{
Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ");
}
txtterm.Background = SkinEngine.LoadedSkin.TerminalBackColor.CreateBrush();
txtterm.Foreground = SkinEngine.LoadedSkin.TerminalForeColor.CreateBrush();
txtterm.GotFocus += (o, a) =>
{
Startup.ConsoleOut = txtterm;
};
txtterm.Focus();
}
public void OnLoad()
{
this.SetTitle("Terminal");
}
public void OnSkinLoad()
{
txtterm.SetFont(SkinEngine.LoadedSkin.TerminalFont);
}
public bool OnUnload()
{
return true;
}
public void OnUpgrade()
{
}
public void txtterm_KeyDown(object o, KeyEventArgs a) {
if (a.Key == Key.Enter)
{
try
{
a.Handled = true;
var text2 = txtterm.GetLineText(txtterm.LineCount - 1);
Console.WriteLine("");
var text3 = "";
var text4 = Regex.Replace(text2, @"\t|\n|\r", "");
if (backend.PrefixEnabled)
{
text3 = text4.Remove(0, $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length);
}
backend.LastCommand = text3;
if (backend.InStory == false)
{
backend.InvokeCommand(text3);
}
if (backend.PrefixEnabled)
{
Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ");
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
else if (a.Key == Key.Back)
{
var tostring3 = txtterm.GetLineText(txtterm.LineCount - 1);
var tostringlen = tostring3.Length + 1;
var workaround = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ";
var derp = workaround.Length + 1;
if (tostringlen != derp)
{
AppearanceManager.CurrentPosition--;
}
else
{
a.Handled = true;
}
}
else if (a.Key == Key.Left)
{
var getstring = txtterm.GetLineText(txtterm.LineCount - 1);
var stringlen = getstring.Length + 1;
var header = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ";
var headerlen = header.Length + 1;
var selstart = txtterm.SelectionStart;
var remstrlen = txtterm.Text.Length - stringlen;
var finalnum = selstart - remstrlen;
if (finalnum != headerlen)
{
AppearanceManager.CurrentPosition--;
}
else
{
a.Handled = true;
}
}
//( ͡° ͜ʖ ͡° ) You found the lennyface without looking at the commit message. Message Michael in the #shiftos channel on Discord saying "ladouceur" somewhere in your message if you see this.
else if (a.Key == Key.Up)
{
var tostring3 = txtterm.GetLineText(txtterm.LineCount - 1);
if (tostring3 == $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ")
Console.Write(backend.LastCommand);
a.Handled = true;
}
else
{
AppearanceManager.CurrentPosition++;
}
}
private void txtterm_GotFocus(object sender, RoutedEventArgs e)
{
Startup.ConsoleOut = txtterm;
}
}
}
|