// 神话世界·西游记·版本4.50
/* */
// /feature/more.c
// 从侠客行借鉴并增强功能 可以向前、向后翻多页,查看大文件很方便
// 例如 f10(向下翻10页), b5(向上翻5页), etc
#include
varargs void more(string cmd, string *text, int line, int force)
{
int i, j, n;
if( sscanf(cmd, "b%d", n) == 1 ) cmd = "b";
if( sscanf(cmd, "f%d", n) == 1 ) cmd = "f";
if( n < 1 ) n = 1;
switch(cmd) {
case "b":
line -= 23 * ( n + 1 );
write(ESC+"[1A"+ESC+"[200D"+ESC+"[K\n\n");
if( line < -22 && !force ) return;
for( i = line + 23; line < i; line ++ )
write(text[line]+"\n");
break;
case "q":
write(ESC+"[1A"+ESC+"[200D"+ESC+"[K\n\n");
return;
break;
case "f":
line += 23 * ( n - 1 );
default:
write(ESC+"[1A"+ESC+"[200D"+ESC+"[K");
case "first":
if( n > 1 ) write("\n\n");
for(i=line + 23; line < sizeof(text) && line > i; line++)
write(text[line] + "\n");
if( line >= sizeof(text) && !force ) return;
}
printf("== 未完继续 "HIY"%d%%"NOR" == (q 离开,b[n]向前翻页,f[n]向后翻页,
其他继续下一页)",
(line*100/sizeof(text)) );
input_to("more", text, line);
}
varargs void start_more(string msg, int force)
{
if( !msg || strlen(msg) < 1 )
return;
more("first", explode(msg, "\n"), 0, force);
}
尊重作者 转载请注明出处52mud.com