Function to extract terminfo

This commit is contained in:
Kovid Goyal
2023-09-01 19:41:46 +05:30
parent f1ba9f45bc
commit 71a2d7359a
2 changed files with 21 additions and 2 deletions

View File

@@ -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() {

View File

@@ -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)
}
}