bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using ncurses only for terminfo (no I/O)


From: Grant Edwards
Subject: Re: Using ncurses only for terminfo (no I/O)
Date: Tue, 19 Jan 2021 15:05:16 -0000 (UTC)
User-agent: slrn/1.0.3 (Linux)

On 2021-01-19, Thomas Dickey <dickey@his.com> wrote:
> On Fri, Jan 15, 2021 at 11:22:33PM -0000, Grant Edwards wrote:
>> I've recently been working with ncurses from Python, and would like to
> ...
>> The basic 'problem' is that tputs and putp write to libc's FILE
>> *stdout stream. Python's normal output mechanisms have their own
>> buffering and write to file descriptor 1 instead of FILE
>> *stdout. Therefore, "normal" Python output can't be mixed with putp()
>> or tputs() calls without a fair amount of ugliness[1].
>
> Actually, tputs doesn't necessarily write to stdout (the python
> binding might need some work, but that's out of scope):
>
> man tputs:
>
>        int tputs(const char *str, int affcnt, int (*putc)(int));
>                                               ^^^^^^^^^^^^^^^^ (no stdout)

You're right.

Tputs() could be used, but the Python curses module doesn't provide
tputs(), it only provides putp(). That may have made made sense many
years years ago when Python's oputput functions also wrote to FILE
*stdout, but they don't do that now. IMO, the Python curses module
should probably be changed to provide tputs(). What would be most
useful is a function that just replaces the padding specifier with the
NUL bytes and returns a new byte string. If tputs() were available it
could be used to do that.

FWIW, if anybody actually cares about using the terminfo functions
from Python, I've written up notes and examples showing how to work
around the FILE *stdio problem:

  https://github.com/GrantEdwards/Python-curses-and-terminfo






reply via email to

[Prev in Thread] Current Thread [Next in Thread]