www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - arsd terminal with ConsoleOutputType.cellular

reply Jani Hur <spam com.invalid> writes:
What might be wrong with the following code below as it doesn't 
clear the screen and print "(0, 0)" as expected:

import arsd.terminal;

void main() {
   auto term = Terminal(ConsoleOutputType.cellular);
   term.clear;
   term.writefln("(%s, %s)", term.cursorX, term.cursorY);
}

If I change to the ConsoleOutputType.linear then the screen is 
cleared and "(0, 0)" is printed as expected.

I'm running Gnome Terminal in Red Hat Linux and compiling with 
DMD:

[jani red arsd]$ echo $TERM
xterm-256color
[jani red arsd]$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.6 (Maipo)
[jani red arsd]$ dmd --version
DMD64 D Compiler v2.083.0
Copyright (C) 1999-2018 by The D Language Foundation, All Rights 
Reserved written by Walter Bright
[jani red arsd]$
Jul 13 2019
next sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Saturday, 13 July 2019 at 13:30:47 UTC, Jani Hur wrote:
 void main() {
   auto term = Terminal(ConsoleOutputType.cellular);
   term.clear;
   term.writefln("(%s, %s)", term.cursorX, term.cursorY);
 }
In cellular mode, it switches the terminal to an alternate screen (like vim - notice that when you exit vim, it goes back to the same screen view you had when you went into it, instead of being leftover stuff from the full screen application), and terminal's destructor switches back. So what happened here is: 1) it switched to the alternate screen. 2) cleared and printed text to that 3) switched back to the normal screen at program exit Meaning you don't see the output! Simply add some kind of wait to the end of main() so the program doesn't exit. Like term.getline(); right at teh end so it waits for you to press enter before exiting and you should see it.
Jul 13 2019
prev sibling parent reply Jani Hur <spam com.invalid> writes:
Other arsd.terminal related question. How to clear a line when it 
is re-used ? The following code snipped is expected to print:

important text !

but instead it prints:

important text !gless mambo-jambo (33, 0)

import arsd.terminal;

void main() {
   auto term = Terminal(ConsoleOutputType.linear);
   term.clear;
   term.write("plenty of meaningless mambo-jambo");
   term.writef(" (%s, %s)", term.cursorX, term.cursorY);
   term.moveTo(0, 0);
   term.write("important text !");
   term.writeln;
}
Jul 13 2019
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Saturday, 13 July 2019 at 13:41:41 UTC, Jani Hur wrote:
 Other arsd.terminal related question. How to clear a line when 
 it is re-used ?
You need to print a number of spaces at the end to clear what's after it. Maybe like a loop from string.length .. terminal.width -1 and write(" "). (maybe i should add a function for that)
Jul 13 2019
parent reply Jani Hur <spam com.invalid> writes:
Thanks for the answers Adam - I can now proceed !
Jul 13 2019
parent Jani Hur <spam com.invalid> writes:
On Saturday, 13 July 2019 at 14:08:26 UTC, Jani Hur wrote:
 Thanks for the answers Adam - I can now proceed !
I wrote two simple examples for D dummies (like me and myself) to demonstrate arsd.terminal features I'm planning to use in my "real" console "application". The examples are available in: https://bitbucket.org/janihur/d-ex/src/master/arsd/
Jul 15 2019