-
Notifications
You must be signed in to change notification settings - Fork 0
/
goqute.go
52 lines (46 loc) · 1.35 KB
/
goqute.go
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
package goqute
import (
"io"
"net/url"
"os"
)
// QuteBrowserInstance represents the single qutebrowser instance during
// the execution of the userscript. QuteBrowserInstance provides parameters set by
// qutebrowser and functionality for interacting with qutebrowser
type QuteBrowserInstance struct {
Params QBParams
Session Session
pipe io.Writer
}
// Tab represents a single qutebrowser tab
type Tab struct {
Title string
URL url.URL
}
// Notify notifies qutebrowser with given message and urgengy level
func (q QuteBrowserInstance) Notify(message string, urgency UrgencyLevel) {
q.ExecuteCommand(createNotifyMessage(message, urgency))
}
// ExecuteCommand executes any command which can be handled by qutebrowser
func (q QuteBrowserInstance) ExecuteCommand(command []byte) {
q.pipe.Write(command)
}
// NewQuteBrowserInstance returns an already intialized QuteBrowserInstance
// by reading values from environment set by qutebrowser
func NewQuteBrowserInstance() (*QuteBrowserInstance, error) {
// Create parameters from QB
params, err := CreateQBParams()
if err != nil {
return nil, err
}
// Open named pipe for communication back to qutebrowser
pipe, err := os.OpenFile(params.Fifo, os.O_RDWR, os.ModeNamedPipe)
if err != nil {
return nil, err
}
// Read current session
return &QuteBrowserInstance{
Params: *params,
pipe: pipe,
}, nil
}