Re: Exploring terminfo

2021-01-19 Thread Grant Edwards
On 2021-01-19, Grant Edwards wrote: >> >> int tgetent(char *bp, const char *name); >> int tgetflag(char *id); >> int tgetnum(char *id); >> char *tgetstr(char *id, char **area); >> char *tgoto(const char *cap, int col, int row); >> int tputs(const char *str, int affcnt, int

Re: Exploring terminfo

2021-01-19 Thread Grant Edwards
On 2021-01-19, Eli the Bearded <*@eli.users.panix.com> wrote: > Putting my Unix hat on, curses is a "friendly" library around creating > text-windowed applications. Programs like mutt use curses rather than > raw terminal operations, programs like vi use raw terminal operations. > Either curses

Re: Exploring terminfo

2021-01-19 Thread Eli the Bearded
In comp.lang.python, Greg Ewing wrote: > On 18/01/21 3:34 am, Alan Gauld wrote: >> The problem is terminfo is not really part of curses. >> Curses is built on top of terminfo. > As far as I can tell from the man pages, terminfo itself > is just a file format. The only programmatic interfaces I >

Re: Exploring terminfo

2021-01-19 Thread Grant Edwards
On 2021-01-19, Alan Gauld via Python-list wrote: > On 18/01/2021 22:14, Random832 wrote: >> On Fri, Jan 15, 2021, at 13:36, Alan Gauld via Python-list wrote: >>> That could make a big difference, the putp() function specifically >>> states that it writes to stdout. >> >> I think there is a

Re: Exploring terminfo

2021-01-19 Thread Grant Edwards
On 2021-01-19, Greg Ewing wrote: > On 19/01/21 2:34 pm, Alan Gauld wrote: >> To be fair that's a limitation of the C curses library. putp() is a >> wrapper around tputs() even there, and you can't change what it does. >> The gap in the curses module is that it doesn't offer the tputs() >> option

Re: Exploring terminfo

2021-01-18 Thread Greg Ewing
On 19/01/21 2:34 pm, Alan Gauld wrote: To be fair that's a limitation of the C curses library. putp() is a wrapper around tputs() even there, and you can't change what it does. The gap in the curses module is that it doesn't offer the tputs() option as an alternative. Seems to me it would be

Re: Exploring terminfo

2021-01-18 Thread Alan Gauld via Python-list
On 18/01/2021 22:14, Random832 wrote: > On Fri, Jan 15, 2021, at 13:36, Alan Gauld via Python-list wrote: >> That could make a big difference, the putp() function specifically >> states that it writes to stdout. > > I think there is a reasonable argument that this is a deficiency of the > curses

Re: Exploring terminfo

2021-01-18 Thread Grant Edwards
On 2021-01-18, Random832 wrote: > On Fri, Jan 15, 2021, at 13:36, Alan Gauld via Python-list wrote: >> That could make a big difference, the putp() function specifically >> states that it writes to stdout. > > I think there is a reasonable argument that this is a deficiency of > the curses

Re: Exploring terminfo

2021-01-18 Thread Random832
On Fri, Jan 15, 2021, at 13:36, Alan Gauld via Python-list wrote: > That could make a big difference, the putp() function specifically > states that it writes to stdout. I think there is a reasonable argument that this is a deficiency of the curses module. I think that the curses module should

Re: Exploring terminfo

2021-01-17 Thread Greg Ewing
On 18/01/21 3:34 am, Alan Gauld wrote: The problem is terminfo is not really part of curses. Curses is built on top of terminfo. As far as I can tell from the man pages, terminfo itself is just a file format. The only programmatic interfaces I can find for it *are* part of curses:

Re: Exploring terminfo

2021-01-17 Thread Grant Edwards
On 2021-01-17, Grant Edwards wrote: > On 2021-01-17, Greg Ewing wrote: >> On 17/01/21 12:40 pm, Chris Angelico wrote: >>> This is true. However, at some point, the boundary is crossed from >>> Python into the C library. Something, at that point, knows. It's very >>> common to have a flush option

Re: Exploring terminfo

2021-01-17 Thread Grant Edwards
On 2021-01-17, Greg Ewing wrote: > On 17/01/21 12:40 pm, Chris Angelico wrote: >> This is true. However, at some point, the boundary is crossed from >> Python into the C library. Something, at that point, knows. It's very >> common to have a flush option available, so it should be used. > > I'm

Re: Exploring terminfo

2021-01-17 Thread Alan Gauld via Python-list
On 17/01/2021 00:02, Greg Ewing wrote: > On 17/01/21 12:40 pm, Chris Angelico wrote: >> This is true. However, at some point, the boundary is crossed from >> Python into the C library. Something, at that point, knows. It's very >> common to have a flush option available, so it should be used. > >

Re: Exploring terminfo

2021-01-16 Thread Eryk Sun
On 1/16/21, Greg Ewing wrote: > On 17/01/21 12:40 pm, Chris Angelico wrote: >> This is true. However, at some point, the boundary is crossed from >> Python into the C library. Something, at that point, knows. It's very >> common to have a flush option available, so it should be used. > > I'm

Re: Exploring terminfo

2021-01-16 Thread Chris Angelico
On Sun, Jan 17, 2021 at 11:06 AM Greg Ewing wrote: > > On 17/01/21 12:40 pm, Chris Angelico wrote: > > This is true. However, at some point, the boundary is crossed from > > Python into the C library. Something, at that point, knows. It's very > > common to have a flush option available, so it

Re: Exploring terminfo

2021-01-16 Thread Greg Ewing
On 17/01/21 12:40 pm, Chris Angelico wrote: This is true. However, at some point, the boundary is crossed from Python into the C library. Something, at that point, knows. It's very common to have a flush option available, so it should be used. I'm wondering whether the problem in this

Re: Exploring terminfo

2021-01-16 Thread Chris Angelico
On Sun, Jan 17, 2021 at 10:36 AM Greg Ewing wrote: > > On 16/01/21 4:17 pm, Chris Angelico wrote: > > But somewhere along the way, you're finding that there's a problem, > > which implies that SOMETHING is calling on C stdio. That thing, > > surely, should be the thing responsible for flushing? >

Re: Exploring terminfo

2021-01-16 Thread Greg Ewing
On 16/01/21 4:17 pm, Chris Angelico wrote: But somewhere along the way, you're finding that there's a problem, which implies that SOMETHING is calling on C stdio. That thing, surely, should be the thing responsible for flushing? The C library using stdio has no way of knowing that something

Re: Exploring terminfo

2021-01-16 Thread Alan Gauld via Python-list
On 15/01/2021 21:41, Dennis Lee Bieber wrote: > On Fri, 15 Jan 2021 13:19:26 +, Alan Gauld via Python-list > declaimed the following: > >> So the native C functions work as expected. >> Why does the Python wrapper not? > > Are you running Python from a plain command shell, or from

Re: Exploring terminfo

2021-01-15 Thread Grant Edwards
My previous code didn't work if the terminfo entities contained delay specifiers because the delay specifier was left in the output datastream. The case where the terminfo description contains delays, but the delays aren't needed can be handled by simply removing the delay specifiers by wrapping

Re: Exploring terminfo

2021-01-15 Thread Grant Edwards
On 2021-01-16, Cameron Simpson wrote: > On 15Jan2021 18:36, Alan Gauld wrote: >>> One difference is that the name prompt is being written to stdout in >>> the C version and stderr in the Python version. But I don't see why >>> that would matter. >> >>That could make a big difference, the putp()

Re: Exploring terminfo

2021-01-15 Thread Grant Edwards
On 2021-01-16, Greg Ewing wrote: > On 16/01/21 7:33 am, Grant Edwards wrote: > >> Starting in Python 3., python's stdio file objects are _not_ >> on top of the libc FILE streams: they're directly on top of the file >> descriptor. > > This sounds like rather a bad situation, because it means that

Re: Exploring terminfo

2021-01-15 Thread Grant Edwards
On 2021-01-16, Chris Angelico wrote: > On Sat, Jan 16, 2021 at 1:36 PM Greg Ewing > wrote: > >> Can something be done about this? Maybe Python stdio objects >> should flush all the C stdio streams before writing anything? >> > > Surely it should be the other way around? If you use the C stdio >

Re: Exploring terminfo

2021-01-15 Thread Grant Edwards
On 2021-01-15, Grant Edwards wrote: > On 2021-01-15, Grant Edwards wrote: > >> Entities that are parameterized (e.g. goto location) would need to be >> passed through curses.tiparm() before they're decoded and printed. I'm >> goign to try that next. > > The curses module doesn't expose tiparm,

Re: Exploring terminfo

2021-01-15 Thread Chris Angelico
On Sat, Jan 16, 2021 at 2:16 PM Greg Ewing wrote: > > On 16/01/21 3:37 pm, Chris Angelico wrote: > > Surely it should be the other way around? If you use the C stdio > > streams, flush them after use. > > 1. You might not know that you're (implicitly) using C stdio. > > 2. There doesn't seem to

Re: Exploring terminfo

2021-01-15 Thread Greg Ewing
On 16/01/21 3:37 pm, Chris Angelico wrote: Surely it should be the other way around? If you use the C stdio streams, flush them after use. 1. You might not know that you're (implicitly) using C stdio. 2. There doesn't seem to be an easy way to flush C stdio from Python any more. -- Greg --

Re: Exploring terminfo

2021-01-15 Thread Cameron Simpson
On 15Jan2021 18:36, Alan Gauld wrote: >> One difference is that the name prompt is being written to stdout in >> the C version and stderr in the Python version. But I don't see why >> that would matter. > >That could make a big difference, the putp() function specifically >states that it writes

Re: Exploring terminfo

2021-01-15 Thread Chris Angelico
On Sat, Jan 16, 2021 at 1:36 PM Greg Ewing wrote: > > On 16/01/21 7:33 am, Grant Edwards wrote: > > Starting in Python 3., python's stdio file objects are _not_ > > on top of the libc FILE streams: they're directly on top of the file > > descriptor. > > This sounds like rather a bad situation,

Re: Exploring terminfo

2021-01-15 Thread Greg Ewing
On 16/01/21 7:33 am, Grant Edwards wrote: Starting in Python 3., python's stdio file objects are _not_ on top of the libc FILE streams: they're directly on top of the file descriptor. This sounds like rather a bad situation, because it means that any C library using stdio is going to interact

Re: Exploring terminfo

2021-01-15 Thread Grant Edwards
On 2021-01-15, Grant Edwards wrote: > Entities that are parameterized (e.g. goto location) would need to be > passed through curses.tiparm() before they're decoded and printed. I'm > goign to try that next. The curses module doesn't expose tiparm, but you can use tparm instead:

Re: Exploring terminfo

2021-01-15 Thread Grant Edwards
On 2021-01-15, Grant Edwards wrote: > On 2021-01-15, Alan Gauld via Python-list wrote: >> On 15/01/2021 17:31, Grant Edwards wrote: >> >>> I suspect that the problem is that putp is writing to the libc >>> "stdout" FILE stream that's declaredin . That stream >>> layer/object has buffering that

Re: Exploring terminfo

2021-01-15 Thread Grant Edwards
On 2021-01-15, Alan Gauld via Python-list wrote: > On 15/01/2021 17:31, Grant Edwards wrote: > cur.putp(cls) name = input("Hello, what's your name? ") cur.putp(bold) print("Nice to meet you ", name) > > >>> putp(clr); >>> putp(bold); >>> printf("Enter a name:

Re: Exploring terminfo

2021-01-15 Thread Grant Edwards
On 2021-01-15, Alan Gauld via Python-list wrote: > On 15/01/2021 17:31, Grant Edwards wrote: > >> I suspect that the problem is that putp is writing to the libc >> "stdout" FILE stream that's declaredin . That stream >> layer/object has buffering that is invisible to Python. > > That would

Re: Exploring terminfo

2021-01-15 Thread Alan Gauld via Python-list
On 15/01/2021 17:31, Grant Edwards wrote: >>> cur.putp(cls) >>> name = input("Hello, what's your name? ") >>> >>> cur.putp(bold) >>> print("Nice to meet you ", name) >> putp(clr); >> putp(bold); >> printf("Enter a name: "); >> fgets(line, sizeof(line),stdin); >> >>

Re: Exploring terminfo

2021-01-15 Thread Grant Edwards
On 2021-01-15, Grant Edwards wrote: > I suspect that the problem is that putp is writing to the libc > "stdout" FILE stream that's declaredin . That stream > layer/object has buffering that is invisible to Python. Python's > sys.stdout.flush() is flushing the Python file object's output buffers

Re: Exploring terminfo

2021-01-15 Thread Grant Edwards
On 2021-01-15, Alan Gauld via Python-list wrote: > On 14/01/2021 16:12, Alan Gauld via Python-list wrote: > >> # >> import curses as cur >> cur.setupterm() >> >> bold = cur.tigetstr('bold') >> cls = cur.tigetstr('clear') >> >> cur.putp(cls) >> name = input("Hello, what's your

Re: Exploring terminfo

2021-01-15 Thread Alan Gauld via Python-list
On 14/01/2021 16:12, Alan Gauld via Python-list wrote: > # > import curses as cur > cur.setupterm() > > bold = cur.tigetstr('bold') > cls = cur.tigetstr('clear') > > cur.putp(cls) > name = input("Hello, what's your name? ") > > cur.putp(bold) > print("Nice to meet you ", name)

Re: Exploring terminfo

2021-01-15 Thread Alan Gauld via Python-list
On 14/01/2021 22:11, Grant Edwards wrote: > Or use a terminfo library: > > https://github.com/DirectXMan12/py-terminfo > > It _may_ be possible to use ncurses to get the terminfo strings > required for various functions without actually having ncurses to any > I/O, but I've never tried

Re: Exploring terminfo

2021-01-15 Thread Alan Gauld via Python-list
On 14/01/2021 23:08, Grant Edwards wrote: > Alternatively, I think you can use the ncurses library to retrieve the control > strings (just don't use any ncurses input/output calls), like this example > from > https://stackoverflow.com/questions/6199285/tput-cup-in-python-on-the-commandline: > >

Re: Exploring terminfo

2021-01-15 Thread Alan Gauld via Python-list
On 14/01/2021 21:30, Barry Scott wrote: >> During lockdown I've been digging deeper into the curses module >> and lately into the ti family of functions that reside there. > It seems that curses does not allow you to mix raw stdin/stdout with its > calls. That's true of curses after you

Re: Exploring terminfo

2021-01-14 Thread Grant Edwards
On 2021-01-14, Eli the Bearded <*@eli.users.panix.com> wrote: > When I've wanted to do simple things like bold and clear, I've used the > tput(1) tool. You can capture stdout from the tool and use the output > over and over. Typically I've done this in shell scripts: > > #!/bin/sh > bold=$(tput

Re: Exploring terminfo

2021-01-14 Thread Grant Edwards
On 2021-01-14, Barry Scott wrote: > It seems that curses does not allow you to mix raw stdin/stdout with > its calls. (got that idea from a quick web search). That is definitely the case. Output in curses is done to an in-memory virtual terminal screen. Optimized output is then sent (at some

Re: Exploring terminfo

2021-01-14 Thread Eli the Bearded
In comp.lang.python, Barry Scott wrote: > Alan Gauld via Python-list wrote: >> I've written a short program that is supposed to >> - *clear the screen*, >> - read some input >> - display the result in a message *highlighted in bold*. >> - get input to end the program > It seems that curses does

Re: Exploring terminfo

2021-01-14 Thread Barry Scott
> On 14 Jan 2021, at 16:12, Alan Gauld via Python-list > wrote: > > During lockdown I've been digging deeper into the curses module > and lately into the ti family of functions that reside there. > > I've written a short program that is supposed to > - *clear the screen*, > - read some

Exploring terminfo

2021-01-14 Thread Alan Gauld via Python-list
During lockdown I've been digging deeper into the curses module and lately into the ti family of functions that reside there. I've written a short program that is supposed to - *clear the screen*, - read some input - display the result in a message *highlighted in bold*. - get input to end