-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathprotocol.go
More file actions
70 lines (60 loc) · 1.45 KB
/
protocol.go
File metadata and controls
70 lines (60 loc) · 1.45 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
63
64
65
66
67
68
69
70
package termimg
import (
"fmt"
)
type Protocol int
const (
Unsupported Protocol = iota
Auto // Auto-detect the best protocol
ITerm2
Kitty
Sixel
Halfblocks
)
func (p Protocol) String() string {
switch p {
case Auto:
return "Auto"
case ITerm2:
return "iTerm2"
case Kitty:
return "Kitty"
case Sixel:
return "Sixel"
case Halfblocks:
return "Halfblocks"
default:
return "unsupported"
}
}
func SupportedProtocols() string {
return fmt.Sprintf("%s, %s, %s, %s", ITerm2, Kitty, Sixel, Halfblocks)
}
// DetermineProtocols returns a slice of supported protocols in the
// preferred order. We try Kitty first (richest feature-set), then iTerm2
// (mac-only but common), then Sixel (legacy but widely available).
// Halfblocks is always available as the ultimate fallback.
func DetermineProtocols() []Protocol {
protos := make([]Protocol, 0, 4)
features := QueryTerminalFeatures()
// Detection order: Kitty -> iTerm2 -> Sixel -> Halfblocks
if features.KittyGraphics {
protos = append(protos, Kitty)
}
if features.ITerm2Graphics {
protos = append(protos, ITerm2)
}
if features.SixelGraphics {
protos = append(protos, Sixel)
}
// Halfblocks is always available as the ultimate fallback
protos = append(protos, Halfblocks)
return protos
}
// DetectProtocol returns the first supported protocol
func DetectProtocol() Protocol {
if protos := DetermineProtocols(); len(protos) > 0 {
return protos[0]
}
return Unsupported
}