Skip to content

Handle terminfo envvar #2

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

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

Conversation

ijc
Copy link

@ijc ijc commented Apr 6, 2017

As reported in moby/moby#32400 (née docker/for-mac#1515) setting $TERMINFO leads to a panic because OpenTermInfo has no code to handle this case.

This PR cleans up a bunch of stuff in that function and adds the missing case for when $TERMINFO is set.

NB I also include ijc@f565047 which is also in #1 so that go fmt -s is clean.

Ian Campbell added 5 commits November 9, 2016 17:28
- Checking if the file is unreadable is not needed, just try to open and read
  and handle the error.
- Upon success just return the result rather than breaking from the loop and
  falling through, which requires more complex error handling.
- Upon overall failure return the error directly. There is no need to
  fmt.Sprintf the static string argument to errors.New()

This does not yet correctly handle the case where $TERMINFO contains a value.

Signed-off-by: Ian Campbell <[email protected]>
https://linux.die.net/man/5/terminfo says:
> If the environment variable TERMINFO is set, it is interpreted as the
> pathname of a directory containing the compiled description you are working
> on. Only that directory is searched.

I'd have preferred a more authoritative/OS neutral reference (such as
http://pubs.opengroup.org/onlinepubs/7908799/xcurses/terminfo.html) but was
unable to find one.

Signed-off-by: Ian Campbell <[email protected]>
Copy link

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one question, but LGTM otherwise

gotty.go Outdated
termloc := os.Getenv("TERMINFO")
if len(termloc) == 0 {
if termloc := os.Getenv("TERMINFO"); len(termloc) > 0 {
path := filepath.Join(termloc, string(termName[0]), termName)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only used on Linux, so perhaps path.Join() instead of filepath.Join()?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using the thing which is semantically correct everywhere is the right thing to do even if it isn't strictly necessary for a given case. Unless there is some massive performance overhead of filepath vs path but I doubt that.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My worry is that when running in, e.g. git bash, I think it would pick back-slashes as a separator, but the environment expects forward slashes. It's a change in behaviour at least (existing code hard-codes /, and everything else assumes forward slashes)

@jhowardmsft @rneugeba to the rescue on what is used in that situation 😊

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing; OpenTermInfo("") will panic. Given that this function is exported, I suggest to add a check for this

if termName == "" {
    nil, errors.New("No terminfo file(-location) found")
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, because of the termName[0]. Will push another fixup, thanks

Using filepath switches from `/` to `\` separators on some platforms which
might be unexpected, so defer such a change to another time/discussion.

Signed-off-by: Ian Campbell <[email protected]>
@thaJeztah
Copy link

See you just pushed; I just added another comment #2 (comment) 😂

Copy link

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

(but would squishy squashy some of those commits 😉)

@ijc
Copy link
Author

ijc commented Apr 6, 2017

I'll leave squashing until @Nvveen requests it.

@andriisoldatenko
Copy link

@ijc @thaJeztah @Nvveen any luck to merge this?

@thaJeztah
Copy link

For Docker/Moby, we replaced this dependency with https://github.com/morikuni/aec, which is slightly more maintained, and was already in use by some other tools (see moby/moby#38398)

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.

3 participants