fix prompting
This commit is contained in:
parent
f7efff157b
commit
fddb79895d
@ -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;
|
||||
|
20
os/console.c
20
os/console.c
@ -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,7 +60,11 @@ 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 == '\n') {
|
||||
if (ch == '\r') {
|
||||
s->linepos = 0;
|
||||
LOCAL_newline = true;
|
||||
} else
|
||||
if (ch == '\n') {
|
||||
CACHE_REGS
|
||||
++s->linecount;
|
||||
++s->charcount;
|
||||
|
@ -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);
|
||||
|
@ -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) &&
|
||||
|
16
os/streams.c
16
os/streams.c
@ -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))
|
||||
return true;
|
||||
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
|
||||
@ -1472,7 +1470,7 @@ void Yap_InitIOStreams(void) {
|
||||
Yap_InitCPred("set_output", 1, set_output, SafePredFlag | SyncPredFlag);
|
||||
Yap_InitCPred("$stream", 1, p_stream, SafePredFlag | TestPredFlag);
|
||||
Yap_InitCPred("$clear_input", 1, clear_input, SafePredFlag | TestPredFlag);
|
||||
|
||||
|
||||
#if HAVE_SELECT
|
||||
Yap_InitCPred("stream_select", 3, p_stream_select,
|
||||
SafePredFlag | SyncPredFlag);
|
||||
|
@ -1392,8 +1392,8 @@ Command = (H --> B) ->
|
||||
|
||||
|
||||
'$enter_command'(Stream, Mod, Status) :-
|
||||
'$clear_input'(Stream),
|
||||
prompt1(': '), prompt(_,' '),
|
||||
'$clear_input'(Stream),
|
||||
Options = [module(Mod), syntax_errors(dec10),variable_names(Vars), term_position(Pos)],
|
||||
(
|
||||
Status == top
|
||||
|
Reference in New Issue
Block a user