Beispiel #1
0
bool Yap_InitReadline(Term enable) {
  // don't call readline within emacs
  if (Yap_Embedded)
    return false;
  if (!(GLOBAL_Stream[StdInStream].status & Tty_Stream_f) ||
      getenv("INSIDE_EMACS") || enable != TermTrue) {
    if (GLOBAL_Flags)
      setBooleanGlobalPrologFlag(READLINE_FLAG, false);
    return false;
  }
  GLOBAL_Stream[StdInStream].u.irl.buf = NULL;
  GLOBAL_Stream[StdInStream].u.irl.ptr = NULL;
  GLOBAL_Stream[StdInStream].status |= Readline_Stream_f;
#if _WIN32
  rl_instream = stdin;
#endif
  // rl_outstream = stderr;
  using_history();
  const char *s = Yap_AbsoluteFile("~/.YAP.history", true);
  history_file = s;
  if (read_history(s) != 0) {
    FILE *f = fopen(s, "a");
    if (f) {
      fclose(f);
    }
  }
  rl_readline_name = "YAP Prolog";
  rl_attempted_completion_function = prolog_completion;
  // rl_prep_terminal(1);
  if (GLOBAL_Flags)
    setBooleanGlobalPrologFlag(READLINE_FLAG, true);
  return Yap_ReadlineOps(GLOBAL_Stream + StdInStream);
}
Beispiel #2
0
void Yap_ConsoleOps(StreamDesc *s) {
  /* the putc routine only has to check it is putting out a newline */
  s->stream_putc = ConsolePutc;
  s->stream_getc = ConsoleGetc;
#if USE_READLINE
  /* if a tty have a special routine to call readline */
  if ((s->status & Readline_Stream_f) && trueGlobalPrologFlag(READLINE_FLAG)) {
    if (Yap_ReadlineOps(s))
      return;
  }
#endif
}