Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 87bbc0b

Browse files
committed
Add informative console title
1 parent 7cdd51c commit 87bbc0b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

internal/sync/sync.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/gorilla/websocket"
1515
"github.com/rjeczalik/notify"
1616
"go.coder.com/flog"
17+
"golang.org/x/crypto/ssh/terminal"
1718
"golang.org/x/xerrors"
1819

1920
"cdr.dev/coder-cli/internal/entclient"
@@ -156,6 +157,13 @@ func (s Sync) work(ev notify.EventInfo) {
156157
}
157158
}
158159

160+
func setConsoleTitle(title string) {
161+
if !terminal.IsTerminal(int(os.Stdout.Fd())) {
162+
return
163+
}
164+
fmt.Printf("\033]0;%s\007", title)
165+
}
166+
159167
// maxinflightInotify sets the maximum number of inotifies before the sync just restarts.
160168
// Syncing a large amount of small files (e.g .git or node_modules) is impossible to do performantly
161169
// with individual rsyncs.
@@ -164,6 +172,7 @@ const maxInflightInotify = 16
164172
var ErrRestartSync = errors.New("the sync exited because it was overloaded, restart it")
165173

166174
func (s Sync) Run() error {
175+
setConsoleTitle("⏳ syncing project")
167176
err := s.initSync()
168177
if err != nil {
169178
return err
@@ -182,12 +191,19 @@ func (s Sync) Run() error {
182191
}
183192
defer notify.Stop(events)
184193

194+
195+
const watchingFilesystemTitle = "🛰 watching filesystem"
196+
setConsoleTitle(watchingFilesystemTitle)
197+
185198
flog.Info("watching %s for changes", s.LocalDir)
186199
for ev := range events {
187200
if len(events) > maxInflightInotify {
188201
return ErrRestartSync
189202
}
203+
204+
setConsoleTitle("🚀 updating " + filepath.Base(ev.Path()))
190205
s.work(ev)
206+
setConsoleTitle(watchingFilesystemTitle)
191207
}
192208

193209
return nil

0 commit comments

Comments
 (0)