Commit Graph

872 Commits

Author SHA1 Message Date
rillig
609d11bc47 libcurses: fix wrong tab width for addch
In sysinst, the installation screen is indented with tabs.  Sysinst uses
msgc, which brings its own text layout engine.  This engine does not use
addbytes but addch.  In addch, the x position for each tab was advanced
twice as much as needed.  The menu items were thus not indented by 8
spaces but by 16, which caused an ugly line break in the German
translation.

This bug largely went unnoticed because most other applications use
addbytes instead, which worked fine all the time.  It had been
introduced somewhere between NetBSD 8.0 and NetBSD 9.0.

The code around this bug used aliased variables for win->curx and
win->cury a lot.  Getting this right is difficult and needs a thorough
test suite.  Even though libcurses has 201 tests, that is not nearly
enough to cover all the relations between the various functions in
libcurses that call each other, crossing API boundaries from internal
to external, doing character conversions on the way and juggling around
4 different types of characters (char, wchar_t, chtype, cchar_t).

The simplest fix was to remove all this aliasing, while keeping the
API the same.  If _cursesi_waddbytes is not considered part of the API,
it would be possible to replace px with win->curx in all places, same
for py and win->cury.

The complicated code with the aliasing may have been meant for
performance reasons, but it's hard to see any advantage if both points
of truth need to be synchronized all the time.

Libcurses can be built in 2 modes: with wide character support or
without (-DDISABLE_WCHAR).  The test suite only covers the variant with
wide characters.  The single-byte variant has to be tested manually.
Running sysinst with the single-byte libcurses produces the correct
layout.
2021-02-13 14:30:37 +00:00
rillig
76716cd400 curses.h: proofread, indent a bit more consistently 2021-02-13 10:37:00 +00:00
rillig
a9a73810b2 curses_screen.3: fix typo 2021-02-07 23:00:57 +00:00
rillig
ae30211ba7 libcurses: fix spelling in comment 2021-02-06 19:41:14 +00:00
rillig
e89f2cb186 libncurses: fix grammar in manual page 2021-02-06 13:58:09 +00:00
uwe
ccb2ee4b73 newwin - fix crash with negative ncols.
When support for negative nrows/ncols was added, one s/ncols/maxx/ was
missed so we ended up passing negative (i.e. huge unsigned) length
when hashing the line contents.

Reported by Naman Jain in PR lib/55484
2020-07-14 04:39:39 +00:00
uwe
70f6ed9ef6 Pads are not to be automatically refreshed on input.
X/Open Curses says in the documentation for newpad():

  Automatic refreshes of pads (e.g., from scrolling or echoing of
  input) do not occur.

And in the documentation for get*():

  If the current or specified window is not a pad, and it has been
  moved or modified since the last refresh operation, then it will be
  refreshed before another character is read.

From Michael Forney in PR lib/55457
2020-07-06 23:33:38 +00:00
uwe
f6dea36d0e mvwins*(WINDOW *win, ...) functions - call wins* on win, not stdscr.
From Naman Jain in PR lib/55460.
2020-07-06 22:46:50 +00:00
uwe
71a0f0ceb5 wtouchln - verify/clip input parameters
From Naman Jain in PR lib/55454
2020-07-03 23:28:51 +00:00
uwe
939fb589cb setcchar - don't lose combining marks to a typo.
We copy len wchars but set the length field to 1, instead of len.
From Naman Jain in PR lib/55443
2020-07-02 23:43:01 +00:00
uwe
1765a45b05 hline, vline - don't lose attributes when using default character.
Make default (wide) and non-wide behavior match.  If the character
argument has (only) attributes set, use them with the default line
character.

