AlecAivazis / survey

A golang library for building interactive and accessible prompts with full support for windows and posix terminals.
MIT License
4.09k stars 354 forks source link

ANSI codes not respected by SecureCRT #69

Closed canghai908 closed 7 years ago

canghai908 commented 7 years ago

When i use exapmple code `package main

import ( "fmt" "gopkg.in/AlecAivazis/survey.v1" )

// the questions to ask var qs = []*survey.Question{ { Name: "name", Prompt: &survey.Input{Message: "What is your name?"}, Validate: survey.Required, }, { Name: "color", Prompt: &survey.Select{ Message: "Choose a color:", Options: []string{"red", "blue", "green"}, Default: "red", }, }, }

func main() { // the answers will be written to this struct answers := struct { Name string // survey will match the question and field names FavoriteColor string survey:"color" // or you can tag fields to match a specific name }{}

// perform the questions
err := survey.Ask(qs, &answers)
if err != nil {
    fmt.Println(err.Error())
    return
}

fmt.Printf("%s chose %s.", answers.Name, answers.FavoriteColor)

}`

the menu is

[root@localhost]/home/mygo/src/cloudcon# go run c.go ? What is your name? 12 ? What is your name? 12 ? Choose a color: ❯ red blue green ? Choose a color: red ❯ blue green ? Choose a color: red blue ❯ green ? Choose a color: red blue ❯ green ? Choose a color: red blue ❯ green

AlecAivazis commented 7 years ago

Hey @canghai908, thanks for reporting this issue and I'm sorry for any inconvenience this caused.

Do you mind telling me what operating system/terminal you are using?

canghai908 commented 7 years ago

@AlecAivazis I use centos7 x64,go 1.8.3 and the terminal is bash

GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu) Copyright (C) 2011 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html

AlecAivazis commented 7 years ago

Hm strange, I'm surprised it's not working on centOS because I would expect the default terminal to support ansi sequences (it looks like colors are being applied from your output). Would u mind sending me the output of 'echo $TERM' on the machine you are experiencing the problem?

canghai908 commented 7 years ago

Thank you @AlecAivazis.I have make a test.When I use SecureCRT to connect CentOS 7 x64,the term is xterm,it have this question. 123 When I use xmanager shell to connect CentOS 7 x64,the term is xtrem,it is ok 222 Sorry to my pool english :)

AlecAivazis commented 7 years ago

No worries about your English - I understand you perfectly. And thanks for the screen captures, they are very helpful.

That being said, I think your test proves that this is a problem with the way SecureCRT handles ansi escape sequences. I think the only way we can fix your problem is by figuring out how to tell it to interpret them correctly. It seems like I can download a free trial of SecureCRT to check myself so I will do that when I get back from a vacation in a few days. Until then, maybe u could look at the docs to see if there's a flag or something we can add when u connect.

AlecAivazis commented 7 years ago

@canghai908 any news on this?

AlecAivazis commented 7 years ago

@canghai908 - i'm going to close this for now. If you this still ends up being a problem feel free to let me know and we can try to figure something out.