mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-17 05:54:59 +02:00
Embed the data files needed for the ssh kitten into the Go binary
This commit is contained in:
37
tools/cmd/ssh/data.go
Normal file
37
tools/cmd/ssh/data.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
|
||||
|
||||
package ssh
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"kitty/tools/utils"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
//go:embed data_generated.bin
|
||||
var embedded_data string
|
||||
|
||||
type Container = map[string][]byte
|
||||
|
||||
var Data = (&utils.Once[Container]{Run: func() Container {
|
||||
raw := utils.ReadCompressedEmbeddedData(embedded_data)
|
||||
num_of_entries := binary.LittleEndian.Uint32(raw)
|
||||
raw = raw[4:]
|
||||
ans := make(Container, num_of_entries)
|
||||
idx := bytes.IndexByte(raw, '\n')
|
||||
text := utils.UnsafeBytesToString(raw[:idx])
|
||||
raw = raw[idx+1:]
|
||||
for _, record := range strings.Split(text, ",") {
|
||||
parts := strings.Split(record, " ")
|
||||
offset, _ := strconv.Atoi(parts[1])
|
||||
size, _ := strconv.Atoi(parts[2])
|
||||
ans[parts[0]] = raw[offset : offset+size]
|
||||
}
|
||||
return ans
|
||||
}}).Get
|
||||
@@ -170,6 +170,7 @@ type connection_data struct {
|
||||
}
|
||||
|
||||
func run_ssh(ssh_args, server_args, found_extra_args []string) (rc int, err error) {
|
||||
go Data()
|
||||
cmd := append([]string{SSHExe()}, ssh_args...)
|
||||
cd := connection_data{remote_args: server_args[1:]}
|
||||
hostname := server_args[0]
|
||||
|
||||
Reference in New Issue
Block a user