[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Strange behavior of Ncurses
From: |
Thomas Dickey |
Subject: |
Re: Strange behavior of Ncurses |
Date: |
Sun, 20 Oct 2024 17:43:44 -0400 |
On Sat, Oct 19, 2024 at 11:43:46AM -0400, Thomas Dickey wrote:
> On Fri, Oct 18, 2024 at 03:43:10PM -0400, Thomas Dickey wrote:
> > time permitting, I'll construct a program from the traces and see if there's
> > some improvement that I might make to the optimization (or some
> > recommendation
> > or changes to the terminal description which would address this device).
>
> taking a quick look, however, there's something amiss with those traces.
Revisiting the debugging traces, I see this chunk in space_trace_printout:
EmitRange 3:{"423"}
PutAttrChar({'4' = 064}) at (1, 29)
PutAttrChar({'2' = 062}) at (1, 30)
PutAttrChar({'3' = 063}) at (1, 31)
+ + + + return }
+ + + + called {TransformLine(0x17fb4f0, 2)
GoTo(0x17fb4f0, 2, 29) from (1, 32)
+ + + + + called {_nc_tinfo_mvcur(0x17fb4f0,1,32,2,29)
+ + + + + + called {tparm("\e[%i%p1%d;%p2%dH$<5>", 2, 29)
+ + + + + + return }"\e[3;30H$<5>"
+ + + + + + called {tparm("\e[%p1%dB", 1)
+ + + + + + return }"\e[1B"
+ + + + + + called {tparm("\e[%p1%dD", 3)
+ + + + + + return }"\e[3D"
+ + + + + + called {tparm("\e[%p1%dB", 1)
+ + + + + + return }"\e[1B"
+ + + + + + called {tparm("\e[%p1%dC", 29)
+ + + + + + return }"\e[29C"
+ + + + + + called {tparm("\e[%p1%dB", 2)
+ + + + + + return }"\e[2B"
+ + + + + + called {tparm("\e[%p1%dC", 29)
+ + + + + + return }"\e[29C"
+ + + + + + called {tparm("\e[%p1%dB", 1)
+ + + + + + return }"\e[1B"
+ + + + + + called {tparm("\e[%p1%dD", 3)
+ + + + + + return }"\e[3D"
tputs(mvcur = "\n\b\b\b", 1, _nc_outch) called
+ + + + + return }0
PutRange(0x17fb4f0, 0x18158f0, 0x18089e0, 2, 29, 31)
That shows what ncurses does to decide how to update cells in row 1,
columns 29-31. It calls TransformLine, which in turn asks how to
get from cell 2,29 to 1,29. _nc_tinfo_mvcur checks the costs of
different cursor movements before settling on \n (to go _down_)
and \b (to go left).
Without optimization, you're probably getting the whole line written,
rather than just the cells which are changed. That's almost always
slower. (Someone may have designed a counter example :-).
The \n and \b are what the terminal description has for cud1 and cub1:
cub=\E[%p1%dD, cub1=^H, cud=\E[%p1%dB, cud1=\n,
^^^^^^^ ^^^^^^^
When ncurses reads the terminal description, it assigns costs to using
various capabilities:
CostOf carriage_return 2 "\r"
CostOf cursor_home 6 "\e[H"
CostOf cursor_to_ll 1000000 (null)
CostOf cursor_left 2 "\b"
CostOf cursor_right 26 "\e[C$<2>"
CostOf cursor_down 2 "\n"
CostOf cursor_up 26 "\e[A$<2>"
CostOf enter_insert_mode 1000000 (null)
CostOf exit_insert_mode 1000000 (null)
With a cost of 2, those are inexpensive. If they were \E[D and \E[B
(the simplified versions of cub1 and cud1), those would work, but would
be a cost of 6 rather than 2. ncurses might use a different strategy
in that case, but you would only know by looking at the trace.
However... the \n and \b (as well as \r) all rely upon having the
terminal in raw mode. Otherwise, you would have the terminal driver
interfering by doing _its_ conversion of those characters. Or
(given that this is a non-standard terminal device), _it_ may be
interpreting those characters.
You could work around that by a terminal description that suppresses
those capabilities, e.g.,
eric100|vt100 almost...,
cr@,
cub1@,
cud1@,
ind@,
use=vt100,
and get a workable terminal description without those characters:
eric100|vt100 almost...,
am, mc5i, msgr, xenl, xon,
cols#80, it#8, lines#24, vt#3,
acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
bel=^G, blink=\E[5m$<2>, bold=\E[1m$<2>,
clear=\E[H\E[J$<50>, cr@, csr=\E[%i%p1%d;%p2%dr,
cub=\E[%p1%dD, cub1@, cud=\E[%p1%dB, cud1@, cuf=\E[%p1%dC,
cuf1=\E[C$<2>, cup=\E[%i%p1%d;%p2%dH$<5>,
cuu=\E[%p1%dA, cuu1=\E[A$<2>, ed=\E[J$<50>, el=\E[K$<3>,
el1=\E[1K$<3>, enacs=\E(B\E)0, home=\E[H, ht=^I, hts=\EH,
ind@, ka1=\EOq, ka3=\EOs, kb2=\EOr, kbs=^H, kc1=\EOp, kc3=\EOn,
kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA, kent=\EOM,
kf0=\EOy, kf1=\EOP, kf10=\EOx, kf2=\EOQ, kf3=\EOR, kf4=\EOS,
kf5=\EOt, kf6=\EOu, kf7=\EOv, kf8=\EOl, kf9=\EOw, lf1=pf1,
lf2=pf2, lf3=pf3, lf4=pf4, mc0=\E[0i, mc4=\E[4i, mc5=\E[5i,
rc=\E8, rev=\E[7m$<2>, ri=\EM$<5>, rmacs=^O, rmam=\E[?7l,
rmkx=\E[?1l\E>, rmso=\E[m$<2>, rmul=\E[m$<2>,
rs2=\E<\E>\E[?3;4;5l\E[?7;8h\E[r, sc=\E7,
sgr=\E[0%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;m%?%p9%t\016%e\017%;$<2>,
sgr0=\E[m\017$<2>, smacs=^N, smam=\E[?7h, smkx=\E[?1h\E=,
smso=\E[7m$<2>, smul=\E[4m$<2>, tbc=\E[3g,
u6=\E[%i%d;%dR, u7=\E[6n, u8=\E[?%[;0123456789]c, u9=\EZ,
--
Thomas E. Dickey <dickey@invisible-island.net>
https://invisible-island.net
signature.asc
Description: PGP signature
- Re: Strange behavior of Ncurses, (continued)
- Re: Strange behavior of Ncurses, Thomas Dickey, 2024/10/12
- RE: Strange behavior of Ncurses, Urban Söderberg, 2024/10/16
- Re: ***UNCHECKED*** RE: Strange behavior of Ncurses, Thomas Dickey, 2024/10/16
- RE: ***UNCHECKED*** RE: Strange behavior of Ncurses, Urban Söderberg, 2024/10/17
- Re: ***UNCHECKED*** RE: Strange behavior of Ncurses, Thomas Dickey, 2024/10/17
- RE: ***UNCHECKED*** RE: Strange behavior of Ncurses, Urban Söderberg, 2024/10/18
- Re: ***UNCHECKED*** RE: Strange behavior of Ncurses, G. Branden Robinson, 2024/10/18
- RE: ***UNCHECKED*** RE: Strange behavior of Ncurses, Urban Söderberg, 2024/10/18
- Re: RE: Strange behavior of Ncurses, Thomas Dickey, 2024/10/18
- Re: Strange behavior of Ncurses, Thomas Dickey, 2024/10/19
- Re: Strange behavior of Ncurses,
Thomas Dickey <=