mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-10 14:14:48 +02:00
Code to query terminal for capabilities
This commit is contained in:
@@ -57,6 +57,10 @@ type Loop struct {
|
||||
style_ctx style.Context
|
||||
atomic_update_active bool
|
||||
pointer_shapes []PointerShape
|
||||
waiting_for_capabilities_response bool
|
||||
|
||||
// Queried capabilities from terminal
|
||||
TerminalCapabilities TerminalCapabilities
|
||||
|
||||
// Suspend the loop restoring terminal state, and run the provided function. When it returns terminal state is
|
||||
// put back to what it was before suspending unless the function returns an error or an error occurs saving/restoring state.
|
||||
@@ -111,6 +115,9 @@ type Loop struct {
|
||||
|
||||
// Called on SIGTERM return true if you wish to handle it yourself
|
||||
OnSIGTERM func() (bool, error)
|
||||
|
||||
// Called when capabilities response is received
|
||||
OnCapabilitiesReceived func(TerminalCapabilities)
|
||||
}
|
||||
|
||||
func New(options ...func(self *Loop)) (*Loop, error) {
|
||||
@@ -538,3 +545,15 @@ func (self *Loop) CurrentPointerShape() (ans PointerShape, has_shape bool) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Query the terminal for various capabilities, the OnCapabilitiesReceived
|
||||
// callback will be called once the query response is received. This
|
||||
// function should be called as early as possible ideally in OnInitialize.
|
||||
func (self *Loop) QueryCapabilities() {
|
||||
if !self.waiting_for_capabilities_response {
|
||||
self.waiting_for_capabilities_response = true
|
||||
self.StartAtomicUpdate()
|
||||
self.QueueWriteString("\x1b[?u\x1b[?996n\x1b[c")
|
||||
self.EndAtomicUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user