In the wide case don't do the fallback in hline - it just calls
hline_set that needs to do it anyway.  Fix the latter to check the
wcwidth of the right character and avoid division by zero.
2020-07-01 02:57:01 +00:00
uwe
4eb5fad78b Oops. Fix y/x typo in the previous whline() fix for !HAVE_WCHAR. 2020-07-01 02:14:41 +00:00
uwe
d9a8ae84b1 Fix indentation in the copyright.
Make it match its siblings in other files.
2020-06-30 21:27:18 +00:00
uwe
9c6a61e7ae whline - save/restore the y coordinate too.
Reaching the right side of the screen can cause a line wrap.
Forgot to apply the fix to the !HAVE_WCHAR case.
PR lib/55434
2020-06-30 21:10:13 +00:00
uwe
1eecb61d77 whline_set - save/restore the y coordinate too.
Reaching the right side of the screen can cause a line wrap.
PR lib/55434
2020-06-30 21:02:24 +00:00
simonb
a5e6defa61 KNF nit. 2020-05-14 11:50:04 +00:00
wiz
e9fe6f785f Fix synopsis, use more markup. 2020-03-23 16:14:20 +00:00
roy
41aea6ac80 Add missing man page for curses mouse functions. 2020-03-23 15:32:56 +00:00
roy
bb2ce1fb3d curses: Add stubs for mouse functions
No mouse support actually included.
But that doesn't matter because most terms don't actually support a mouse.

We should look into hooking these into wsmouse(4) and xterm mouse
in the future.

Compatable with nCurses mouse API version 2.
2020-03-23 13:37:36 +00:00
uwe
eea4ed980c werase, wclrtobot, wclrtoeol - make code even more similar.
Rename attr to battr to match bch and WINDOW::battr.
No functional change intended.
2020-03-15 01:18:43 +00:00
uwe
878e2e095f __NEED_ERASE - don't shadow __LDATA::attr with macro parameter name. 2020-03-15 01:12:47 +00:00
roy
aadfdb111b terminfo: promote numeric parameters from short to int
POSIX mandates implementations must support upto a short but may exceed it.
When NetBSD terminfo was implemented, no terminfo description used over
a short, but because ncurses has supported ints for some time, some now do.

Infact, such a terminfo description was imported where colour pairs for
screen-256color went up to 65536 which exposed a bug in the existing
implementation where it set to zero. Because the number might mean
something more than a range, we need to be able to store it accurately.

This requires a version bump because whilst the API hasn't changed thanks
to C int promotion, the ABI has. Also the underlying database structure
has changed as well - we now store the numeric paramter inside a uint32_t
field rather than a uint16_t one.
Whilst this change can still read the old style database, the old one
cannot read the new one and thus we now maintain the database as
terminfo2.cdb, leaving the old library and database alone so old programs
still work fine.

libcurses, libfrom, libmenu and libpanel have also been bumped to
accomoate this change.
2020-03-13 15:19:24 +00:00
roy
66ae8b28c2 curses: wrap the erase logic in a macro
Easier to use, it's in one place and now hopefully everyone is happy.

X
2020-03-13 02:57:26 +00:00
roy
8a456320fe curses: use perror rather than err in initscr
libhack lacks err and perror is more portable.
2020-03-12 15:50:11 +00:00
roy
d93d20bc2b curses: normalise erase logic with clrtoeol and clrtobot
Define WA_ATTRIBUTES as 0 for the non wide case just to make our code
easier to write.
2020-03-12 12:17:15 +00:00
roy
8e383c4d06 curses: note the change in initscr in our fine man page. 2020-03-12 11:38:28 +00:00
roy
63d07d6408 curses: Fix werase(3) wide character support
We need to consider erasing all attributes, not just WA_ATTRIBUTES.
Fixes PR lib/23910.

While here, make the function a little more readable.
2020-03-11 23:47:40 +00:00
roy
5e81f724dc curses: application should exit if initscr(3) fails
POSIX defines this behaviour here:
https://pubs.opengroup.org/onlinepubs/7908799/xcurses/initscr.html

