Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\t is not displayed correctly in preview #223

Open
po3rin opened this issue Jul 28, 2024 · 0 comments
Open

\t is not displayed correctly in preview #223

po3rin opened this issue Jul 28, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@po3rin
Copy link

po3rin commented Jul 28, 2024

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 po3rin added the bug Something isn't working label Jul 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant