[slang-users] Curious behaviour with SLsmg_set_color and SLsmg_write_string

Remko van der Vossen wich at stack.nl
Tue Nov 27 13:41:51 UTC 2007


Hello,

I have a small problem which I seem unable to resolve, I write items
from an stl list of strings to a scrollable window using
SLsmg_write_nstring and indicate the cursor in said window by using
reverse video with SLsmg_set_color. However as soon as the window starts
scrolling, the text in the cursorline gets garbled, (shifted and
combined with the string which was on that line previously,) all other
lines both above and below the cursor remain fine. I have condensed the
problem to the enclosed test program.

Am I doing something wrong? I know the documentation is a little sketchy
on parts of the API, so it could easily be that I am doing something
that is not allowed or that I am forgetting something. Or am I running
into a bug in the library?

Kind regards,

Remko van der Vossen

---

#include <slang.h>
#include <signal.h>
#include <list>
#include <string>

int main() {
	bool not_done = true;

	//SLutf8_enable(-1);
	//SLsmg_utf8_enable(1);

	SLtt_get_terminfo();
	SLkp_init();
	SLang_init_tty(-1, 0, 0);
	SLang_set_abort_signal(0);
	SLtt_get_screen_size();
	SLsmg_init_smg();
	SLtt_Use_Ansi_Colors = 1;
	SLtt_set_color(1, 0, "black", "white");
	SLtt_set_cursor_visibility(-1);

	std::list<std::string> some_list;
	std::list<std::string>::iterator cursor = some_list.begin();
	while (rand()%40 && some_list.size() < 1000) {
		std::string some_string;
		while (rand()%50 && some_string.size() < 1000) {
			some_string += 0x20 + rand()%0x60;
		}
		some_list.insert(cursor, some_string);
	}
	cursor = some_list.begin();

	while (not_done) {
		std::list<std::string>::iterator i = cursor;
		for (size_t j = SLtt_Screen_Rows/2; i != some_list.begin() && 0 < j; --j)
			--i;
		for (size_t r = 0; r < SLtt_Screen_Rows; ++r) {
			SLsmg_gotorc(r, 0);
			if (i == some_list.end()) {
				SLsmg_set_color(0);
				SLsmg_write_nstring(0, SLtt_Screen_Cols);
				continue;
			}
			SLsmg_set_color(i == cursor ? 1 : 0);
			//XSLANG const_cast because of s-lang const api issue
			SLsmg_write_nstring(const_cast<char*>(i->c_str()), SLtt_Screen_Cols);
			++i;
  	}
		SLsmg_refresh();
		while (SLang_input_pending(1)) {
			switch(SLkp_getkey()) {
			case 'q':
				not_done = false;
				break;
			case 'j':
				if (++cursor == some_list.end())
					--cursor;
				break;
			case 'k':
				if (cursor != some_list.begin())
					--cursor;
				break;
			}
		}
	}

	SLsmg_reset_smg();
	SLang_reset_tty();

	return 0;
}

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2265 bytes
Desc: not available
Url : http://mailman.jedsoft.org/pipermail/slang-users-l/attachments/20071127/0587319f/smime.bin


More information about the slang-users-l mailing list