Skip to content

Commit

Permalink
status: support output to a file
Browse files Browse the repository at this point in the history
Use renameio to get automagic atomic writes
  • Loading branch information
gerryd committed Oct 20, 2023
1 parent ade54d6 commit 0af6ae6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ go 1.19
require (
github.com/BertoldVdb/ms-tools v0.0.0-20231004114646-22ddf782f595
github.com/alecthomas/kong v0.8.0
github.com/google/renameio v1.0.1
github.com/sstallion/go-hid v0.14.1
)

require (
github.com/google/renameio v1.0.1 // indirect
golang.org/x/sys v0.8.0 // indirect
)
require golang.org/x/sys v0.8.0 // indirect
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/BertoldVdb/ms-tools v0.0.0-20221129120332-dd3c7641485a h1:HiNl4aayDj6YwzDHtbcRBX79r8BzCY6gBmGkalPkVuQ=
github.com/BertoldVdb/ms-tools v0.0.0-20221129120332-dd3c7641485a/go.mod h1:jmbR3cRIFTGz2Licvnbx5fv/SG6aLRJHpOILmEKTy5M=
github.com/BertoldVdb/ms-tools v0.0.0-20231004114646-22ddf782f595 h1:dUuC+xTDdNG2kl6WF0O4iJKAzabaKhNfedXrdaz6pQs=
github.com/BertoldVdb/ms-tools v0.0.0-20231004114646-22ddf782f595/go.mod h1:jmbR3cRIFTGz2Licvnbx5fv/SG6aLRJHpOILmEKTy5M=
github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2ojoH/0=
Expand Down
10 changes: 9 additions & 1 deletion status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package main

import (
"fmt"
"os"
"time"

"encoding/binary"
"encoding/json"

"github.com/google/renameio"
)

type Region struct {
Expand Down Expand Up @@ -56,7 +60,11 @@ func (s *StatusCmd) Run(c *Context) error {
p = fmt.Sprintf("width: %d\nheight: %d\nsignal: %s\n", output.Width, output.Height, output.Signal)
}

fmt.Print(p)
if (s.Filename == "") {
fmt.Print(p)
} else {
renameio.WriteFile(s.Filename, []byte(p), os.FileMode(int(0644)))
}

if (s.Loop == 0) {
next = false
Expand Down

0 comments on commit 0af6ae6

Please sign in to comment.