-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterminal-log-lego.js
More file actions
157 lines (133 loc) · 4.47 KB
/
terminal-log-lego.js
File metadata and controls
157 lines (133 loc) · 4.47 KB
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
/**
* TERMINAL & LOG CONTAINER
* Bottom container split 50/50: Terminal (top) and Activity Log (bottom)
*/
let isTerminalLogInitialized = false;
/**
* Initialize Terminal & Log container
*/
function initTerminalLogContainer() {
if (isTerminalLogInitialized) {
console.log('TERMINAL/LOG: Already initialized, just showing');
showTerminalLog();
return;
}
console.log('TERMINAL/LOG: Initializing container...');
// Find the bottom container
const container = document.querySelector('.lego-container[data-position="bottom"]');
if (!container) {
console.error('TERMINAL/LOG: Container not found');
return;
}
// Clear existing content and create structure
container.innerHTML = `
<div class="terminal-log-split">
<div class="terminal-panel">
<div class="panel-header">TERMINAL</div>
<div class="terminal-content" id="terminal-content">
<div class="terminal-line">$ <span class="terminal-prompt">horus ready</span></div>
<div class="terminal-line">$ <span class="terminal-cursor">_</span></div>
</div>
</div>
<div class="log-panel">
<div class="panel-header">ACTIVITY LOG</div>
<div class="log-content" id="log-content">
<!-- Log entries will be added dynamically -->
</div>
</div>
</div>
`;
isTerminalLogInitialized = true;
console.log('TERMINAL/LOG: Initialized successfully');
}
/**
* Show terminal/log (scroll to bottom)
*/
function showTerminalLog() {
if (!isTerminalLogInitialized) {
initTerminalLogContainer();
return;
}
const terminalContent = document.getElementById('terminal-content');
const logContent = document.getElementById('log-content');
if (terminalContent) {
terminalContent.scrollTop = terminalContent.scrollHeight;
}
if (logContent) {
logContent.scrollTop = logContent.scrollHeight;
}
console.log('TERMINAL/LOG: Showing container');
}
/**
* Hide terminal/log (doesn't need cleanup)
*/
function hideTerminalLog() {
console.log('TERMINAL/LOG: Hiding container');
}
/**
* Add terminal output (for future use)
*/
function addTerminalOutput(command, output) {
const terminalContent = document.getElementById('terminal-content');
if (!terminalContent || !isTerminalLogInitialized) return;
// Remove cursor from last line
const lastLine = terminalContent.querySelector('.terminal-line:last-child');
if (lastLine) {
lastLine.innerHTML = lastLine.innerHTML.replace('_', '');
}
// Add command line
const commandLine = document.createElement('div');
commandLine.className = 'terminal-line';
commandLine.innerHTML = `$ <span class="terminal-command">${command}</span>`;
terminalContent.appendChild(commandLine);
// Add output if provided
if (output) {
const outputLine = document.createElement('div');
outputLine.className = 'terminal-line terminal-output';
outputLine.textContent = output;
terminalContent.appendChild(outputLine);
}
// Add new prompt with cursor
const promptLine = document.createElement('div');
promptLine.className = 'terminal-line';
promptLine.innerHTML = `$ <span class="terminal-cursor">_</span>`;
terminalContent.appendChild(promptLine);
// Auto-scroll
terminalContent.scrollTop = terminalContent.scrollHeight;
}
/**
* Add log entry (for future use)
*/
function addLogEntry(action, message) {
const logContent = document.getElementById('log-content');
if (!logContent || !isTerminalLogInitialized) return;
// Format time as AM/PM
const now = new Date();
const hours = now.getHours();
const minutes = now.getMinutes();
const seconds = now.getSeconds();
const ampm = hours >= 12 ? 'PM' : 'AM';
const hours12 = hours % 12 || 12;
const time = `${hours12}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')} ${ampm}`;
const entry = document.createElement('div');
entry.className = 'log-entry';
entry.innerHTML = `
<span class="log-time">${time}</span>
<span class="log-action">${action}</span>
<span class="log-message">${message}</span>
`;
logContent.appendChild(entry);
// Auto-scroll
logContent.scrollTop = logContent.scrollHeight;
}
// Export functions for use in main script
if (typeof window !== 'undefined') {
window.TerminalLogContainer = {
init: initTerminalLogContainer,
show: showTerminalLog,
hide: hideTerminalLog,
addTerminalOutput: addTerminalOutput,
addLogEntry: addLogEntry,
isInitialized: () => isTerminalLogInitialized
};
}