config.go RawHistoryFolder

1package handlers
2
3import (
4	"context"
5	"encoding/json"
6	"fmt"
7
8	"github.com/bnema/dumber/internal/application/dto"
9	"github.com/bnema/dumber/internal/application/port"
10	"github.com/bnema/dumber/internal/logging"
11)
12
13// ConfigHandler handles configuration-related messages.
14type ConfigHandler struct {
15	saveConfig func(context.Context, dto.WebUIConfig) error
16}
17
18// NewConfigHandler creates a new ConfigHandler.
19// saveConfig is called to persist config changes (typically usecase.SaveWebUIConfigUseCase.Execute).
20func NewConfigHandler(saveConfig func(context.Context, dto.WebUIConfig) error) *ConfigHandler {
21	if saveConfig == nil {
22		panic("NewConfigHandler: saveConfig must not be nil")
23	}
24	return &ConfigHandler{saveConfig: saveConfig}
25}
26
27// Handle processes the save_config message.
28func (h *ConfigHandler) Handle(ctx context.Context, viewID port.WebViewID, payload json.RawMessage) (any, error) {
29	if h == nil {
30		return nil, fmt.Errorf("config handler is nil")
31	}
32	if h.saveConfig == nil {
33		return nil, fmt.Errorf("config handler: saveConfig not initialized")
34	}
35	log := logging.FromContext(ctx).With().Str("handler", "config").Logger()
36
37	var payloadCfg dto.WebUIConfig
38	if err := json.Unmarshal(payload, &payloadCfg); err != nil {
39		log.Error().Err(err).Msg("failed to unmarshal config payload")
40		return nil, fmt.Errorf("invalid config format: %w", err)
41	}
42
43	source := "webui"
44	if viewID != 0 {
45		source = fmt.Sprintf("webview:%d", viewID)
46	}
47	log.Info().Str("source", source).Msg("saving appearance configuration")
48
49	if err := h.saveConfig(ctx, payloadCfg); err != nil {
50		log.Error().Err(err).Msg("failed to save config")
51		return nil, fmt.Errorf("failed to save config: %w", err)
52	}
53
54	return map[string]any{"status": "success"}, nil
55}
56
57// RegisterConfigHandlers registers configuration handlers with the router.
58func RegisterConfigHandlers(
59	ctx context.Context, router port.WebUIHandlerRouter,
60	saveConfig func(context.Context, dto.WebUIConfig) error,
61) error {
62	handler := NewConfigHandler(saveConfig)
63
64	log := logging.FromContext(ctx).With().Str("component", "handlers").Logger()
65
66	if err := port.RegisterWebUIMessage(router, port.MsgSaveConfig, handler); err != nil {
67		return err
68	}
69
70	log.Info().Msg("registered save_config handler")
71
72	return nil
73}

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 8

Tags 42

↑↓ moveenter openesc close