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

Fix broken spacing for each row of completion area #243

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

raccoonback
Copy link

We tried to use Emoji, but we found that each row in the completion area was pushed back as shown in the following issue.

Related issue: #209

# Error case
md > 
           🎨    Store the username and age             
                ⚡️  Store the article text posted by user  
                   🔥    Store the text commented to articles   
                        🐛    Store the text commented to articles   
                             ✨    Store the text commented to articles   
                                 📝    Store the text commented to articles   

# Solved case
md > 🚧
      🎉    Store the text commented to articles   
      ✅    Store the text commented to articles   
      🔒    Store the text commented to articles   
      🔖    Store the text commented to articles   
      🚨    Store the text commented to articles   
      🚧    Store the text commented to articles   

Therefore, I applied carriage return to specify the initial cursor of all rows at the column interval of the initial cursor.

In addition, we applied carriage return before moving the prefix to the current cursor column, so that the prefix does not look redundant.

# init state
abcdefghi > 
             🎉    Store the text commented to articles   
             ✅    Store the text commented to articles   
             🔒    Store the text commented to articles   
             🔖    Store the text commented to articles   
             🚨    Store the text commented to articles   
             🚧    Store the text commented to articles   

# error case
aabcdefghi > 🌱        // The 'a' of old prefix  remains.
             🥅    Store the text commented to articles   
             🚩    Store the text commented to articles   
             🌱    Store the text commented to articles   
             🏷     Store the text commented to articles   
             🔍    Store the text commented to articles   
             ⚗     Store the text commented to articles   

@raccoonback
Copy link
Author

You can test it with the code below.

package main

import (
	"fmt"
	"github.com/c-bata/go-prompt"
)

func completer(d prompt.Document) []prompt.Suggest {
	s := []prompt.Suggest{
		{Text: "🎨", Description: "Store the username and age"},
		{Text: "⚡️", Description: "Store the article text posted by user"},
		{Text: "🔥", Description: "Store the text commented to articles"},
		{Text: "🐛", Description: "Store the text commented to articles"},
		{Text: "✨", Description: "Store the text commented to articles"},
		{Text: "📝", Description: "Store the text commented to articles"},
		{Text: "🚀", Description: "Store the text commented to articles"},
		{Text: "💄", Description: "Store the text commented to articles"},
		{Text: "🎉", Description: "Store the text commented to articles"},
		{Text: "✅", Description: "Store the text commented to articles"},
		{Text: "🔒", Description: "Store the text commented to articles"},
		{Text: "🔖", Description: "Store the text commented to articles"},
		{Text: "🚨", Description: "Store the text commented to articles"},
		{Text: "🚧", Description: "Store the text commented to articles"},
		{Text: "💚", Description: "Store the text commented to articles"},
		{Text: "⬇", Description: "Store the text commented to articles"},
		{Text: "⬆", Description: "Store the text commented to articles"},
		{Text: "📌", Description: "Store the text commented to articles"},
		{Text: "👷", Description: "Store the text commented to articles"},
		{Text: "📈", Description: "Store the text commented to articles"},
		{Text: "♻", Description: "Store the text commented to articles"},
		{Text: "➕", Description: "Store the text commented to articles"},
		{Text: "➖", Description: "Store the text commented to articles"},
		{Text: "🔧", Description: "Store the text commented to articles"},
		{Text: "🌐", Description: "Store the text commented to articles"},
		//
		{Text: "✏️", Description: "Store the text commented to articles"},
		{Text: "💩", Description: "Store the text commented to articles"},
		{Text: "⏪", Description: "Store the text commented to articles"},
		{Text: "📦", Description: "Store the text commented to articles"},
		{Text: "👽", Description: "Store the text commented to articles"},
		{Text: "🚚", Description: "Store the text commented to articles"},
		{Text: "💥", Description: "Store the text commented to articles"},
		{Text: "♿", Description: "Store the text commented to articles"},
		{Text: "🍱", Description: "Store the text commented to articles"},
		{Text: "💡", Description: "Store the text commented to articles"},
		{Text: "💬", Description: "Store the text commented to articles"},
		{Text: "🗑️", Description: "Store the text commented to articles"},
		{Text: "💫", Description: "Store the text commented to articles"},
		{Text: "🥅", Description: "Store the text commented to articles"},
		{Text: "🚩", Description: "Store the text commented to articles"},
		{Text: "🌱", Description: "Store the text commented to articles"},
		{Text: "🏷", Description: "Store the text commented to articles"},
		{Text: "🔍", Description: "Store the text commented to articles"},
		{Text: "⚗", Description: "Store the text commented to articles"},
		{Text: "📸", Description: "Store the text commented to articles"},
		{Text: "🙈", Description: "Store the text commented to articles"},
		{Text: "🥚", Description: "Store the text commented to articles"},
		{Text: "🤡", Description: "Store the text commented to articles"},
		{Text: "📱", Description: "Store the text commented to articles"},
		{Text: "🏗", Description: "Store the text commented to articles"},
		{Text: "🚸", Description: "Store the text commented to articles"},
		{Text: "👥", Description: "Store the text commented to articles"},
		{Text: "🔇", Description: "Store the text commented to articles"},
		{Text: "🔊", Description: "Store the text commented to articles"},
		{Text: "🗃", Description: "Store the text commented to articles"},
		{Text: "💬", Description: "Store the text commented to articles"},
		{Text: "🍻", Description: "Store the text commented to articles"},
		{Text: "💡", Description: "Store the text commented to articles"},
		{Text: "♿", Description: "Store the text commented to articles"},
		{Text: "📄", Description: "Store the text commented to articles"},
	}
	return prompt.FilterHasPrefix(s, d.GetWordBeforeCursor(), true)
}

func main() {
	fmt.Println("Please select table.")
	t := prompt.Input("abcdefgi > ", completer, prompt.OptionShowCompletionAtStart(),
		prompt.OptionCompletionOnDown(),)
	fmt.Println("You selected " + t)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant