Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 924540 - dispatch-conf: Provide wider support for shells & terminal envs
Summary: dispatch-conf: Provide wider support for shells & terminal envs
Status: CONFIRMED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Enhancement/Feature Requests (show other bugs)
Hardware: All Linux
: Normal enhancement
Assignee: Portage team
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2024-02-14 10:12 UTC by thanosapollo
Modified: 2024-02-15 06:00 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description thanosapollo 2024-02-14 10:12:50 UTC
dispatchc-conf does not work with eshell:

Error message:
====
Traceback (most recent call last):
  File "/usr/lib/python-exec/python3.11/dispatch-conf", line 619, in <module>
    d.grind(portage.util.shlex_split(portage.settings.get("CONFIG_PROTECT", "")))
  File "/usr/lib/python-exec/python3.11/dispatch-conf", line 341, in grind
    clear_screen()
  File "/usr/lib/python-exec/python3.11/dispatch-conf", line 568, in clear_screen
    sys.stdout.write(_unicode_decode(curses.tigetstr("clear")))
TypeError: write() argument must be str, not None
====

It's quite simple to fix this by changing clear_screen() to something like this:

```python
def clear_screen():
    if curses is not None:
        try:
            curses.setupterm()
            clear_str = curses.tigetstr("clear")
            if clear_str is not None and os.isatty(sys.stdout.fileno()):
                sys.stdout.write(_unicode_decode(clear_str))
                sys.stdout.flush()
            return
        except curses.error:
            pass
    os.system("clear 2>/dev/null")
```

Now it can handle running in emacs eshell without flushing it. A
modification like this one should provide a wider support for different shells and terminal environments in general.
Comment 1 Zac Medico gentoo-dev 2024-02-15 04:01:34 UTC
Out of curiosity, does the os.system("clear 2>/dev/null") part actually clear the screen for eshell?

Anyway, it seems like we should definitely handle the None return value from curses.tigetstr, since documentation clearly says it can return None in some cases:

https://docs.python.org/3/library/curses.html#curses.tigetstr
Comment 2 thanosapollo 2024-02-15 05:49:18 UTC
(In reply to Zac Medico from comment #1)
> Out of curiosity, does the os.system("clear 2>/dev/null") part actually
> clear the screen for eshell?

Nope, it does not flush the screen. I don't think it'd be possible to flush the screen in eshell unless we try to use something like `subprocess.run(["emacsclient", "--eval", "(eshell/clear-scrollback)"])` but I wouldn't advise that, since flushing the screen is not a must have requirment for dispatch-conf to work properly AFAIK.
Comment 3 thanosapollo 2024-02-15 06:00:17 UTC
extra: the use of the word "flushing" in my above comment is not accurate. I think you get the point still though.