diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2024-05-07 16:58:17 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2024-05-07 16:58:17 +0900 |
| commit | 4bedd33c593ab0cb750e17c42750048904fdf7fb (patch) | |
| tree | 10ef749a51b1b947f5bb34eb154c5f992a50edbb /src/functions.go | |
| parent | c5fb0c43f9222e72ff00290162b68e34a8f0d5d7 (diff) | |
| download | fzf-4bedd33c593ab0cb750e17c42750048904fdf7fb.tar.gz | |
Refactor the code to remove global variables
Diffstat (limited to 'src/functions.go')
| -rw-r--r-- | src/functions.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/functions.go b/src/functions.go new file mode 100644 index 00000000..f16371a2 --- /dev/null +++ b/src/functions.go @@ -0,0 +1,35 @@ +package fzf + +import ( + "os" + "strings" + "unsafe" +) + +func writeTemporaryFile(data []string, printSep string) string { + f, err := os.CreateTemp("", "fzf-preview-*") + if err != nil { + // Unable to create temporary file + // FIXME: Should we terminate the program? + return "" + } + defer f.Close() + + f.WriteString(strings.Join(data, printSep)) + f.WriteString(printSep) + return f.Name() +} + +func removeFiles(files []string) { + for _, filename := range files { + os.Remove(filename) + } +} + +func stringBytes(data string) []byte { + return unsafe.Slice(unsafe.StringData(data), len(data)) +} + +func byteString(data []byte) string { + return unsafe.String(unsafe.SliceData(data), len(data)) +} |
