mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-20 07:24:41 +02:00
DRYer
This commit is contained in:
@@ -27,19 +27,15 @@ func is_stream_response(serialized_response []byte) bool {
|
||||
|
||||
func do_chunked_io(io_data *rc_io_data) (serialized_response []byte, err error) {
|
||||
serialized_response = make([]byte, 0)
|
||||
// we cant do inbandresize notification as in the --no-response case the
|
||||
// command can cause a resize and the loop can quit before the notification
|
||||
// arrives, leading to the notification being sent to whatever is executed
|
||||
// after us. Similarly no focus tracking.
|
||||
lp, err := loop.New(loop.NoAlternateScreen, loop.NoRestoreColors, loop.NoInBandResizeNotifications, loop.NoFocusTracking)
|
||||
lp, err := loop.NewForSimpleInteraction()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if io_data.on_key_event != nil {
|
||||
lp.FullKeyboardProtocol()
|
||||
lp.NoRoundtripToTerminalOnExit = false
|
||||
} else {
|
||||
lp.NoKeyboardStateChange()
|
||||
lp.NoRoundtripToTerminalOnExit = true
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@@ -141,6 +141,21 @@ func New(options ...func(self *Loop)) (*Loop, error) {
|
||||
return l, nil
|
||||
}
|
||||
|
||||
// Create a loop that does not change terminal state such as keyboard mode,
|
||||
// resize/focus notifications, mouse tracking, alternate screen etc. Useful
|
||||
// for special purpose kittens such as icat/clipboard/@ etc.
|
||||
func NewForSimpleInteraction() (*Loop, error) {
|
||||
lp, err := New(
|
||||
NoAlternateScreen, NoRestoreColors, NoMouseTracking, NoInBandResizeNotifications,
|
||||
NoFocusTracking, NoKeyboardStateChange,
|
||||
)
|
||||
if err == nil {
|
||||
lp.NoRoundtripToTerminalOnExit = true
|
||||
lp.terminal_options.color_scheme_change_notification = false
|
||||
}
|
||||
return lp, err
|
||||
}
|
||||
|
||||
func (self *Loop) AddTimer(interval time.Duration, repeats bool, callback TimerCallback) (IdType, error) {
|
||||
return self.add_timer(interval, repeats, callback)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user