Reaperxxxx commited on
Commit
d5287e7
·
verified ·
1 Parent(s): 049a78a

Update public/terminal.js

Browse files
Files changed (1) hide show
  1. public/terminal.js +24 -8
public/terminal.js CHANGED
@@ -9,9 +9,19 @@ document.addEventListener("DOMContentLoaded", () => {
9
  const terminal = document.getElementById("terminal");
10
  const commandInput = document.getElementById("command");
11
 
12
- const appendToTerminal = (text) => {
13
  const line = document.createElement("div");
14
  line.textContent = text;
 
 
 
 
 
 
 
 
 
 
15
  terminal.appendChild(line);
16
  terminal.scrollTop = terminal.scrollHeight;
17
  };
@@ -23,13 +33,19 @@ document.addEventListener("DOMContentLoaded", () => {
23
  const logs = await response.text();
24
  terminal.innerHTML = "";
25
  logs.split("\n").forEach((line) => {
26
- if (line.trim()) appendToTerminal(line);
 
 
 
 
 
 
27
  });
28
  } else {
29
- appendToTerminal("Failed to fetch logs.");
30
  }
31
  } catch (error) {
32
- appendToTerminal("Error fetching logs.");
33
  }
34
  };
35
 
@@ -44,10 +60,10 @@ document.addEventListener("DOMContentLoaded", () => {
44
  if (response.ok) {
45
  fetchLogs();
46
  } else {
47
- appendToTerminal("Error executing command.");
48
  }
49
  } catch (error) {
50
- appendToTerminal("Command execution failed.");
51
  }
52
  };
53
 
@@ -84,10 +100,10 @@ document.addEventListener("DOMContentLoaded", () => {
84
  appendToTerminal("Deployment started...");
85
  fetchLogs();
86
  } else {
87
- appendToTerminal("Error starting deployment.");
88
  }
89
  } catch (error) {
90
- appendToTerminal("Deployment failed.");
91
  }
92
  }
93
  });
 
9
  const terminal = document.getElementById("terminal");
10
  const commandInput = document.getElementById("command");
11
 
12
+ const appendToTerminal = (text, type = "info") => {
13
  const line = document.createElement("div");
14
  line.textContent = text;
15
+
16
+ // Differentiate logs visually (e.g., errors in red)
17
+ if (type === "error") {
18
+ line.style.color = "red";
19
+ } else if (type === "warn") {
20
+ line.style.color = "orange";
21
+ } else {
22
+ line.style.color = "white";
23
+ }
24
+
25
  terminal.appendChild(line);
26
  terminal.scrollTop = terminal.scrollHeight;
27
  };
 
33
  const logs = await response.text();
34
  terminal.innerHTML = "";
35
  logs.split("\n").forEach((line) => {
36
+ if (line.includes("WARN")) {
37
+ appendToTerminal(line, "warn");
38
+ } else if (line.includes("ERROR") || line.includes("error")) {
39
+ appendToTerminal(line, "error");
40
+ } else if (line.trim()) {
41
+ appendToTerminal(line);
42
+ }
43
  });
44
  } else {
45
+ appendToTerminal("Failed to fetch logs.", "error");
46
  }
47
  } catch (error) {
48
+ appendToTerminal("Error fetching logs.", "error");
49
  }
50
  };
51
 
 
60
  if (response.ok) {
61
  fetchLogs();
62
  } else {
63
+ appendToTerminal("Error executing command.", "error");
64
  }
65
  } catch (error) {
66
+ appendToTerminal("Command execution failed.", "error");
67
  }
68
  };
69
 
 
100
  appendToTerminal("Deployment started...");
101
  fetchLogs();
102
  } else {
103
+ appendToTerminal("Error starting deployment.", "error");
104
  }
105
  } catch (error) {
106
+ appendToTerminal("Deployment failed.", "error");
107
  }
108
  }
109
  });