mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
More linter fixes
This commit is contained in:
@@ -38,14 +38,14 @@ func DetectSupport(timeout time.Duration) (memory, files, direct bool, err error
|
|||||||
}
|
}
|
||||||
if len(shm_files_to_delete) > 0 && transfer_by_memory != supported {
|
if len(shm_files_to_delete) > 0 && transfer_by_memory != supported {
|
||||||
for _, name := range shm_files_to_delete {
|
for _, name := range shm_files_to_delete {
|
||||||
name.Unlink()
|
_ = name.Unlink()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
lp.OnInitialize = func() (string, error) {
|
lp.OnInitialize = func() (string, error) {
|
||||||
var iid uint32
|
var iid uint32
|
||||||
lp.AddTimer(timeout, false, func(loop.IdType) error {
|
_, _ = lp.AddTimer(timeout, false, func(loop.IdType) error {
|
||||||
return fmt.Errorf("Timed out waiting for a response form the terminal: %w", os.ErrDeadlineExceeded)
|
return fmt.Errorf("Timed out waiting for a response form the terminal: %w", os.ErrDeadlineExceeded)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ func DetectSupport(timeout time.Duration) (memory, files, direct bool, err error
|
|||||||
g1 := &graphics.GraphicsCommand{}
|
g1 := &graphics.GraphicsCommand{}
|
||||||
g1.SetTransmission(t).SetAction(graphics.GRT_action_query).SetImageId(iid).SetDataWidth(1).SetDataHeight(1).SetFormat(
|
g1.SetTransmission(t).SetAction(graphics.GRT_action_query).SetImageId(iid).SetDataWidth(1).SetDataHeight(1).SetFormat(
|
||||||
graphics.GRT_format_rgb).SetDataSize(uint64(len(payload)))
|
graphics.GRT_format_rgb).SetDataSize(uint64(len(payload)))
|
||||||
g1.WriteWithPayloadToLoop(lp, utils.UnsafeStringToBytes(payload))
|
_ = g1.WriteWithPayloadToLoop(lp, utils.UnsafeStringToBytes(payload))
|
||||||
return iid
|
return iid
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +63,9 @@ func DetectSupport(timeout time.Duration) (memory, files, direct bool, err error
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
file_query_id = g(graphics.GRT_transmission_tempfile, tf.Name())
|
file_query_id = g(graphics.GRT_transmission_tempfile, tf.Name())
|
||||||
temp_files_to_delete = append(temp_files_to_delete, tf.Name())
|
temp_files_to_delete = append(temp_files_to_delete, tf.Name())
|
||||||
tf.Write([]byte{1, 2, 3})
|
if _, err = tf.Write([]byte{1, 2, 3}); err != nil {
|
||||||
|
print_error("Failed to write to temporary file for data transfer, file based transfer is disabled. Error: %v", err)
|
||||||
|
}
|
||||||
tf.Close()
|
tf.Close()
|
||||||
} else {
|
} else {
|
||||||
print_error("Failed to create temporary file for data transfer, file based transfer is disabled. Error: %v", err)
|
print_error("Failed to create temporary file for data transfer, file based transfer is disabled. Error: %v", err)
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ const (
|
|||||||
supported
|
supported
|
||||||
)
|
)
|
||||||
|
|
||||||
var transfer_by_file, transfer_by_memory, transfer_by_stream transfer_mode
|
var transfer_by_file, transfer_by_memory transfer_mode
|
||||||
|
|
||||||
var files_channel chan input_arg
|
var files_channel chan input_arg
|
||||||
var output_channel chan *image_data
|
var output_channel chan *image_data
|
||||||
@@ -162,7 +162,9 @@ func main(cmd *cli.Command, o *Options, args []string) (rc int, err error) {
|
|||||||
if opts.Clear {
|
if opts.Clear {
|
||||||
cc := &graphics.GraphicsCommand{}
|
cc := &graphics.GraphicsCommand{}
|
||||||
cc.SetAction(graphics.GRT_action_delete).SetDelete(graphics.GRT_free_visible)
|
cc.SetAction(graphics.GRT_action_delete).SetDelete(graphics.GRT_free_visible)
|
||||||
cc.WriteWithPayloadTo(os.Stdout, nil)
|
if err = cc.WriteWithPayloadTo(os.Stdout, nil); err != nil {
|
||||||
|
return 1, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if screen_size.Xpixel == 0 || screen_size.Ypixel == 0 {
|
if screen_size.Xpixel == 0 || screen_size.Ypixel == 0 {
|
||||||
return 1, fmt.Errorf("Terminal does not support reporting screen sizes in pixels, use a terminal such as kitty, WezTerm, Konsole, etc. that does.")
|
return 1, fmt.Errorf("Terminal does not support reporting screen sizes in pixels, use a terminal such as kitty, WezTerm, Konsole, etc. that does.")
|
||||||
@@ -224,7 +226,6 @@ func main(cmd *cli.Command, o *Options, args []string) (rc int, err error) {
|
|||||||
// tmux doesn't allow responses from the terminal so we can't detect if memory or file based transferring is supported
|
// tmux doesn't allow responses from the terminal so we can't detect if memory or file based transferring is supported
|
||||||
transfer_by_memory = unsupported
|
transfer_by_memory = unsupported
|
||||||
transfer_by_file = unsupported
|
transfer_by_file = unsupported
|
||||||
transfer_by_stream = supported
|
|
||||||
}
|
}
|
||||||
if opts.DetectSupport {
|
if opts.DetectSupport {
|
||||||
if transfer_by_memory == supported {
|
if transfer_by_memory == supported {
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ func load_one_frame_image(ctx *images.Context, imgd *image_data, src *opened_inp
|
|||||||
}
|
}
|
||||||
|
|
||||||
var debugprintln = tty.DebugPrintln
|
var debugprintln = tty.DebugPrintln
|
||||||
|
var _ = debugprintln
|
||||||
|
|
||||||
func (frame *image_frame) set_disposal(anchor_frame int, disposal byte) int {
|
func (frame *image_frame) set_disposal(anchor_frame int, disposal byte) int {
|
||||||
anchor_frame, frame.compose_onto = images.SetGIFFrameDisposal(frame.number, anchor_frame, disposal)
|
anchor_frame, frame.compose_onto = images.SetGIFFrameDisposal(frame.number, anchor_frame, disposal)
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ func process_dirs(args ...string) (results []input_arg, err error) {
|
|||||||
return nil, &fs.PathError{Op: "Stat", Path: arg, Err: err}
|
return nil, &fs.PathError{Op: "Stat", Path: arg, Err: err}
|
||||||
}
|
}
|
||||||
if s.IsDir() {
|
if s.IsDir() {
|
||||||
filepath.WalkDir(arg, func(path string, d fs.DirEntry, walk_err error) error {
|
if err = filepath.WalkDir(arg, func(path string, d fs.DirEntry, walk_err error) error {
|
||||||
if walk_err != nil {
|
if walk_err != nil {
|
||||||
if d == nil {
|
if d == nil {
|
||||||
err = &fs.PathError{Op: "Stat", Path: arg, Err: walk_err}
|
err = &fs.PathError{Op: "Stat", Path: arg, Err: walk_err}
|
||||||
@@ -107,7 +107,9 @@ func process_dirs(args ...string) (results []input_arg, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
results = append(results, input_arg{arg: arg, value: arg})
|
results = append(results, input_arg{arg: arg, value: arg})
|
||||||
}
|
}
|
||||||
@@ -124,7 +126,7 @@ type opened_input struct {
|
|||||||
|
|
||||||
func (self *opened_input) Rewind() {
|
func (self *opened_input) Rewind() {
|
||||||
if self.file != nil {
|
if self.file != nil {
|
||||||
self.file.Seek(0, io.SeekStart)
|
_, _ = self.file.Seek(0, io.SeekStart)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ func transmit_shm(imgd *image_data, frame_num int, frame *image_frame) (err erro
|
|||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
data_size, _ = f.Seek(0, io.SeekEnd)
|
data_size, _ = f.Seek(0, io.SeekEnd)
|
||||||
f.Seek(0, io.SeekStart)
|
_, _ = f.Seek(0, io.SeekStart)
|
||||||
mmap, err = shm.CreateTemp("icat-*", uint64(data_size))
|
mmap, err = shm.CreateTemp("icat-*", uint64(data_size))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to create a SHM file for transmission: %w", err)
|
return fmt.Errorf("Failed to create a SHM file for transmission: %w", err)
|
||||||
@@ -108,7 +108,7 @@ func transmit_shm(imgd *image_data, frame_num int, frame *image_frame) (err erro
|
|||||||
if errors.Is(err, io.EOF) {
|
if errors.Is(err, io.EOF) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
mmap.Unlink()
|
_ = mmap.Unlink()
|
||||||
return fmt.Errorf("Failed to read data from image output data file: %w", err)
|
return fmt.Errorf("Failed to read data from image output data file: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,10 +128,10 @@ func transmit_shm(imgd *image_data, frame_num int, frame *image_frame) (err erro
|
|||||||
gc := gc_for_image(imgd, frame_num, frame)
|
gc := gc_for_image(imgd, frame_num, frame)
|
||||||
gc.SetTransmission(graphics.GRT_transmission_sharedmem)
|
gc.SetTransmission(graphics.GRT_transmission_sharedmem)
|
||||||
gc.SetDataSize(uint64(data_size))
|
gc.SetDataSize(uint64(data_size))
|
||||||
gc.WriteWithPayloadTo(os.Stdout, utils.UnsafeStringToBytes(mmap.Name()))
|
err = gc.WriteWithPayloadTo(os.Stdout, utils.UnsafeStringToBytes(mmap.Name()))
|
||||||
mmap.Close()
|
mmap.Close()
|
||||||
|
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func transmit_file(imgd *image_data, frame_num int, frame *image_frame) (err error) {
|
func transmit_file(imgd *image_data, frame_num int, frame *image_frame) (err error) {
|
||||||
@@ -174,8 +174,7 @@ func transmit_file(imgd *image_data, frame_num int, frame *image_frame) (err err
|
|||||||
if data_size > 0 {
|
if data_size > 0 {
|
||||||
gc.SetDataSize(uint64(data_size))
|
gc.SetDataSize(uint64(data_size))
|
||||||
}
|
}
|
||||||
gc.WriteWithPayloadTo(os.Stdout, utils.UnsafeStringToBytes(fname))
|
return gc.WriteWithPayloadTo(os.Stdout, utils.UnsafeStringToBytes(fname))
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func transmit_stream(imgd *image_data, frame_num int, frame *image_frame) (err error) {
|
func transmit_stream(imgd *image_data, frame_num int, frame *image_frame) (err error) {
|
||||||
@@ -192,8 +191,7 @@ func transmit_stream(imgd *image_data, frame_num int, frame *image_frame) (err e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
gc := gc_for_image(imgd, frame_num, frame)
|
gc := gc_for_image(imgd, frame_num, frame)
|
||||||
gc.WriteWithPayloadTo(os.Stdout, data)
|
return gc.WriteWithPayloadTo(os.Stdout, data)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculate_in_cell_x_offset(width, cell_width int) int {
|
func calculate_in_cell_x_offset(width, cell_width int) int {
|
||||||
@@ -291,7 +289,7 @@ func transmit_image(imgd *image_data) {
|
|||||||
frame.filename = ""
|
frame.filename = ""
|
||||||
}
|
}
|
||||||
if frame.shm != nil {
|
if frame.shm != nil {
|
||||||
frame.shm.Unlink()
|
_ = frame.shm.Unlink()
|
||||||
frame.shm.Close()
|
frame.shm.Close()
|
||||||
frame.shm = nil
|
frame.shm = nil
|
||||||
}
|
}
|
||||||
@@ -386,11 +384,15 @@ func transmit_image(imgd *image_data) {
|
|||||||
case opts.Loop > 0:
|
case opts.Loop > 0:
|
||||||
c.SetNumberOfLoops(uint64(opts.Loop) + 1)
|
c.SetNumberOfLoops(uint64(opts.Loop) + 1)
|
||||||
}
|
}
|
||||||
c.WriteWithPayloadTo(os.Stdout, nil)
|
if imgd.err = c.WriteWithPayloadTo(os.Stdout, nil); imgd.err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
case 1:
|
case 1:
|
||||||
c := frame_control_cmd
|
c := frame_control_cmd
|
||||||
c.SetAnimationControl(2) // set animation to loading mode
|
c.SetAnimationControl(2) // set animation to loading mode
|
||||||
c.WriteWithPayloadTo(os.Stdout, nil)
|
if imgd.err = c.WriteWithPayloadTo(os.Stdout, nil); imgd.err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -400,7 +402,9 @@ func transmit_image(imgd *image_data) {
|
|||||||
if is_animated {
|
if is_animated {
|
||||||
c := frame_control_cmd
|
c := frame_control_cmd
|
||||||
c.SetAnimationControl(3) // set animation to normal mode
|
c.SetAnimationControl(3) // set animation to normal mode
|
||||||
c.WriteWithPayloadTo(os.Stdout, nil)
|
if imgd.err = c.WriteWithPayloadTo(os.Stdout, nil); imgd.err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if imgd.move_to.x == 0 {
|
if imgd.move_to.x == 0 {
|
||||||
fmt.Println() // ensure cursor is on new line
|
fmt.Println() // ensure cursor is on new line
|
||||||
|
|||||||
Reference in New Issue
Block a user