kba / lanterna

Automatically exported from code.google.com/p/lanterna
GNU Lesser General Public License v3.0
0 stars 0 forks source link

SwingTerminal.setCursorVisible(false) Does Nothing #94

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Repro steps:
- Create a new SwingTerminal
- Call setCursorVisible(false)
- Look for the cursor

Expected: can't find it!
Actual: It lives at (0, 0).

You can verify this by calling setCursorPosition, too, on the screen.

This causes really annoying flickering in my roguelike, because I'm drawing to 
a lot of different areas on screen.

Original issue reported on code.google.com by alibhai....@gmail.com on 28 Nov 2013 at 6:10

GoogleCodeExporter commented 9 years ago
I can't reproduce this. What version of Lanterna are you using? Also, if you 
could give me a very simple code example that reproduces it?

Original comment by mab...@gmail.com on 1 Dec 2013 at 1:47

GoogleCodeExporter commented 9 years ago
I'm using version 2.1.6 (via Gradle). I don't have a "very simple" example, but 
I have a working version of my game on GitHub, which you can use: 
https://github.com/deengames/Freedom

From the main/battle screens, you can see the cursor (black) in the top-left 
corner. The lantern code is isolated to RgbConsoleScreen.java. You have to jam 
down the arrow keys, because I optimized it to draw only the minimal (changed) 
tiles.

Original comment by alibhai....@gmail.com on 1 Dec 2013 at 2:43

GoogleCodeExporter commented 9 years ago
Okay, I'll try to get that running. In the meantime, could you try this sample? 
It should first show the cursor for 5 seconds, then it should disappear.

import com.googlecode.lanterna.terminal.swing.SwingTerminal;
public class Issue94 {
    public static void main(String[] args) throws InterruptedException {
        SwingTerminal swingTerminal = new SwingTerminal(80, 20);
        swingTerminal.enterPrivateMode();
        Thread.sleep(5000);
        swingTerminal.setCursorVisible(false);
        Thread.sleep(5000);
        swingTerminal.exitPrivateMode();
    }
}

Original comment by mab...@gmail.com on 2 Dec 2013 at 12:20

GoogleCodeExporter commented 9 years ago
Your sample works well. Integrating it into my code, not so much. I'm using a 
combination of terminal and screen; mostly the screen, except the actual 
writing (because of the full-colour issue) is done directly to the terminal.

If you don't mind taking a look, I tried adding this to the constructor of my 
RgbConsoleScreen; I get weird behaviour (first attempt to draw is empty-screen; 
or I get two terminal windows, one is always blank).

Original comment by alibhai....@gmail.com on 2 Dec 2013 at 10:58

GoogleCodeExporter commented 9 years ago
Any updates on this?

Original comment by alibhai....@gmail.com on 23 Dec 2013 at 10:33

GoogleCodeExporter commented 9 years ago
I've tried to get your code running but with my limited understanding of Gradle 
I haven't had much luck yet. Could you give me some step-by-step instructions 
for how to compile, start and find the issue you describe above?

Original comment by mab...@gmail.com on 16 Feb 2014 at 7:11

GoogleCodeExporter commented 9 years ago
Okay, let's try that first.

Gradle is a tool for many things, primarily (in this context) downloading and 
managing dependencies for my project.

To set it up, you'll need the Gradle Eclipse plugin (from the marketplace). 
Once you do that, you can import the projects as Gradle projects, and build/run 
them. (You may need to right-click, and pick  something like "Gradle > Update 
Dependencies"

If that's too much to try out, I can give you a zip containing everything 
instead. Let me know what works for you.

Original comment by alibhai....@gmail.com on 26 Feb 2014 at 10:30

GoogleCodeExporter commented 9 years ago
This is obvious where the problem is.

When using screen you are doing something like this:

    Terminal terminal = new SwingTerminal(80, 24);
    terminal.setCursorVisible(false);

    Screen screen = new Screen(terminal);
    screen.startScreen();

Have a look into constructor of Screen class, on line 92 there is:

    this.cursorPosition = new TerminalPosition(0, 0);

And have a look into startScreen() function:

        if(cursorPosition != null) {
            terminal.setCursorVisible(true);
            terminal.moveCursor(cursorPosition.getColumn(), cursorPosition.getRow());
        }
        else
            terminal.setCursorVisible(false);

It means that else branch is never executed in this scenario and the function 
setCursorVisible(true); is always called.

The workaround will be probably to fist call startScreen() function and then 
setCursorVisible(false);

Hopefully it won't be hard to fix it.

Original comment by r...@balent.cz on 27 Feb 2014 at 6:02

GoogleCodeExporter commented 9 years ago
Suggested workaround will not work because screen.refresh() will again call 
setCursorVisible(true) in a same way as startScreen() function.

Original comment by r...@balent.cz on 27 Feb 2014 at 6:16

GoogleCodeExporter commented 9 years ago
Yeah, looks like Screen actually sets a cursor position in the start method. 
I'll remove this in the next release. Anyhow, if you call 
setCursorPosition(null) just after startScreen(), does that work?

Original comment by mab...@gmail.com on 30 Mar 2014 at 1:19

GoogleCodeExporter commented 9 years ago
Is this fixed in 2.17?

Original comment by alibhai....@gmail.com on 17 May 2014 at 2:37

GoogleCodeExporter commented 9 years ago
Not sure, I can't actually remember what I did on this one...

Have you tried this?
Terminal terminal = new SwingTerminal(80, 24);
Screen screen = new Screen(terminal);
screen.setCursorPosition(null);
screen.startScreen();

Original comment by mab...@gmail.com on 9 Jun 2014 at 1:12

GoogleCodeExporter commented 9 years ago
That seems to work.

Thanks!

Original comment by alibhai....@gmail.com on 9 Jun 2014 at 7:20

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
P.S. maybe this should be mentioned in the docs somewhere

Original comment by alibhai....@gmail.com on 9 Jun 2014 at 7:23

GoogleCodeExporter commented 9 years ago
Yeah, I'll make sure to update this when I re-write the docs for 3.0

Original comment by mab...@gmail.com on 18 Jun 2014 at 1:04