Partial fix for PR lib/23910
2020-03-11 21:33:38 +00:00
rin
4ecd76e535 0x%p --> %p for non-external codes. 2020-02-24 12:20:29 +00:00
roy
cc96515f67 curses: believe in unicorns
Hopefully this ends the bikeshed.
If you don't believe in unicorns, please #if 0 it out to preserve
the humour.
2019-09-03 13:43:34 +00:00
roy
b02c2cea81 curses: Add __NetBSD_Curses_Version__
Similar to __NetBSD_Version__ from sys/param.h but has no
correlation to it or the ELF symver libcurses is built as.

If we say that v1 was everything prior to this, it makes sense to
start this from v2.
2019-09-03 10:36:17 +00:00
roy
c977d4cfab curses(3): add curses_version()
Returns NetBSD-Curses %s
Where %s is the NetBSD version taken from sys/param.h

Discussed on tech-net@, only for ncurses compat.
2019-09-02 09:08:29 +00:00
sevan
7cc04b4007 typo 2019-07-28 14:28:50 +00:00
uwe
4753bc1e70 __slk_set_finalise - fix length vs. width confusion 2019-07-28 00:51:59 +00:00
uwe
96ffe7929a __slk_set - fix calculating "len" for HAVE_WCHAR 2019-07-28 00:15:38 +00:00
sevan
5442ac99a4 nit 2019-07-27 16:15:58 +00:00
sevan
09453b8368 list the wide variant of functions. 2019-07-27 16:00:02 +00:00
uwe
7cefafafd5 Put slk_color() undef #ifdef HAVE_WCHAR too. 2019-07-27 00:58:34 +00:00
uwe
acf023e482 Put wide character functions under #ifdef HAVE_WCHAR 2019-07-27 00:46:43 +00:00
uwe
7e8b9e03e4 #ifdef HAVE_WCHAR around enhanced curses stuff. 2019-07-25 20:18:50 +00:00
blymn
cb5c29f5ae Fix return for mvscanw to return ERR/OK instead of the number of
elements scanned, now matches SUSv2 specification

Bump lib major due to return change.
2019-06-30 22:16:20 +00:00
blymn
febeea01e0 Fix typo for unknown key keyname return. 2019-06-11 10:17:24 +00:00
blymn
2a780e62ed Rework previous fix for getch cursor position when cursor is moved
without refresh.  If the window is not dirty but the window cursor
position does not match curscr then move the cursor.  This fixes
the issues seen in PR lib/54263.
2019-06-09 07:40:14 +00:00
blymn
e2cfd49c61 Back out incorrect fix for PR 53617 and fix it in a different way.
Keep track of the cursor location, if getch is called without a refresh
and without pending updates (dirty windows) then move the cursor to the
correct location directly.  Doing this prevents unnecessary refreshes.
2019-05-20 22:17:41 +00:00
blymn
652cdcd214 Fix _cursesi_addwchar so that it performs line wrap. SUSv2 says
add_wch line wraps and updates position.  Since wrap is done we are
not past EOL.
2019-05-12 02:29:00 +00:00
blymn
d63c9d29fb Add more debug to _wnoutrefresh 2019-05-12 02:19:23 +00:00
blymn
7d6b8c3110 Add/improve debug output for some routines. 2019-04-24 07:09:44 +00:00
roy
69f3641e49 printw: rework vw_printw so it uses open_memstream rather than funopen2
This makes it more portable as open_memstream is POSIX and fixes a
potential issue with wide characters not fully being printed
due to any buffer overflow.
2019-04-01 11:39:15 +00:00
roy
fb513c8258 Minor adjustment to prior to match putch 2019-03-29 18:32:45 +00:00
roy
c571d3a4f2 Use WCOL rather than wcwidth(3) as we should already know the width
during refresh.
Ensure the character width is not negative when advancing during refresh
(unlikely) and we actually have something to insert in the lower right
corner depending on terminal caps.

Fixes PR lib/54085
2019-03-29 16:56:58 +00:00