Add a scrollbar on Ncurses or make it like “more”

荒凉一梦 提交于 2021-01-27 06:04:11

问题


Basically I am writing a client program which receives response and logs from server, the client is also able to send request to server for different information. I used curses and output looks pretty good. It looks like VI, output at the top and user on Client end enter command at the bottom. Only thing is I am not able to scroll back.. My boss told me to make it like "more command in linux" and I want to stick with my solution and add a scroll bar on the side for output window... I was thinking Server sends logs randomly and it's nearly impossible (or too hard) to make it look like more...


回答1:


If you maintain a list or array of lines in your client and ask ncurses to paint a range of lines as a sliding window, you can slide your window up and down in response to ^F ^B ^U ^D ^Y ^E commands, which just repaints the screen with different indexes.

I would skip trying to draw a scrollbar though: It would look out of place on a Linux system. Not even mc has scrollbars. Just show a content summary in the bottom line, similar to vim's Top, Bot, All, N% when :set ruler is turned on, that'll feel most at home.




回答2:


I'm not entirely sure if you are asking about how to implement scrollback or how to draw a scrollbar with ncurses. My guess is the second.

Assuming your ncurses is compiled with Unicode support (remember to set the environment correctly when initializing ncurses, look into "setlang"), you can use following characters:

Unicode:
▲ - U+25B2 BLACK UP-POINTING TRIANGLE
▼ - U+25BC BLACK DOWN-POINTING TRIANGLE
▮ - U+25AE BLACK VERTICAL RECTANGLE

ASCII:
176 - ░ Light shaded block
177 - ▒ Medium shaded block
178 - ▓ Dark shaded block
219 - █ Block block

Writing the code to display the dark block at the right place should be quite straightforward.

If I understood your question wrong, my excuses.




回答3:


Another possibility is to re-write your client as an IRC bot or an IM client. Users send messages either to the client directly or to a specific channel, and the bot performs the action and sends back any necessary replies.

The beauty is you get to skip all the user interface stuff yourself -- scroll back and history is handled via irssi or xchat or some other client. Users can run the client they like the most.

Logging can be handled via a central mechanism, published to the world, or given to specific managers / administrators as needs dictate.

The downside is that you have to maintain and run an IRC server or XMPP server. If you're already using them elsewhere in the organization, and it is appropriate to use them for this, the leverage might be worth it. If you're not already using one, the savings in the client might not be worth the expense of maintaining yet another service.

A team I was part of in the past loved having an IRC interface to BuildBot to report check-ins, build success, build failures, test success, test failures, for our continuous integration build and test setup.



来源:https://stackoverflow.com/questions/6617419/add-a-scrollbar-on-ncurses-or-make-it-like-more

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!