在命令行界面应用程序中控制箭头键。

huangapple go评论80阅读模式
英文:

Control arrow keys in CLI app

问题

我想要构建一个(golang)库,为用户选择提供多个选项。我的想法是打印选项的名称,并将其中一个突出显示为“活动”。当按下箭头键(左右或上下)时,我希望在内部和可见上更新“选定”的答案。

我知道termboxtcell,我也查看了像pecorat这样的项目。它们似乎都是基于某种屏幕的基本概念构建的。理想情况下,我希望仅在用户在终端中编辑的行中保持控制,而不创建全屏交互。有没有办法实现这一点?

英文:

I would like to build a (golang) library that offers a number of options for user choice. My idea is to print the names of the options and highlight one as "active". Upon arrow keys (left and right or up and down) being pressed I would like to update the "selected" answer internally and visibly.

I know about termbox and tcell and I also have checked projects like peco and rat. All of them seem to build on the basic concept of a screen of some kind. Ideally I would like to keep the control in just the line the user is editing in his terminal without creating a fullscreen interaction. Is there any way to achieve this?

答案1

得分: 1

ncurses是Linux中一个流行的终端控制库,它有Go绑定(也支持OSX和Windows)。我从未使用过它们,所以无法为它们提供担保,但这是实现你想要的功能的一种方式。

英文:

ncurses is one popular library for terminal control in Linux, and it has Go bindings (also supports OSX and Windows). I have never used them, so I cannot vouch for them, but this is one way to accomplish what you want.

答案2

得分: -1

回答我的问题:这个很棒的库叫做climenu实际上就是我所要求的。所有需要的技术技巧都包含在这段代码中。向Paul Rademacher致敬!我肯定可以根据自己的需求进行调整。

英文:

Answering my own question: This neat library called climenu practically does what I asked for. All the technical trickery needed is part of this code. Kudos to
Paul Rademacher! I surely can adapt this to suit my needs.

huangapple
  • 本文由 发表于 2017年4月17日 22:47:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/43453721.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定