| 1 |
package fzf |
| 2 |
|
| 3 |
import ( |
| 4 |
"os" |
| 5 |
"strings" |
| 6 |
"unsafe" |
| 7 |
) |
| 8 |
|
| 9 |
func WriteTemporaryFile(data []string, printSep string) string { |
| 10 |
f, err := os.CreateTemp("", "fzf-temp-*") |
| 11 |
if err != nil { |
| 12 |
// Unable to create temporary file |
| 13 |
// FIXME: Should we terminate the program? |
| 14 |
return "" |
| 15 |
} |
| 16 |
defer f.Close() |
| 17 |
|
| 18 |
f.WriteString(strings.Join(data, printSep)) |
| 19 |
f.WriteString(printSep) |
| 20 |
return f.Name() |
| 21 |
} |
| 22 |
|
| 23 |
func removeFiles(files []string) { |
| 24 |
for _, filename := range files { |
| 25 |
os.Remove(filename) |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
func stringBytes(data string) []byte { |
| 30 |
return unsafe.Slice(unsafe.StringData(data), len(data)) |
| 31 |
} |
| 32 |
|
| 33 |
func byteString(data []byte) string { |
| 34 |
return unsafe.String(unsafe.SliceData(data), len(data)) |
| 35 |
} |