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.

None yet

1 participant