fix: append command history row in real-time after execution
This commit is contained in:
@@ -12,6 +12,12 @@ terminalInput.addEventListener('keydown', function(e) {
|
||||
}
|
||||
});
|
||||
|
||||
function escapeHtml(str) {
|
||||
const d = document.createElement('div');
|
||||
d.textContent = str;
|
||||
return d.innerHTML;
|
||||
}
|
||||
|
||||
function executeCommand() {
|
||||
const command = terminalInput.value.trim();
|
||||
if (!command) return;
|
||||
@@ -46,6 +52,9 @@ function executeCommand() {
|
||||
if (data.stderr) {
|
||||
appendTerminalLine(data.stderr, 'error');
|
||||
}
|
||||
if (data.history) {
|
||||
appendHistoryRow(data.history);
|
||||
}
|
||||
updateStatus('connected', 'Connected');
|
||||
} else {
|
||||
appendTerminalLine(data.message || 'Command failed', 'error');
|
||||
@@ -84,6 +93,23 @@ function clearTerminal() {
|
||||
terminalOutput.innerHTML = '';
|
||||
}
|
||||
|
||||
function appendHistoryRow(h) {
|
||||
const tbody = document.querySelector('.card-body .table tbody');
|
||||
if (!tbody) return;
|
||||
const emptyState = tbody.closest('.card-body')?.querySelector('.empty-state');
|
||||
if (emptyState) emptyState.remove();
|
||||
const row = document.createElement('tr');
|
||||
const time = h.executed_at ? new Date(h.executed_at.replace(' ', 'T')).toLocaleTimeString('en-US', { hour12: false }) : '';
|
||||
row.innerHTML =
|
||||
'<td>' + time + '</td>' +
|
||||
'<td><code>' + escapeHtml(h.command) + '</code></td>' +
|
||||
'<td><span class="badge ' + (h.exit_status === 0 ? 'badge-success' : 'badge-danger') + '">' + (h.exit_status === 0 ? 'OK' : 'ERR') + '</span></td>' +
|
||||
'<td>' + escapeHtml(h.username || 'System') + '</td>';
|
||||
tbody.prepend(row);
|
||||
const container = tbody.closest('.table-responsive');
|
||||
if (container) container.scrollTop = 0;
|
||||
}
|
||||
|
||||
function clearHistory() {
|
||||
if (!confirm('Clear all command history for this server?')) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user