Had to stop production as I ran out of copilot credits
This commit is contained in:
+24
-37
@@ -5,33 +5,38 @@ namespace PainoBar_Helper
|
||||
{
|
||||
public partial class StationForm : Form
|
||||
{
|
||||
private readonly PianobarManager _pianobarManager;
|
||||
private readonly StringBuilder _outputBuffer = new StringBuilder();
|
||||
|
||||
public StationForm(PianobarManager pianobarManager)
|
||||
public StationForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_pianobarManager = pianobarManager;
|
||||
|
||||
// Subscribe to output BEFORE controls are initialized
|
||||
_pianobarManager.OutputReceived += PianobarManager_TerminalOutputReceived;
|
||||
|
||||
// Handle form load to display buffered output
|
||||
// Handle form load and closing for event subscription
|
||||
this.Load += StationForm_Load;
|
||||
this.FormClosing += StationForm_FormClosing;
|
||||
|
||||
InitializeControls();
|
||||
}
|
||||
|
||||
private void StationForm_Load(object? sender, EventArgs e)
|
||||
{
|
||||
// Display any buffered output when form loads
|
||||
if (terminal_box != null && _outputBuffer.Length > 0)
|
||||
// First, populate terminal with existing history
|
||||
if (terminal_box != null && Main.TerminalHistory.Count > 0)
|
||||
{
|
||||
terminal_box.Text = _outputBuffer.ToString();
|
||||
foreach (string line in Main.TerminalHistory)
|
||||
{
|
||||
terminal_box.AppendText(line + "\n");
|
||||
}
|
||||
terminal_box.SelectionStart = terminal_box.Text.Length;
|
||||
terminal_box.ScrollToCaret();
|
||||
}
|
||||
|
||||
// Second, subscribe to live output events
|
||||
Main.OnPianobarOutputReceived += AppendToTerminal;
|
||||
}
|
||||
|
||||
private void StationForm_FormClosing(object? sender, FormClosingEventArgs e)
|
||||
{
|
||||
// Unsubscribe from the static event
|
||||
Main.OnPianobarOutputReceived -= AppendToTerminal;
|
||||
}
|
||||
|
||||
#region Initialization
|
||||
@@ -61,16 +66,11 @@ namespace PainoBar_Helper
|
||||
|
||||
#region Terminal Output
|
||||
|
||||
private void PianobarManager_TerminalOutputReceived(object? sender, string e)
|
||||
private void AppendToTerminal(string data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(e))
|
||||
if (string.IsNullOrEmpty(data))
|
||||
return;
|
||||
|
||||
string lineWithNewline = e + "\n";
|
||||
|
||||
// Buffer output even before form is shown
|
||||
_outputBuffer.Append(lineWithNewline);
|
||||
|
||||
// Thread-safe UI update
|
||||
if (terminal_box != null)
|
||||
{
|
||||
@@ -78,12 +78,12 @@ namespace PainoBar_Helper
|
||||
{
|
||||
terminal_box.Invoke(() =>
|
||||
{
|
||||
AppendTerminalText(lineWithNewline);
|
||||
AppendTerminalText(data + "\n");
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
AppendTerminalText(lineWithNewline);
|
||||
AppendTerminalText(data + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,11 +125,8 @@ namespace PainoBar_Helper
|
||||
|
||||
try
|
||||
{
|
||||
// Echo the command to the terminal (simulating user input display)
|
||||
AppendTerminalText($"> {command}\n");
|
||||
|
||||
// Send command to Pianobar with newline and flush
|
||||
_pianobarManager.SendCommand(command);
|
||||
// Send command directly to Pianobar stdin (no manual echo with ">")
|
||||
Main.SendStdin(command);
|
||||
|
||||
command_input_box.Clear();
|
||||
}
|
||||
@@ -157,15 +154,5 @@ namespace PainoBar_Helper
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cleanup
|
||||
|
||||
protected override void OnFormClosing(FormClosingEventArgs e)
|
||||
{
|
||||
_pianobarManager.OutputReceived -= PianobarManager_TerminalOutputReceived;
|
||||
base.OnFormClosing(e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user