Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

terminal: where am I?

Is there a variable or a function, which can tell me the actual position of the cursor?

#!/usr/bin/env perl
use warnings;
use 5.012;

use Term::ReadKey;
use Term::Cap;
use POSIX;

my( $col, $row ) = GetTerminalSize();

my $termios = new POSIX::Termios;
$termios->getattr;
my $ospeed = $termios->getospeed;

my $terminal = Tgetent Term::Cap { TERM => undef, OSPEED => $ospeed };

# some movement ...

# at which position (x/y) is the cursor now?
like image 380
sid_com Avatar asked Feb 25 '23 03:02

sid_com


2 Answers

You could use curses instead. It has getcurx() and getcurx(). There is a CPAN module for it (and the libcurses-perl package in Debian or Ubuntu).

like image 131
maxelost Avatar answered Mar 04 '23 00:03

maxelost


I don't think you can determine the cursor position using termcap.

The termutils manual says:

If you plan to use the relative cursor motion commands in an application program, you must know what the starting cursor position is. To do this, you must keep track of the cursor position and update the records each time anything is output to the terminal, including graphic characters.

like image 25
Linus Kleen Avatar answered Mar 03 '23 23:03

Linus Kleen