2024-05-07 16:58:17 +09:00
|
|
|
package fzf
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2024-05-20 19:33:46 +09:00
|
|
|
func WriteTemporaryFile(data []string, printSep string) string {
|
2024-05-10 01:40:56 +09:00
|
|
|
f, err := os.CreateTemp("", "fzf-temp-*")
|
2024-05-07 16:58:17 +09:00
|
|
|
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))
|
|
|
|
}
|