[SOLVED] Getting cursor position in console

I am trying to get cursor position using stdin/stdout.

import sys.io.File;

class Test {
	static final esc = "\x1B[";
	static final stdout = Sys.stdout();
	static final stdin = Sys.stdin();

	static function main() {
		stdout.writeString(esc + "6n");
		var log = stdin.readUntil("R".code);

		File.saveContent("./log.txt", log);
	}
}

The problem is that the file is written only after pressing Enter.

Hi!
I’ve been doing some research around this kind of things recently…
It seems like you’d have to switch the terminal to ‘raw’ mode which… I don’t think is possible in Haxe directly (without extending through native extensions).

1 Like

Thank you. Here’s what I was able to find out. It is possible to do this on cpp, hl/c, java, nodejs and python targets. Not sure about other targets. I did it in nodejs:

import js.Syntax;
import sys.io.File;

class Main {
	static final esc = "\x1B[";
	static final stdout = Sys.stdout();
	static final stdin = Sys.stdin();

	static function main() {
		#if nodejs
		Syntax.code("process.stdin.setRawMode(true);");
		#end 
		stdout.writeString(esc + "6n");
		var log = stdin.readUntil("R".code);

		File.saveContent("./log.txt", log);
	}
}

Also in VSCode Integrated Terminal I get an error, but Konsole and xterm works.