6

I want to clear screen inside SWI-prolog console using either keyboard shortcut or command (i guess in Prolog you call that "predicate").

Here is similar question where i kinda find what i need - there is predicate that works for me:

write('\33\[2J').

Is there a better (easier) way to clear screen?

Guy Coder
  • 24,501
  • 8
  • 71
  • 136
TTB_Detagari
  • 81
  • 1
  • 1
  • 5

4 Answers4

6

On UNIX terminals, you can simply use the built-in tty_clear predicate to clear the console.

tty_clear.
Jakob Miserez
  • 96
  • 1
  • 4
  • This doesn't work as I try (v8.4.2, 64-bit, Windows 10). `?- tty_clear. ERROR: Unknown procedure: tty:tty_get_capability/3 ERROR: In: ERROR: [12] tty:tty_get_capability(cl,string,_3000) ERROR: [11] tty:string_action(cl) at c:/program files/swipl/library/tty.pl:82 ERROR: [9] toplevel_call(user:user:tty_clear) at c:/program files/swipl/boot/toplevel.pl:1158 ERROR: ERROR: Note: some frames are missing due to last-call optimization. ERROR: Re-run your program in debug mode (:- debug.) to get more detail. Exception: (12) tty:tty_get_capability(cl, string, _2456) ?` – Stewart May 08 '22 at 11:53
  • This didn't work for me as well. Using SWI-Prolog in windows 64 machine – Awshaf Ishtiaque Aug 03 '22 at 20:00
  • Apparently, Windows terminals do not support `tty_clear`, see [this post](https://stackoverflow.com/questions/16908764/clearing-screen-in-swipl-prolog-in-windows) for a Windows alternative, such as `cls :- write('\e[2J').` I've updated my answer. – Jakob Miserez Aug 03 '22 at 20:14
4

SWI-Prolog allows the definition of a settings file that is loaded by default at startup. Its name depends on the operating-system. On POSIX systems, it's named .swiplrc. You can simply create or update the file if you're already using it with a definition for a shortcut predicate. For example:

cls :- write('\33\[2J').
Paulo Moura
  • 18,373
  • 3
  • 23
  • 33
1

Thanks for helping me. I was able to solve my problem - in the folder, where i have my .pl file, i added file "swipl.ini"(it's for windows), where i added predicate:

cls :- write('\33\[2J').

Now i can just write inside SWI-prolog terminal "cls." and it works as expected.

TTB_Detagari
  • 81
  • 1
  • 1
  • 5
0

In 2022, running SWI-Prolog on Windows 10, the initialisation file is called 'init.pl', and is located on my computer in C:\Users\name\AppData\Roaming\swi-prolog

Francis King
  • 1,652
  • 1
  • 7
  • 14