Skip to content

Conversation

quackduck
Copy link

I noticed that option+ (move right by word), option+ (move left by word) and option+delete (delete by word) weren't working, at least on macOS. Used raw mode and some debugging to figure out what escape codes were being signaled.

This PR also removes two unnecessary checks for whether the first byte is the escape character. (Unnecessary because the function returns earlier if the first byte isn't the escape character)

Sample program to see the change this PR makes:
Run this and then compare how alt-right, alt-left and alt-delete work with this change and without.

package main

import (
	"fmt"
	"os"

	"golang.org/x/term"
)

func main() {
	fmt.Println("Use q to quit")
	oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
	if err != nil {
		panic(err)
	}
	defer term.Restore(int(os.Stdin.Fd()), oldState)

	t := term.NewTerminal(os.Stdin, "> ")
	for {
		line, err := t.ReadLine()
		if err != nil {
			fmt.Println(err)
			break
		}
		if line == "q" {
			break
		}
		t.Write([]byte(line + "\n"))
	}
}

@gopherbot
Copy link
Contributor

This PR (HEAD: 61c0997) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/term/+/383594 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

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.

2 participants