mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-08 01:53:35 +02:00
Move roundtrip on exit flag into terminal options to have a consistent API
This commit is contained in:
@@ -33,7 +33,7 @@ func do_chunked_io(io_data *rc_io_data) (serialized_response []byte, err error)
|
||||
}
|
||||
if io_data.on_key_event != nil {
|
||||
lp.FullKeyboardProtocol()
|
||||
lp.NoRoundtripToTerminalOnExit = false
|
||||
lp.NoRoundtripToTerminalOnExit()
|
||||
} else {
|
||||
lp.NoKeyboardStateChange()
|
||||
}
|
||||
|
||||
@@ -62,13 +62,6 @@ type Loop struct {
|
||||
// Queried capabilities from terminal
|
||||
TerminalCapabilities TerminalCapabilities
|
||||
|
||||
// Set this to true to avoid doing a query response loop to the terminal at
|
||||
// exit. This loop is needed for most kittens to ensure that in-flight
|
||||
// responses such as in-band resize notifications, color queries, kitty
|
||||
// keyboard events, etc. are not leaked to the shell. For some special
|
||||
// purpose uses of the loop, this is not appropriate, hence this setting.
|
||||
NoRoundtripToTerminalOnExit bool
|
||||
|
||||
// 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.
|
||||
SuspendAndRun func(func() error) error
|
||||
@@ -147,10 +140,9 @@ func New(options ...func(self *Loop)) (*Loop, error) {
|
||||
func NewForSimpleInteraction() (*Loop, error) {
|
||||
lp, err := New(
|
||||
NoAlternateScreen, NoRestoreColors, NoMouseTracking, NoInBandResizeNotifications,
|
||||
NoFocusTracking, NoKeyboardStateChange,
|
||||
NoFocusTracking, NoKeyboardStateChange, NoRoundtripToTerminalOnExit,
|
||||
)
|
||||
if err == nil {
|
||||
lp.NoRoundtripToTerminalOnExit = true
|
||||
lp.terminal_options.color_scheme_change_notification = false
|
||||
}
|
||||
return lp, err
|
||||
@@ -177,6 +169,15 @@ func NoAlternateScreen(self *Loop) {
|
||||
self.terminal_options.Alternate_screen = false
|
||||
}
|
||||
|
||||
func (self *Loop) NoRoundtripToTerminalOnExit() *Loop {
|
||||
self.terminal_options.roundtrip_on_exit = false
|
||||
return self
|
||||
}
|
||||
|
||||
func NoRoundtripToTerminalOnExit(self *Loop) {
|
||||
self.terminal_options.roundtrip_on_exit = false
|
||||
}
|
||||
|
||||
func (self *Loop) OnlyDisambiguateKeys() *Loop {
|
||||
self.terminal_options.kitty_keyboard_mode = DISAMBIGUATE_KEYS
|
||||
return self
|
||||
|
||||
@@ -30,6 +30,7 @@ func new_loop() *Loop {
|
||||
l.terminal_options.in_band_resize_notification = true
|
||||
l.terminal_options.color_scheme_change_notification = false
|
||||
l.terminal_options.kitty_keyboard_mode = DISAMBIGUATE_KEYS | REPORT_ALTERNATE_KEYS | REPORT_ALL_KEYS_AS_ESCAPE_CODES | REPORT_TEXT_WITH_KEYS
|
||||
l.terminal_options.roundtrip_on_exit = true
|
||||
l.escape_code_parser.HandleCSI = l.handle_csi
|
||||
l.escape_code_parser.HandleOSC = l.handle_osc
|
||||
l.escape_code_parser.HandleDCS = l.handle_dcs
|
||||
@@ -452,7 +453,7 @@ func (self *Loop) run() (err error) {
|
||||
case <-tty_leftover_read_channel:
|
||||
default:
|
||||
}
|
||||
if !self.NoRoundtripToTerminalOnExit {
|
||||
if self.terminal_options.roundtrip_on_exit {
|
||||
// ensure that any terminal responses such as kitty keyboard events,
|
||||
// color scheme changes, in-band resize notifications, etc. do not
|
||||
// bleed into the shell.
|
||||
|
||||
@@ -106,6 +106,12 @@ type TerminalStateOptions struct {
|
||||
in_band_resize_notification bool
|
||||
focus_tracking bool
|
||||
color_scheme_change_notification bool
|
||||
// Set this to true to avoid doing a query response loop to the terminal at
|
||||
// exit. This loop is needed for most kittens to ensure that in-flight
|
||||
// responses such as in-band resize notifications, color queries, kitty
|
||||
// keyboard events, etc. are not leaked to the shell. For some special
|
||||
// purpose uses of the loop, this is not appropriate, hence this setting.
|
||||
roundtrip_on_exit bool
|
||||
}
|
||||
|
||||
func set_modes(sb *strings.Builder, modes ...Mode) {
|
||||
|
||||
Reference in New Issue
Block a user