termbox-go – 从控制台读取数据

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

termbox-go - Reading data from the console

问题

我对Go语言非常陌生,但我已经阅读了一些关于Go语言的基本示例和文献。目前,我正在一个需要创建终端应用程序的项目上工作。在阅读了termbox-go的相关资料后,我们决定将termbox-go作为开发的基础库。

这个应用程序非常简单,用户将会看到以下一组菜单:

主菜单
---------
01) 菜单1
02) 菜单2
03) 菜单3
99) 退出

请输入您的选择:__

在查看了示例后,我已经能够完成布局和其他所有内容。但是我没有看到任何示例中从终端读取选择的地方。用户将在选择完成后按下"Enter"键。

有人可以分享一个示例,展示如何实现上述功能吗?

另外,是否有任何示例中用户屏幕上有多个输入区域,用户可以使用上下键移动并输入值,如下所示:

输入姓名:_____________
输入出生日期:_____________
输入城市:_____________

非常感谢任何示例或指导。

英文:

I am very new to Go and went through some of the basic examples and literature around Go Lang. Currently I am working on a project where I need to create a terminal application. After reading around termbox-go we have decided to use the termbox-go as the base library for the development.

The application is very simple where the user will be provided with a set of menus as follows

Main Menu
---------
01) Menu 1
02) Menu 2
03) Menu 3
99) Quit

Please enter your selection : __

I am able to get the layout and all everything done after looking through the examples. But it no where I am not seeing any examples of where the selection is read from the terminal. The user will hit "Enter" key after the selection is done.

Can anyone can share an example which shows how to achieve the above.

Also is there any examples where the user screen has multiple input areas where user can move using up and down key and enter the values - as below

Enter Name : _____________
Enter DOB : ______________
Enter City: ______________

Any examples or pointers are highly appreciated.

Thanks

答案1

得分: 1

关于用户如何输入文本,你可以参考这个示例:https://github.com/nsf/termbox-go/blob/master/_demos/editbox.go

在这个示例中,当你按下回车键时,没有任何反应,这只是因为在主循环中没有处理。此外,你可以扩展这个示例,使用多个编辑框,并将上下箭头映射到改变焦点的编辑框。

英文:

As for how users could enter text you could check out this example https://github.com/nsf/termbox-go/blob/master/_demos/editbox.go

In the example nothing happens when you press Enter but that's just because it's not handled in the main loop. Also you could expand this example with multiple edit boxes and map the up/down arrows to change which box has focus.

huangapple
  • 本文由 发表于 2015年2月15日 10:40:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/28522509.html
匿名

发表评论

匿名网友

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

确定