From 65c3630099ddcb67aaf33ade0c46dcee158f3d6d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 31 Aug 2022 21:51:49 +0530 Subject: [PATCH] send_text other than from stdin works --- gen-go-code.py | 2 -- kitty/rc/send_text.py | 2 -- tools/cmd/at/main.go | 9 +++++++++ tools/cmd/at/send_text.go | 12 +++++++----- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/gen-go-code.py b/gen-go-code.py index 2aebbbb65..5d4341f6f 100755 --- a/gen-go-code.py +++ b/gen-go-code.py @@ -4,7 +4,6 @@ import io import json import os -import sys from contextlib import contextmanager, suppress from typing import Dict, Iterator, List, Set, Tuple, Union @@ -246,7 +245,6 @@ def update_at_commands() -> None: os.remove(dest) with open(dest, 'w') as f: f.write(code) - print('\x1b[31mTODO\x1b[m: test send_text, env', file=sys.stderr) def main() -> None: diff --git a/kitty/rc/send_text.py b/kitty/rc/send_text.py index 9ae5dd3fa..d39b2815f 100644 --- a/kitty/rc/send_text.py +++ b/kitty/rc/send_text.py @@ -101,8 +101,6 @@ Path to a file whose contents you wish to send. Note that in this case the file are sent as is, not interpreted for escapes. ''' args = RemoteCommand.Args(spec='[TEXT TO SEND]', json_field='data', special_parse='+session_id:parse_send_text(io_data, args)') - is_asynchronous = True - reads_streaming_data = True def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType: limit = 1024 diff --git a/tools/cmd/at/main.go b/tools/cmd/at/main.go index b9ebc55f6..a23a8649a 100644 --- a/tools/cmd/at/main.go +++ b/tools/cmd/at/main.go @@ -87,6 +87,14 @@ type wrapped_serializer struct { all_payloads_done bool } +func debug_to_log(args ...interface{}) { + f, err := os.OpenFile("/tmp/kdlog", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666) + if err == nil { + fmt.Fprintln(f, args...) + f.Close() + } +} + func (self *wrapped_serializer) next(io_data *rc_io_data) ([]byte, error) { const prefix = "\x1bP@kitty-cmd" const suffix = "\x1b\\" @@ -197,6 +205,7 @@ func get_response(do_io func(io_data *rc_io_data) ([]byte, error), io_data *rc_i if errors.Is(err, os.ErrDeadlineExceeded) { io_data.rc.Payload = nil io_data.rc.CancelAsync = true + io_data.multiple_payload_generator = nil io_data.rc.NoResponse = true io_data.serializer.state = 0 do_io(io_data) diff --git a/tools/cmd/at/send_text.go b/tools/cmd/at/send_text.go index 990170a24..c4d24f6b9 100644 --- a/tools/cmd/at/send_text.go +++ b/tools/cmd/at/send_text.go @@ -10,16 +10,18 @@ import ( "strings" ) -type generator_function func(io_data *rc_io_data) (bool, error) - func parse_send_text(io_data *rc_io_data, args []string) error { - generators := make([]generator_function, 0, 1) + generators := make([]func(io_data *rc_io_data) (bool, error), 0, 1) if len(args) > 0 { text := strings.Join(args, " ") text_gen := func(io_data *rc_io_data) (bool, error) { - set_payload_data(io_data, "text:"+text[:2048]) - text = text[2048:] + limit := len(text) + if limit > 2048 { + limit = 2048 + } + set_payload_data(io_data, "text:"+text[:limit]) + text = text[limit:] return len(text) == 0, nil } generators = append(generators, text_gen)