Ejemplo n.º 1
0
static void _print_string(const char *ptr, size_t width, bool utf8,
		bool left_adjust)
{
	if (!ptr)
		ptr = nullstr;

	size_t padding = 0;
	if (width) {
		size_t w = screen_display_width(ptr, utf8);
		if (w < width)
			padding = width - w;
	}

	if (padding && !left_adjust)
		tui_repeat_char(' ', padding);

	if (utf8) {
		screen_puts(ptr, 0);
	} else {
		convert(CONVERT_G2U, ptr, CONVERT_ALL, NULL, 0,
				screen_put_gbk_helper, NULL);
	}

	if (padding && left_adjust)
		tui_repeat_char(' ', padding);
}
Ejemplo n.º 2
0
Archivo: tui.c Proyecto: fbbs/fbbs
void tui_update_status_line(void)
{
	extern time_t login_start_time; //main.c

	char date[STRLEN];

	screen_move_clear(-1);

	if (!DEFINE(DEF_ENDLINE))
		return;

	fb_time_t now = fb_time();
	int cur_sec = now % 10;

	if (cur_sec < 5) {
		strlcpy(date, format_time(now, TIME_FORMAT_UTF8_ZH), sizeof(date));
	} else {
		if (resolve_boards() >= 0)
			convert_g2u(brdshm->date, date);
		else
			date[0] = '\0';
	}

	if (cur_sec >= 5 && is_birth(&currentuser)) {
		screen_printf("\033[0;1;33;44m[\033[36m                      "
				"啦啦~~生日快乐!记得要请客哟 :P"
				"                       \033[33m]\033[m");
	} else {
		int stay = (now - login_start_time) / 60;
		char stay_str[20];
		describe_stay(stay, stay_str, sizeof(stay_str));

		char notice[128];
		notice_string(notice, sizeof(notice));
		int notice_width = screen_display_width(notice, true);

		screen_printf("\033[1;44;33m[\033[36m%29s\033[33m]"
			"[\033[36m%5d\033[33m人\033[36m%3d\033[33m友]",
			date, session_count_online(),
			session_count_online_followed(!HAS_PERM(PERM_SEECLOAK)));
		// 剩下35列
		if (notice_width) {
			int space = 33 - notice_width;
			if (space > 0)
				tui_repeat_char(' ', space);
			screen_printf("[\033[%d;36m%s\033[m\033[1;33;44m]\033[m",
					_suppress_notice ? 1 : 5, notice);
		} else {
			int space = 27 - strlen(currentuser.userid);
			tui_repeat_char(' ', space);
			prints("[\033[36m%s\033[33m]%s\033[m", currentuser.userid,
					stay_str);
		}
	}
}
Ejemplo n.º 3
0
Archivo: tui.c Proyecto: fbbs/fbbs
void tui_header_line(const char *menu, bool check_mail)
{
	extern int mailXX; //main.c
	char title[36];

	if (check_mail && chkmail())
		strlcpy(title, strstr(menu, "讨论区列表") ? "[您有信件,按 M 看新信]"
				: "[您有信件]", sizeof(title));
	else if (check_mail && mailXX == 1)
		strlcpy(title, "[信件过量,请整理信件!]", sizeof(title));
	else
		strlcpy(title, BBSNAME_UTF8, sizeof(title));

	bool show_board = true;
	int w1 = screen_display_width(menu, true),
		w2 = screen_display_width(title, true),
		w3 = screen_display_width(currboard, true) + 2;
	int spaces = 80 - w1 - w2 - w3;
	if (spaces < 0) {
		spaces = 80 - w1 - w2;
		show_board = false;
	}

	screen_move_clear(0);
	screen_printf("\033[1;33;44m%s", menu);
	if (spaces > 0)
		tui_repeat_char(' ', spaces / 2);
	if (streq(title, BBSNAME_UTF8))
		screen_printf("\033[37m%s", title);
	else if (title[0] == '[')
		screen_printf("\033[5;36m%s\033[0;1;44m", title);
	else
		screen_printf("\033[36m%s", title);
	if (spaces > 0)
		tui_repeat_char(' ', spaces - spaces / 2);
	if (show_board)
		screen_printf("\033[33m[%s]\033[m", currboard);
	tui_update_status_line();
	screen_move(1, 0);
}
Ejemplo n.º 4
0
Archivo: xyz.c Proyecto: fbbs/fbbs
//      更改用户的权限设定
unsigned int setperms(unsigned int pbits, char *prompt, int numbers, int (*showfunc) ())
{
	int lastperm = numbers - 1;
	int i, done = NA;
	char choice[3], buf[80];
	screen_move(4, 0);
	screen_printf("\033[m请按下您要的代码来设定%s,按 Enter 结束.\n", prompt);
	screen_move(6, 0);
	screen_clrtobot();

	for (int j = 0; j < 16 && j < numbers; ++j) {
		showfunc(pbits, j, false);
		if (j + 16 < numbers) {
			tui_repeat_char(' ', 4);
			showfunc(pbits, j + 16, false);
		}
	}
	while (!done) {
		//% sprintf(buf, "选择(ENTER 结束%s): ",
		sprintf(buf, "\xd1\xa1\xd4\xf1(ENTER \xbd\xe1\xca\xf8%s): ",
				//% ((strcmp(prompt, "权限") != 0)) ? "" : ",0 停权");
				((strcmp(prompt, "\xc8\xa8\xcf\xde") != 0)) ? "" : "\xa3\xac""0 \xcd\xa3\xc8\xa8");
		getdata(-1, 0, buf, choice, 2, DOECHO, YEA);
		*choice = toupper(*choice);
		/*		if (*choice == '0')
		 return (0);
		 else modified by kit,rem 0停权* remed all by Amigo 2002.04.03*/
		if (*choice == '\n' || *choice == '\0')
		done = YEA;
		else if (*choice < 'A' || *choice> 'A' + lastperm)
		bell ();
		else {
			i = *choice - 'A';
			pbits ^= (1 << i);
			if ((*showfunc) (pbits, i, YEA) == NA) {
				pbits ^= (1 << i);
			} //if
		} //else
	}
	//while !done
	return (pbits);
}
Ejemplo n.º 5
0
Archivo: tui.c Proyecto: fbbs/fbbs
static int _tui_input(int line, int col, const char *prompt, char *buf,
		int len, int echo, int clear, bool utf8)
{
	extern int RMSG;
	extern int msg_num;

	if (clear)
		buf[0] = '\0';
	buf[len - 1] = '\0';

	int real_x = prompt ? screen_display_width(prompt, utf8) : 0;

	int cur, clen;
	cur = clen = strlen(buf);

	bool inited = screen_inited(), prompted = false;
	while (1) {
		if (inited || !prompted) {
			screen_move(line, col);
			clrtoeol();
			if (prompt) {
				if (utf8)
					screen_printf("%s", prompt);
				else
					prints("%s", prompt);
			}
			prompted = true;
		}
		if (inited) {
			if (echo)
				prints("%s", buf);
			else
				tui_repeat_char('*', clen);
			screen_move(line, real_x + cur);
		}

		if (RMSG)
			screen_flush();

		int ch = terminal_getchar();

		if (RMSG && msg_num == 0) {
			if (ch == Ctrl('Z') || ch == KEY_UP) {
				buf[0] = Ctrl('Z');
				clen = 1;
				break;
			}
			if (ch == Ctrl('A') || ch == KEY_DOWN) {
				buf[0] = Ctrl('A');
				clen = 1;
				break;
			}
		}

		if (ch == '\n' || ch == '\r')
			break;

		if (!inited) {
			if (ch == '\x7f' || ch == Ctrl('H')) {
				int dec = remove_character(buf, &cur, clen, true);
				if (dec) {
					clen -= dec;
					screen_puts("\x8 \x8", 3);
				}
			} else if (isprint2(ch) && clen < len - 1) {
				buf[cur] = ch;
				buf[++cur] = '\0';
				++clen;
				screen_putc(echo ? ch : '*');
			}
			continue;
		}

		if (ch == '\x7f' || ch == Ctrl('H')) {
			clen -= remove_character(buf, &cur, clen, true);
		} else if (ch == KEY_DEL) {
			clen -= remove_character(buf, &cur, clen, false);
		} else if (ch == KEY_LEFT) {
			if (cur > 0)
				--cur;
		} else if (ch == KEY_RIGHT) {
			if (cur < clen)
				++cur;
		} else if (ch == Ctrl('E') || ch == KEY_END) {
			cur = clen;
		} else if (ch == Ctrl('A') || ch == KEY_HOME) {
			cur = 0;
		} else if (isprint2(ch) && clen < len - 1) {
			if (buf[cur] != '\0')
				memmove(buf + cur + 1, buf + cur, clen - cur);
			buf[cur++] = ch;
			buf[++clen] = '\0';
		}
	}

	screen_putc('\n');
	screen_flush();
	return clen;
}
Ejemplo n.º 6
0
void tui_update_status_line(void)
{
	extern time_t login_start_time; //main.c

	char date[STRLEN];

	screen_move_clear(-1);

	if (!DEFINE(DEF_ENDLINE))
		return;

	fb_time_t now = fb_time();
	int cur_sec = now % 10;

	if (cur_sec < 5) {
		strlcpy(date, format_time(now, TIME_FORMAT_ZH), sizeof(date));
	} else {
		if (resolve_boards() >= 0)
			strlcpy(date, brdshm->date, 30);
		else
			date[0] = '\0';
	}

	if (cur_sec >= 5 && is_birth(&currentuser)) {
		//% "啦啦~~,生日快乐!   记得要请客哟 :P"
		prints("\033[0;1;44;33m[\033[36m                     "
				"\xc0\xb2\xc0\xb2\xa1\xab\xa1\xab\xa3\xac\xc9\xfa\xc8\xd5"
				"\xbf\xec\xc0\xd6!   \xbc\xc7\xb5\xc3\xd2\xaa\xc7\xeb"
				"\xbf\xcd\xd3\xb4 :P                   \033[33m]\033[m");
	} else {
		int stay = (now - login_start_time) / 60;
		char stay_str[20];
		describe_stay(stay, stay_str, sizeof(stay_str));

		char notice[128];
		notice_string(notice, sizeof(notice));
		int notice_len = strlen(notice);

		prints(	"\033[1;44;33m[\033[36m%29s\033[33m]"
			//% "人 友"
			"[\033[36m%5d\033[33m\xc8\xcb\033[36m%3d\033[33m\xd3\xd1]",
			date, session_count_online(),
			session_count_online_followed(!HAS_PERM(PERM_SEECLOAK)));
		if (notice_len) {
			int space = 25 - notice_len;
			if (space > 0) {
				tui_repeat_char(' ', space);
				prints("[\033[%d;36m%s\033[m\033[1;33;44m]%s\033[m",
						_suppress_notice ? 1 : 5, notice, stay_str);
			} else {
				space += 6;
				if (space > 0)
					tui_repeat_char(' ', space);
				prints("[\033[%d;36m%s\033[m\033[1;33;44m]\033[m",
						_suppress_notice ? 1 : 5, notice);
			}
		} else {
			int space = 25 - strlen(currentuser.userid);
			tui_repeat_char(' ', space);
			prints("[\033[36m%s\033[33m]%s\033[m", currentuser.userid,
					stay_str);
		}
	}
}