FAQ
Hi,

In the context of ssh client in go, (
https://godoc.org/golang.org/x/crypto/ssh) I am looking for

1) some way to disable colors when using session.RequestPty
2) if #1 is not possible, I need some way to strip all colors(they are
formatted as ANSI escape codes) from the string obtained from stdoutpipe of
such session.

Thanks,
Srinath

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Konstantin Khomoutov at Mar 22, 2016 at 7:44 pm

    On Tue, 22 Mar 2016 19:27:23 +0000 Srinath wrote:

    In the context of ssh client in go, (
    https://godoc.org/golang.org/x/crypto/ssh) I am looking for

    1) some way to disable colors when using session.RequestPty
    In theory, there should be a way to communicate the type of your
    terminal device to the remote. If you set it to something not
    supporting colors ("dumb" is a good candidate) the programs running
    remotely should not attempt to use colors.

    Note that the remote system must have the definition file for this
    terminal available. (If this is a GNU/Linux based system you can
    verify this by running `infocmp dumb` there).
    2) if #1 is not possible, I need some way to strip all colors(they are
    formatted as ANSI escape codes) from the string obtained from
    stdoutpipe of such session.
    That's simple [1]: you look for a sequence of two runes "\033["
    and skip everything until, and including, the nearest rune "m".

    1. https://github.com/mgutz/ansi/blob/master/ansi.go#L26

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • John McKown at Mar 22, 2016 at 8:39 pm

    On Tue, Mar 22, 2016 at 2:27 PM, Srinath wrote:

    Hi,

    In the context of ssh client in go, (
    https://godoc.org/golang.org/x/crypto/ssh) I am looking for

    1) some way to disable colors when using session.RequestPty
    2) if #1 is not possible, I need some way to strip all colors(they are
    formatted as ANSI escape codes) from the string obtained from stdoutpipe of
    such session.

    Thanks,
    Srinath
    ​I did a quick try on the following, but it is just a straight SSH from my
    Linux/Intel system to my Raspberry Pi 3, running Raspbian. Instead of just
    entering: ssh rpi3, I entered: TERM=dumb ssh rpi3. This set the terminal to
    "dumb" which BASH realizes does not have any coloring capability and so it
    doesn't color anything. Looking here:
    https://godoc.org/golang.org/x/crypto/ssh#Session.RequestPty The example
    shows something like:

    // Request pseudo terminal
    if err := session.RequestPty("xterm", 80, 40, modes); err != nil {
         log.Fatalf("request for pseudo terminal failed: %s", err)
    }

    === change to ===

    // Request pseudo terminal
    if err := session.RequestPty("dumb", 80, 40, modes); err != nil {
         log.Fatalf("request for pseudo terminal failed: %s", err)
    }

    Unfortunately, I am ignorant of how to use Go + ssh + public keys. I've
    given it a try, but have (so far) failed to get anything working.

    --
    How many surrealists does it take to screw in a lightbulb? One to hold the
    giraffe and one to fill the bathtub with brightly colored power tools.

    Maranatha! <><
    John McKown

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Konstantin Khomoutov at Mar 23, 2016 at 10:46 am

    On Tue, 22 Mar 2016 19:27:23 +0000 Srinath wrote:

    In the context of ssh client in go, (
    https://godoc.org/golang.org/x/crypto/ssh) I am looking for

    1) some way to disable colors when using session.RequestPty
    2) if #1 is not possible, I need some way to strip all colors(they are
    formatted as ANSI escape codes) from the string obtained from
    stdoutpipe of such session.
    ...and while we're at it, are you sure you need PTY at all?
    Pseudo terminal is only needed if you intend to spawn in the remote
    session a program which actively expects to be connected to a terminal
    device, and such programs are in most cases are interactive -- such as
    full-screen text editors (like nano, Vim, Emacs etc) or, say, chat
    clients like irssi or mcabber and so on. If you merely want to spawn a
    program which prints something to its standard output streams, and you
    want to grab that output, not only you do not need to allocate a PTY to
    run that program, but doing that might actually complicate matters.

    To explain it in more simple words, suppose you need to run `git log`
    on a remote machine and grab its output. If you allocate a PTY for
    that command to run, it will detect it's connected to a terminal and
    enable colouring of its output -- assuming it's interacting with a
    human operator. What's worse, it will even spawn the so-called
    "pager" (usually `less` or `more`) to pipe its output through it.
    Conversely, if it will detect it's not connected to a termnial, it will
    go to a "no-frills" mode and merely output plain uncoloured data into
    its stdout; no pager will be run, of course.

    TL;DR
    Please make sure you do really need a PTY to run your program.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 22, '16 at 7:27p
activeMar 23, '16 at 10:46a
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase