Add a scrollbar on Ncurses or make it like "more"
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. 开发者_StackOverflow社区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...
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.
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.
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.
精彩评论