[arch-general] pacman 6 current/total not displayed on TDE - what does old konsole lack?

Ralph Corderoy ralph at inputplus.co.uk
Sun Dec 12 10:41:11 UTC 2021


Hi David,

> /* Moves console cursor `lines` up */
> void console_cursor_move_up(unsigned int lines)
> {
> 	printf("\x1B[%dF", lines);
> }

It's a shame the code isn't using terminfo(5) so it's portable to
different terminals, including older ones, and less misleading in its
choice of function names and commentary.  By sticking with terminfo's
names we have a lingua franca.

https://invisible-island.net/xterm/ctlseqs/ctlseqs.pdf is very useful
when digging into this kind of thing.  It's from Thomas Dickey,
xterm(1)'s maintainer.

Here's terminfo moving the cursor up N lines, as that function suggests
it does.  ‘cuu’ is in terminfo(5).

    $ seq 4; printf 5; tput cuu 3; printf here
    1
    2here$ 
    3
    4
    5

The tput is using Esc '[' N 'A', not 'F' which that function uses.

    $ tput cuu 3 | od -c
    0000000 033   [   3   A
    0000004

ctlseqs describes this on page 8 as ‘Cursor Up Ps Times (default = 1)
(CUU)’.

console_cursor_move_up()'s 'F' is a few lines down in ctlseqs, described
as ‘Cursor Preceding Line Ps Times (default = 1) (CPL)’.  terminfo(5)
doesn't have ‘cpl’.

The ECMA 48 standard,
https://www.ecma-international.org/wp-content/uploads/ECMA-48_5th_edition_june_1991.pdf,
does have CUU and CPL, logical pages 37 and 35 respectively, physical 51
and 49.  It seems CPL does a CUU and then moves to the first column, as
Carriage Return, CR, logical page 35, often does.

Here's CUU, and then CPL using ECMA 48's definitions.

    $ printf '1\n2\n3\n4\n555\x1b[3Ahere' 
    1
    2  here$ 
    3
    4
    555

    $ printf '1\n2\n3\n4\n555\x1b[3Fhere' 
    1
    here$ 
    3
    4
    555

I'm not saying this is the cause of your problems; I just picked on
console_cursor_move_up() at random, but it shows the folly of not using
terminfo in the time-honoured way and hard-coding escape sequences as if
this were MS DOS.  Hopefully, it's also provided some resources for you
debug more where the problem lies.  I suggest testing the sequences you
find on your terminal.  Also, script(1) may be useful to record what
gets output to the terminal by the program which isn't working.

-- 
Cheers, Ralph.


More information about the arch-general mailing list