fix prompting

This commit is contained in:
Vitor Santos Costa 2017-03-03 11:21:29 +00:00
parent f7efff157b
commit fddb79895d
6 changed files with 31 additions and 22 deletions

View File

@ -2149,14 +2149,13 @@ X_API YAP_Term YAP_CopyTerm(Term t) {
X_API char *YAP_WriteBuffer(Term t, char *buf, size_t sze, int flags) {
CACHE_REGS
seq_tv_t inp, out;
size_t length = sze;
char *b;
BACKUP_MACHINE_REGS();
inp.val.t = t;
inp.type = YAP_STRING_TERM;
out.type = YAP_STRING_CHARS;
out.val.c = buf;
out.max = sze-1;
out.enc = LOCAL_encoding;
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return NULL;

View File

@ -45,14 +45,12 @@ static int ConsolePutc(int, int);
bool Yap_DoPrompt(StreamDesc *s) {
if (s->status & Tty_Stream_f) {
if (GLOBAL_Stream[0].status & Tty_Stream_f &&
s->name == GLOBAL_Stream[0].name)
return true;
if (GLOBAL_Stream[1].status & Tty_Stream_f &&
s->name == GLOBAL_Stream[1].name)
return true;
if (GLOBAL_Stream[2].status & Tty_Stream_f &&
s->name == GLOBAL_Stream[2].name)
return true;
s->name == GLOBAL_Stream[0].name &&
((GLOBAL_Stream[1].status & Tty_Stream_f ||
s->name == GLOBAL_Stream[1].name) ||
(GLOBAL_Stream[2].status & Tty_Stream_f &&
s->name == GLOBAL_Stream[2].name)))
return LOCAL_newline;
}
return false;
}
@ -62,6 +60,10 @@ bool Yap_DoPrompt(StreamDesc *s) {
int console_post_process_read_char(int ch, StreamDesc *s) {
/* the character is also going to be output by the console handler */
console_count_output_char(ch, GLOBAL_Stream + StdErrStream);
if (ch == '\r') {
s->linepos = 0;
LOCAL_newline = true;
} else
if (ch == '\n') {
CACHE_REGS
++s->linecount;

View File

@ -134,7 +134,8 @@ extern void Yap_InitSocketLayer(void);
extern void Yap_InitMems(void);
extern void Yap_InitConsole(void);
extern void Yap_InitReadlinePreds(void);
bool Yap_InitReadline(Term);
extern bool Yap_InitReadline(Term);
extern bool Yap_readline_clear_pending_input (StreamDesc *s);
extern void Yap_InitChtypes(void);
extern void Yap_InitCharsio(void);
extern void Yap_InitFormat(void);

View File

@ -251,6 +251,15 @@ void Yap_ReadlineFlush(int sno) {
}
}
bool Yap_readline_clear_pending_input(StreamDesc *s) {
rl_clear_pending_input();
if (s->u.irl.buf) {
free( ( void *)s->u.irl.buf );
}
s->u.irl.ptr = s->u.irl.buf = NULL;
return true;
}
bool Yap_ReadlineOps(StreamDesc *s) {
if (s->status & Tty_Stream_f) {
if (GLOBAL_Stream[0].status & (Input_Stream_f | Tty_Stream_f) &&

View File

@ -154,16 +154,14 @@ int Yap_GetFreeStreamD(void) { return GetFreeStreamD(); }
*/
static bool clearInput(int sno)
{
#if HAVE_READLINE
return rl_clear_pending_input ();
#endif
#if ISATTY||_WIN32
int i = fileno(GLOBAL_Stream[sno].file);
if (!isatty(i))
if (!(GLOBAL_Stream[sno].status & Tty_Stream_f))
return true;
#if USE_READLINE
if (GLOBAL_Stream[sno].status & Readline_Stream_f)
return Yap_readline_clear_pending_input (GLOBAL_Stream+sno);
#endif
#if HAVE_TCFLUSH
return tcflush(i, TCIOFLUSH) == 0;
return tcflush(fileno(GLOBAL_Stream[sno].file), TCIOFLUSH) == 0;
#elif MSC_VER
return fflush(GLOBAL_Stream[sno].file) == 0;
#endif

View File

@ -1392,8 +1392,8 @@ Command = (H --> B) ->
'$enter_command'(Stream, Mod, Status) :-
prompt1(': '), prompt(_,' '),
'$clear_input'(Stream),
prompt1(': '), prompt(_,' '),
Options = [module(Mod), syntax_errors(dec10),variable_names(Vars), term_position(Pos)],
(
Status == top