v0.3.0 d226234

webview.go RawHistoryFolder

1//go:build !webkit_cgo
2
3package webkit
4
5import (
6	"fmt"
7	"log"
8)
9
10// WebView represents a browser view powered by WebKit2GTK.
11// Methods are currently stubs returning ErrNotImplemented to satisfy TDD ordering.
12type WebView struct {
13	config       *Config
14	visible      bool
15	zoom         float64
16	url          string
17	destroyed    bool
18	window       *Window
19	msgHandler   func(payload string)
20	titleHandler func(title string)
21	uriHandler   func(uri string)
22	zoomHandler  func(level float64)
23}
24
25// NewWebView constructs a new WebView instance.
26func NewWebView(cfg *Config) (*WebView, error) {
27	if cfg == nil {
28		cfg = &Config{}
29	}
30	log.Printf("[webkit] NewWebView (non-CGO stub) — UI will not be displayed. Build with -tags=webkit_cgo for native window.")
31	wv := &WebView{config: cfg}
32	if cfg.ZoomDefault <= 0 {
33		wv.zoom = 1.0
34	} else {
35		wv.zoom = cfg.ZoomDefault
36	}
37	// Construction succeeds; create a logical window placeholder.
38	wv.window = &Window{Title: "Dumber Browser"}
39	return wv, nil
40}
41
42// LoadURL navigates the webview to the specified URL.
43func (w *WebView) LoadURL(rawURL string) error {
44	if w == nil || w.destroyed {
45		return ErrNotImplemented
46	}
47	if rawURL == "" {
48		return fmt.Errorf("url cannot be empty")
49	}
50	// Minimal validation; actual navigation handled by CGO bridge later.
51	w.url = rawURL
52	log.Printf("[webkit] LoadURL (non-CGO stub): %s", rawURL)
53	return nil
54}
55
56// Show makes the WebView visible.
57func (w *WebView) Show() error {
58	if w == nil || w.destroyed {
59		return ErrNotImplemented
60	}
61	w.visible = true
62	log.Printf("[webkit] Show (non-CGO stub): no native window will appear")
63	return nil
64}
65
66// Hide hides the WebView window.
67func (w *WebView) Hide() error {
68	if w == nil || w.destroyed {
69		return ErrNotImplemented
70	}
71	w.visible = false
72	return nil
73}
74
75// Destroy releases native resources.
76func (w *WebView) Destroy() error {
77	if w == nil {
78		return ErrNotImplemented
79	}
80	w.destroyed = true
81	return nil
82}
83
84// Window returns the associated native window wrapper (non-nil).
85func (w *WebView) Window() *Window { return w.window }
86
87// GetCurrentURL returns the last requested URL (non-CGO build approximation).
88func (w *WebView) GetCurrentURL() string { return w.url }
89
90// GoBack is not supported in the non-CGO stub.
91func (w *WebView) GoBack() error { return ErrNotImplemented }
92
93// GoForward is not supported in the non-CGO stub.
94func (w *WebView) GoForward() error { return ErrNotImplemented }
95
96// ShowDevTools is a no-op in the non-CGO build.
97func (w *WebView) ShowDevTools() error { return nil }
98
99// CloseDevTools is a no-op in the non-CGO build.
100func (w *WebView) CloseDevTools() error { return nil }
101
102// RegisterScriptMessageHandler registers a callback invoked when the content script posts a message.
103func (w *WebView) RegisterScriptMessageHandler(cb func(payload string)) { w.msgHandler = cb }
104
105func (w *WebView) dispatchScriptMessage(payload string) {
106	if w != nil && w.msgHandler != nil {
107		w.msgHandler(payload)
108	}
109}
110
111// RegisterTitleChangedHandler registers a callback invoked when the page title changes.
112func (w *WebView) RegisterTitleChangedHandler(cb func(title string)) { w.titleHandler = cb }
113
114func (w *WebView) dispatchTitleChanged(title string) {
115	if w != nil && w.titleHandler != nil {
116		w.titleHandler(title)
117	}
118}
119
120// RegisterURIChangedHandler registers a callback invoked when the current page URI changes.
121func (w *WebView) RegisterURIChangedHandler(cb func(uri string)) { w.uriHandler = cb }
122
123func (w *WebView) dispatchURIChanged(uri string) {
124	if w != nil && w.uriHandler != nil {
125		w.uriHandler(uri)
126	}
127}
128
129// RegisterZoomChangedHandler registers a callback invoked when zoom level changes.
130func (w *WebView) RegisterZoomChangedHandler(cb func(level float64)) { w.zoomHandler = cb }
131
132func (w *WebView) dispatchZoomChanged(level float64) {
133	if w != nil && w.zoomHandler != nil {
134		w.zoomHandler(level)
135	}
136}

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