feat/data-dnd e05cb15

watch.go RawHistoryFolder

1package config
2
3import (
4	"context"
5	"errors"
6	"io/fs"
7	"time"
8
9	"github.com/bnema/kvconf"
10	"github.com/bnema/neferwl/internal/ports"
11	"github.com/bnema/zerowrap"
12)
13
14// reloadDebounce is the quiet time after a change before the file is read:
15// every write restarts it, so the file is never read half written.
16const reloadDebounce = 100 * time.Millisecond
17
18// loadRaw returns the effective keys of the file at startup; missing means none.
19func loadRaw(path string) map[string]string {
20	_, raw, _, err := loadFile(path)
21	if err != nil {
22		return map[string]string{}
23	}
24	return raw
25}
26
27// Watch reloads the config when the file at path changes and sends each
28// changed config on out. kvconf watches the parent directory, so atomic file
29// replacements are seen, follows symlinks (dotfiles) down to their target, and
30// waits for a missing directory to appear.
31func Watch(ctx context.Context, path string, out chan<- ports.ConfigChanged, log zerowrap.Logger) error {
32	ctx, cancel := context.WithCancel(ctx)
33	defer cancel()
34	// A pending signal already means "changed": one slot is enough.
35	signals := make(chan struct{}, 1)
36	last := loadRaw(path)
37	watchErr := make(chan error, 1)
38	go func() {
39		watchErr <- kvconf.Watch(ctx, path, kvconf.WatchOptions{Debounce: reloadDebounce}, signals)
40	}()
41	for {
42		select {
43		case <-ctx.Done():
44			return <-watchErr
45		case err := <-watchErr:
46			return err
47		case <-signals:
48		}
49		cfg, raw, warnings, err := loadFile(path)
50		switch {
51		case errors.Is(err, fs.ErrNotExist):
52			log.Warn().Msg("config file removed; keeping current config")
53			continue
54		case err != nil:
55			log.Warn().Err(err).Msg("config reload failed")
56			continue
57		}
58		for _, w := range warnings {
59			log.Warn().Int("line", w.Line).Msg(w.Msg)
60		}
61		changed := kvconf.Changed(last, raw)
62		last = raw
63		if len(changed) == 0 {
64			log.Debug().Msg("config unchanged")
65			continue
66		}
67		select {
68		case <-ctx.Done():
69			return <-watchErr
70		case out <- ports.ConfigChanged{Config: cfg}:
71		}
72		log.Info().Strs("changed", changed).Msg("config reloaded")
73	}
74}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 25

Tags 10

↑↓ moveenter openesc close