manifoldco / promptui

Interactive prompt for command-line applications

Home Page:https://www.manifold.co

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BlockCursor is broken on macOS

synfinatic opened this issue · comments

Tested with both iTerm2 3.4.12 and Terminal 2.10 on macOS 10.15.7 with promptui 0.9.0 and Go 1.17.5

using:

	prompt := promptui.Prompt{
		Label:    "SSO Instance Name (DefaultSSO)",
		Validate: validateSSOName,
		Default: "Default",
		Pointer:  promptui.BlockCursor,
	}

Generates the following prompt:

SSO Instance Name (DefaultSSO): \e[7mD\e[0mefault

DefaultCursor is very painful when there is a default value since it obscures the first character, so right now that only leaves PipeCursor which is very hard to see and seems very non-standard.

I think that the solution to the problem may be to set the course for the last character of the default value. I would say that this is the most natural behavior for an input field across other UIs.

commented

I ran into similar issue cursor blocking default value and found #146

set AllowEdit: true will move cursor to the end of default value

The problem is that the escape code for ESC must be \x1b and not as is done today in cursor.go.

A fixed blockCursor is:

func blockCursor(input []rune) []rune {
  return []rune(fmt.Sprintf("\x1b[7m%s\x1b[0m", string(input)))
}