fix prompting vs buffering outside readline

This commit is contained in:
Vitor Santos Costa 2017-07-30 22:23:16 +01:00
parent f99d048cc2
commit 8ad14f6765
3 changed files with 11 additions and 9 deletions

View File

@ -44,13 +44,10 @@ static int ConsolePutc(int, int);
bool Yap_DoPrompt(StreamDesc *s) { bool Yap_DoPrompt(StreamDesc *s) {
if (s->status & Tty_Stream_f) { if (s->status & Tty_Stream_f) {
if (GLOBAL_Stream[0].status & Tty_Stream_f && if (GLOBAL_Stream[StdInStream].status & Tty_Stream_f &&
s->name == GLOBAL_Stream[0].name && GLOBAL_Stream[StdErrStream].status & Tty_Stream_f) {
((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 LOCAL_newline;
}
} }
return false; return false;
} }
@ -149,6 +146,7 @@ restart:
GLOBAL_Stream[StdErrStream].stream_putc(StdErrStream, ch); GLOBAL_Stream[StdErrStream].stream_putc(StdErrStream, ch);
} }
} }
Yap_clearInput(StdErrStream);
strncpy(LOCAL_Prompt, (char *)RepAtom(LOCAL_AtPrompt)->StrOfAE, MAX_PROMPT); strncpy(LOCAL_Prompt, (char *)RepAtom(LOCAL_AtPrompt)->StrOfAE, MAX_PROMPT);
LOCAL_newline = FALSE; LOCAL_newline = FALSE;
} }

View File

@ -79,6 +79,7 @@ Int Yap_CloseSocket(int, socket_info, socket_domain);
#endif /* USE_SOCKET */ #endif /* USE_SOCKET */
extern bool Yap_clearInput(int sno);
extern Term Yap_read_term(int inp_stream, Term opts, bool clauatse); extern Term Yap_read_term(int inp_stream, Term opts, bool clauatse);
extern Term Yap_Parse(UInt prio, encoding_t enc, Term cmod); extern Term Yap_Parse(UInt prio, encoding_t enc, Term cmod);

View File

@ -154,7 +154,7 @@ int Yap_GetFreeStreamD(void) { return GetFreeStreamD(); }
/** /**
* *
*/ */
static bool clearInput(int sno) bool Yap_clearInput(int sno)
{ {
if (!(GLOBAL_Stream[sno].status & Tty_Stream_f)) if (!(GLOBAL_Stream[sno].status & Tty_Stream_f))
return true; return true;
@ -162,7 +162,10 @@ int Yap_GetFreeStreamD(void) { return GetFreeStreamD(); }
if (GLOBAL_Stream[sno].status & Readline_Stream_f) if (GLOBAL_Stream[sno].status & Readline_Stream_f)
return Yap_readline_clear_pending_input (GLOBAL_Stream+sno); return Yap_readline_clear_pending_input (GLOBAL_Stream+sno);
#endif #endif
#if HAVE_TCFLUSH #if HAVE_FPURGE
fflush(NULL);
return fpurge( GLOBAL_Stream[sno].file ) == 0;
#elif HAVE_TCFLUSH
return tcflush(fileno(GLOBAL_Stream[sno].file), TCIOFLUSH) == 0; return tcflush(fileno(GLOBAL_Stream[sno].file), TCIOFLUSH) == 0;
#elif MSC_VER #elif MSC_VER
return fflush(GLOBAL_Stream[sno].file) == 0; return fflush(GLOBAL_Stream[sno].file) == 0;
@ -176,7 +179,7 @@ static Int clear_input( USES_REGS1 )
"clear_input/1"); "clear_input/1");
if (sno != -1) if (sno != -1)
UNLOCK(GLOBAL_Stream[sno].streamlock); UNLOCK(GLOBAL_Stream[sno].streamlock);
return clearInput(sno); return Yap_clearInput(sno);
} }
static Term lineCount(int sno) { static Term lineCount(int sno) {