I'm using fzf to select objects in a list, so i thought of passing the STDIN of Formcars(),and passed it to fzf as a buffer.
code:
func Formcars() {
..... //some code
for _, res := range resp.Automobiles {
..... // some code
continue
}
for _, car := range res.Types {
..... // some code
continue
}
cars = []string{
*car.Engine
*car.Type,
*car.Date,
*car.Reg,
}
fmt.Println(strings.Join(cars, " | "))
}
}
}
func Filter() string {
stdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
Formcars()
ChnOut := make(chan string)
go func() {
var buf bytes.Buffer
io.Copy(&buf, r)
ChnOut <- buf.String()
}()
w.Close()
os.Stdout = stdout
str := <-ChnOut
cmd := exec.Command("fzf", "--multi")
out := bytes.NewBufferString(str)
cmd.Stdin = out
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
fmt.Println(err.Error())
}
return strings.Join(cars, " | ")
}
func main() {
str := strings.Split(Filter(), " | ")
fmt.Println(str[0], str[1], str[2]) //for debugging purpose
}
If i select a line in the fuzzy list it ignores that and chooses just first one, must be a wrong logic but can't figure out what's wrong