Skip to content

Commit

Permalink
Adjust index for log (#5)
Browse files Browse the repository at this point in the history
* Adjust index for log

* Strip ascii with regex

* Style

* format
  • Loading branch information
ludeeus authored Sep 12, 2020
1 parent f922125 commit 5ba9b1f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 21 deletions.
10 changes: 8 additions & 2 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"net"
"net/http"
"regexp"
"strings"
)

Expand Down Expand Up @@ -84,10 +85,15 @@ func statusIndex(w http.ResponseWriter, r *http.Request) {
// Set logs
if !data.On {
var buf bytes.Buffer
var re = regexp.MustCompile(`\[\d+m`)
logWriter := bufio.NewWriter(&buf)

supervisorLogs(logWriter)
data.Logs = buf.String()
err := supervisorLogs(logWriter)
if err != nil {
data.Logs = err.Error()
} else {
data.Logs = re.ReplaceAllLiteralString(buf.String(), "")
}
}

// Render Website
Expand Down
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func main() {
// Serve static help files
staticFiles := http.FileServer(http.Dir(wwwRoot))
http.Handle("/observer.css", staticFiles)
http.Handle("/observer.js", staticFiles)

log.Print("Start webserver on http://0.0.0.0:80")
http.ListenAndServe(":80", nil)
Expand Down
7 changes: 4 additions & 3 deletions rootfs/usr/share/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home Assistant observer</title>
<link rel="stylesheet" href="/observer.css">
<script src="/observer.js"></script>
</head>
<body>
<div class="container">
<h1>Home Assistant observer</h1>
<div class="info">
<span class="title">Supervisor:</span>
<span id="connection" class="description {{if .On}}connected{{else}}disconnected{{end}}">
<span class="description {{if .On}}connected{{else}}disconnected{{end}}">
{{if .On}}Connected{{else}}Disconnected{{end}}
</span>
</div>
<pre id="log" class="log">{{.Logs}}</pre>
{{ if not .On }}
<pre class="log">{{.Logs}}</pre>
{{ end }}
</div>
</body>
</html>
4 changes: 4 additions & 0 deletions rootfs/usr/share/www/observer.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ h1 {
white-space: pre-wrap;
overflow-wrap: break-word;
font-size: 12px;
line-height: 18px;
font-family: monospace;
padding: 4px;
border-radius: 8px;
background-color: #fafafa;
}

@media only screen and (max-width: 600px) {
Expand Down
15 changes: 0 additions & 15 deletions rootfs/usr/share/www/observer.js

This file was deleted.

0 comments on commit 5ba9b1f

Please sign in to comment.