go-fuzzyfinder icon indicating copy to clipboard operation
go-fuzzyfinder copied to clipboard

\t is not displayed correctly in preview

Open po3rin opened this issue 1 year ago • 0 comments

When fuzzyfinder.WithPreviewWindow returns a string containing \t, an unintended line break occurs at that position.

To reproduce

package main

import (
	"fmt"
	"log"

	"github.com/ktr0731/go-fuzzyfinder"
)

type Track struct {
	Name      string
	AlbumName string
	Artist    string
}

var tracks = []Track{
	{"foo", "album1", "artist1"},
}

func main() {
	idx, err := fuzzyfinder.FindMulti(
		tracks,
		func(i int) string {
			return tracks[i].Name
		},
		fuzzyfinder.WithPreviewWindow(func(i, w, h int) string {
			if i == -1 {
				return ""
			}
			return fmt.Sprintf("Track: %s (%s)\nAlbum\t: %s",
				tracks[i].Name,
				tracks[i].Artist,
				tracks[i].AlbumName)
		}))
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("selected: %v\n", idx)
}

preview

Track: foo (artist1) 
Album
: album1

Expected behavior

\t should be displayed as a tab

Track: foo (artist1) 
Album       : album1

Environment

  • OS: macOS Monterey
  • Terminal: iTerm2
  • go-fuzzyfinder version: v0.8.0

Additional context

This behavior is troublesome when we want to preview code that includes tabs.

Please let us know what do you think. Thank you!

po3rin avatar Jul 28 '24 18:07 po3rin