v0.2.0 759cc92

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}
23
24// NewWebView constructs a new WebView instance.
25func NewWebView(cfg *Config) (*WebView, error) {
26    if cfg == nil {
27        cfg = &Config{}
28    }
29    log.Printf("[webkit] NewWebView (non-CGO stub) — UI will not be displayed. Build with -tags=webkit_cgo for native window.")
30    wv := &WebView{config: cfg}
31    if cfg.ZoomDefault <= 0 {
32        wv.zoom = 1.0
33    } else {
34        wv.zoom = cfg.ZoomDefault
35    }
36    // Construction succeeds; create a logical window placeholder.
37    wv.window = &Window{Title: "Dumber Browser"}
38    return wv, nil
39}
40
41// LoadURL navigates the webview to the specified URL.
42func (w *WebView) LoadURL(rawURL string) error {
43    if w == nil || w.destroyed {
44        return ErrNotImplemented
45    }
46    if rawURL == "" {
47        return fmt.Errorf("url cannot be empty")
48    }
49    // Minimal validation; actual navigation handled by CGO bridge later.
50    w.url = rawURL
51    log.Printf("[webkit] LoadURL (non-CGO stub): %s", rawURL)
52    return nil
53}
54
55// Show makes the WebView visible.
56func (w *WebView) Show() error {
57    if w == nil || w.destroyed {
58        return ErrNotImplemented
59    }
60    w.visible = true
61    log.Printf("[webkit] Show (non-CGO stub): no native window will appear")
62    return nil
63}
64
65// Hide hides the WebView window.
66func (w *WebView) Hide() error {
67    if w == nil || w.destroyed {
68        return ErrNotImplemented
69    }
70    w.visible = false
71    return nil
72}
73
74// Destroy releases native resources.
75func (w *WebView) Destroy() error {
76    if w == nil {
77        return ErrNotImplemented
78    }
79    w.destroyed = true
80    return nil
81}
82
83// Window returns the associated native window wrapper (non-nil).
84func (w *WebView) Window() *Window { return w.window }
85
86// GetCurrentURL returns the last requested URL (non-CGO build approximation).
87func (w *WebView) GetCurrentURL() string { return w.url }
88
89// GoBack is not supported in the non-CGO stub.
90func (w *WebView) GoBack() error { return ErrNotImplemented }
91// GoForward is not supported in the non-CGO stub.
92func (w *WebView) GoForward() error { return ErrNotImplemented }
93
94// ShowDevTools is a no-op in the non-CGO build.
95func (w *WebView) ShowDevTools() error { return nil }
96// CloseDevTools is a no-op in the non-CGO build.
97func (w *WebView) CloseDevTools() error { return nil }
98
99// RegisterScriptMessageHandler registers a callback invoked when the content script posts a message.
100func (w *WebView) RegisterScriptMessageHandler(cb func(payload string)) { w.msgHandler = cb }
101
102func (w *WebView) dispatchScriptMessage(payload string) {
103    if w != nil && w.msgHandler != nil { w.msgHandler(payload) }
104}
105
106// RegisterTitleChangedHandler registers a callback invoked when the page title changes.
107func (w *WebView) RegisterTitleChangedHandler(cb func(title string)) { w.titleHandler = cb }
108
109func (w *WebView) dispatchTitleChanged(title string) {
110    if w != nil && w.titleHandler != nil { w.titleHandler(title) }
111}
112
113// RegisterURIChangedHandler registers a callback invoked when the current page URI changes.
114func (w *WebView) RegisterURIChangedHandler(cb func(uri string)) { w.uriHandler = cb }
115
116func (w *WebView) dispatchURIChanged(uri string) {
117    if w != nil && w.uriHandler != nil { w.uriHandler(uri) }
118}

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