-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
62 lines (50 loc) · 1.3 KB
/
Copy pathmain.go
File metadata and controls
62 lines (50 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"bytes"
"flag"
"fmt"
"os"
"os/exec"
"time"
tea "github.com/charmbracelet/bubbletea"
)
const statusDuration = time.Second
func execWlCopy(data []byte) *exec.Cmd {
cmd := exec.Command("wl-copy")
cmd.Stdin = bytes.NewReader(data)
return cmd
}
func main() {
sourceID := flag.String("source-id", "", "Source window ID (niri window id or hyprland address)")
sourceClass := flag.String("source-class", "", "Source window app-id/class")
flag.Parse()
// Use passed-in source window, or auto-detect
var source SourceWindow
if *sourceID != "" {
source = SourceWindow{Address: *sourceID, Class: *sourceClass}
} else {
source = captureSourceWindow()
}
// Load theme
loadTheme()
// Load metadata (fast, local JSON)
meta := loadMetadata()
// Launch TUI immediately with empty entries — loads async
m := newModel(nil, meta, source)
p := tea.NewProgram(m, tea.WithAltScreen())
result, err := p.Run()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
// Clear any kitty images on exit
clearKittyImages()
// Handle paste action
if finalModel, ok := result.(model); ok && finalModel.pendingPaste != "" {
if finalModel.pendingPaste == "__snippet__" {
pasteToWindowDirect(source)
} else {
pasteToWindow(source, finalModel.pendingPaste)
}
}
}