forked from fyne-io/terminal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapc.go
33 lines (27 loc) · 788 Bytes
/
apc.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
package terminal
import (
"log"
"strings"
)
// APCHandler handles a APC command for the given terminal.
type APCHandler func(*Terminal, string)
var apcHandlers = map[string]func(*Terminal, string){}
func (t *Terminal) handleAPC(code string) {
for apcCommand, handler := range apcHandlers {
if strings.HasPrefix(code, apcCommand) {
// Extract the argument from the code
arg := code[len(apcCommand):]
// Invoke the corresponding handler function
handler(t, arg)
return
}
}
if t.debug {
// Handle other APC sequences or log the received APC code
log.Println("Unrecognised APC", code)
}
}
// RegisterAPCHandler registers a APC handler for the given APC command string.
func RegisterAPCHandler(APC string, handler APCHandler) {
apcHandlers[APC] = handler
}