Skip to content

Commit cd2e7fc

Browse files
committed
Implemented handling for setting Background-Terminal's newline character when pressing the return key
1 parent 363c43f commit cd2e7fc

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

Background-Terminal/MainWindow.xaml.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Linq;
99
using System.Management;
1010
using System.Text;
11+
using System.Text.RegularExpressions;
1112
using System.Threading.Tasks;
1213
using System.Windows;
1314
using System.Windows.Controls;
@@ -40,6 +41,8 @@ public partial class MainWindow : Window
4041

4142
private ObservableCollection<string> _terminalData = new ObservableCollection<string>();
4243

44+
private string _newlineString = Environment.NewLine;
45+
4346
private int _cmdProcessId;
4447

4548
private bool _terminalWindowActive = false;
@@ -200,10 +203,25 @@ private void CMD_ErrorDataReceived(object sender, DataReceivedEventArgs e)
200203

201204
private void SendCommand(string command, bool output = true)
202205
{
203-
if (output)
204-
_terminalData.Add(command);
206+
// Background-Terminal application commands
207+
if (command.StartsWith("bgt"))
208+
{
209+
string bgtCommand = command.Split(' ')[1];
210+
string[] parameters = command.Substring(command.IndexOf(bgtCommand) + bgtCommand.Length + 1).Split(' ');
205211

206-
_process.StandardInput.WriteLine(command);
212+
if (bgtCommand.Equals("newline"))
213+
{
214+
_newlineString = Regex.Unescape(parameters[0]);
215+
}
216+
}
217+
else
218+
{
219+
if (output)
220+
_terminalData.Add(command);
221+
222+
_process.StandardInput.NewLine = _newlineString;
223+
_process.StandardInput.WriteLine(command);
224+
}
207225
}
208226

209227
private void KillChildren()

0 commit comments

Comments
 (0)