From 71a2d7359af29df35f8ef52fc53f2556a4f3668b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 1 Sep 2023 19:41:46 +0530 Subject: [PATCH] Function to extract terminfo --- tools/tui/shell_integration/api.go | 16 ++++++++++++++-- tools/tui/shell_integration/api_test.go | 7 +++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/tools/tui/shell_integration/api.go b/tools/tui/shell_integration/api.go index df612733e..3dd133c16 100644 --- a/tools/tui/shell_integration/api.go +++ b/tools/tui/shell_integration/api.go @@ -20,9 +20,9 @@ var _ = fmt.Print type integration_setup_func = func(shell_integration_dir string, argv []string, env map[string]string) ([]string, map[string]string, error) -func extract_shell_integration_for(shell_name string, dest_dir string) (err error) { +func extract_files(match, dest_dir string) (err error) { d := Data() - for _, fname := range d.FilesMatching("shell-integration/" + shell_name + "/") { + for _, fname := range d.FilesMatching(match) { entry := d[fname] dest := filepath.Join(dest_dir, fname) ddir := filepath.Dir(dest) @@ -50,6 +50,18 @@ func extract_shell_integration_for(shell_name string, dest_dir string) (err erro return } +func extract_shell_integration_for(shell_name string, dest_dir string) (err error) { + return extract_files("shell-integration/"+shell_name+"/", dest_dir) +} + +func extract_terminfo(dest_dir string) (err error) { + if err = extract_files("terminfo/", dest_dir); err == nil { + dest := filepath.Join(dest_dir, "terminfo", "78") + err = os.Symlink("x", dest) + } + return +} + func EnsureShellIntegrationFilesFor(shell_name string) (shell_integration_dir_for_shell string, err error) { if kid := os.Getenv("KITTY_INSTALLATION_DIR"); kid != "" { if s, e := os.Stat(kid); e == nil && s.IsDir() { diff --git a/tools/tui/shell_integration/api_test.go b/tools/tui/shell_integration/api_test.go index c53965273..23c472e3f 100644 --- a/tools/tui/shell_integration/api_test.go +++ b/tools/tui/shell_integration/api_test.go @@ -39,4 +39,11 @@ func TestExtractShellIntegration(t *testing.T) { if !bytes.Equal(changed, orig) { t.Fatalf("Failed to update shell integration file") } + + if err = extract_terminfo(tdir); err != nil { + t.Fatal(err) + } + if _, err := os.Stat(filepath.Join(tdir, "terminfo", "78", "xterm-kitty")); err != nil { + t.Fatal(err) + } }