dqysi86208 2015-10-16 09:26
浏览 306

如何在Golang SSH客户端中删除颜色代码

I am using golang ssh package to build a ssh client, I set the terminal modes as below

// Set up terminal modes
modes := ssh.TerminalModes{
    ssh.ECHO:          0,     // disable echoing
    ssh.TTY_OP_ISPEED: 14400, // input speed = 14.4kbaud
    ssh.TTY_OP_OSPEED: 14400, // output speed = 14.4kbaud
}

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

it works fine, but a tiny problem, when I use "ls" command, it returns the names with color code, like below

[root@localhost ~]# ls
ls
anaconda-ks.cfg    [0m[01;34mpeter[0m
[01;32mbuild.sh[0m           [01;34mredis64[0m

it makes me feel difficult to read the file names, so is there any method to remove the color code around the names? thanks

  • 写回答

1条回答 默认 最新

  • drugs3550 2015-10-16 16:43
    关注

    Use session.RequestPty with "vt220" terminal type

    example: session.RequestPty("vt220", 80, 40, modes)

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?