pike.git
/
NT
/
tools
/
lib.pike
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/NT/tools/lib.pike:199:
object inout; #if __VERSION__ > 0.699999 && constant(thread_create) class RLInOut { Thread.Mutex m=Thread.Mutex(); object rl=Stdio.Readline(); string prompt="";
+
array from_handler= ({"\r\n","\n\r","\n"});
+
array to_handler= ({"\n\r","\n\r","\n\r"});
+
string read() { string tmp=rl->read(); if(tmp) { tmp+="\n"; prompt=""; } return tmp; } int write(string s) {
-
s=prompt+s
-
"
\r
";
-
array lines=s/"
\n
";
-
rl->write
(lines
[..sizeof
(
s
)-
2
]
*"
\n
"
);
-
rl->set_prompt(prompt
=lines[-1]
);
+
/* This provides some very basic terminal emulation */
+
/* We need to understand \r, \n, and \b */
+
// werror("%O\n",
s
);
+
s
=
replace(
prompt+s
,from_handler,to_handler);
+
+
array tmp=s/
"
/b
";
+
+
array lines=s/"
\r
";
+
foreach
(lines
, string l)
+
{
+
if
(
strlen(l
)
&& l[
-
1
]
=='
\n
'
)
+
{
+
rl->write(l)
;
+
prompt="";
+
}else{
+
prompt=l;
+
}
+
}
+
+
rl->set_prompt(prompt);
return strlen(s); } void create() { rl->enable_history(512);
-
+
for(int e=0;e<256;e++)
+
{
+
switch(e)
+
{
+
case '\n': case '\r': break;
+
default:
+
from_handler+=({ sprintf("%c\b",e) });
+
to_handler+=({ sprintf("") });
}
-
+
}
+
}
}; if(!silent && !!Stdio.stdin->tcgetattr() && !!Stdio.stdout->tcgetattr()) { inout=RLInOut(); }else #endif inout=SimpleInOut();
pike.git/NT/tools/lib.pike:245:
for(int e=0;e<sizeof(cmd);e++) f->write(sprintf("%4c%s",strlen(cmd[e]),cmd[e])); // if(f->proxy) // f->proxy(Stdio.File("stdin")); // else // werror("FNORD\n"); thread_create(lambda(object f) { int killed;
+
int last_killed;
void killme() {
-
if(
!
killed)
-
{
+
if(
last_
killed
== time(
)
) return;
+
last_killed=time();
werror("\r\n** Interupted\r\n");
-
+
if(!killed || killed+5 > time())
+
{
f->write_oob("x");
-
killed=1;
+
if(!
killed
)
+
killed
=
time();
+
}else{
+
exit(
1
)
;
} }; if(f->write_oob) { signal(signum("SIGINT"), killme); } while(string s=inout->read()) f->write(s);