在golang中将文本显示在终端屏幕的中央位置

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

Show text in the center of terminal screen in golang

问题

我正在使用golang玩耍,并希望创建一个简单的终端工具(在Mac上,但它也应该在Linux上工作)。我需要在终端窗口的中心显示字符"x"。我如何检测终端窗口的宽度和高度,并检测其变化?

英文:

I am playing with golang and want to create a simple terminal tool (on mac, but it should work on linux too). I need to display character "x" in the center of the terminal window. How can I detect width and height of terminal window and detect its changes?

答案1

得分: 9

一个终端包存在于Go crypto 仓库中:
特别是,查看 GetSize 函数。

英文:

A terminal package exists in the Go crypto repository:
In particular, check out the GetSize function

答案2

得分: 6

一个轻量级的替代ncurses的选择是termbox-go。这是一个纯Go语言实现的termbox。

它提供了一个简单的API,可以在终端中完成一些“图形”相关的工作,并且在支持不同终端实现方面相当不错。

英文:

A lightweight alternative to the usual ncurses option, is termbox-go. This is a pure-go implementation of termbox.

It offers a simple API to get some 'graphical' stuff done in a terminal and is pretty decent as far as support for different terminal implementations goes.

huangapple
  • 本文由 发表于 2013年5月14日 22:01:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/16545285.html
匿名

发表评论

匿名网友

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

确定