jmespath-community / jmespath.terminal

JMESPath exploration tool in the terminal
Apache License 2.0
9 stars 1 forks source link

Error when piping JSON to jpterm #1

Closed chriscroome closed 1 year ago

chriscroome commented 1 year ago

Thanks @springcomp for forking and updating this project :slightly_smiling_face:.

I have found that piping into jpterm generates an error:

cat defaults/main.yml | yq -o=json | jpterm 
Traceback (most recent call last):
  File "/home/chris/.local/bin/jpterm", line 6, in <module>
    jpterm.main()
  File "/home/chris/.local/pipx/venvs/jmespath-community-terminal/lib/python3.11/site-packages/jpterm.py", line 231, in main
    display.main(screen=screen)
  File "/home/chris/.local/pipx/venvs/jmespath-community-terminal/lib/python3.11/site-packages/jpterm.py", line 148, in main
    self.loop.run()
  File "/home/chris/.local/pipx/venvs/jmespath-community-terminal/lib/python3.11/site-packages/urwid/main_loop.py", line 287, in run
    self._run()
  File "/home/chris/.local/pipx/venvs/jmespath-community-terminal/lib/python3.11/site-packages/urwid/main_loop.py", line 385, in _run
    self.event_loop.run()
  File "/home/chris/.local/pipx/venvs/jmespath-community-terminal/lib/python3.11/site-packages/urwid/main_loop.py", line 790, in run
    self._loop()
  File "/home/chris/.local/pipx/venvs/jmespath-community-terminal/lib/python3.11/site-packages/urwid/main_loop.py", line 827, in _loop
    self._watch_files[fd]()
  File "/home/chris/.local/pipx/venvs/jmespath-community-terminal/lib/python3.11/site-packages/urwid/raw_display.py", line 417, in <lambda>
    event_loop, callback, self.get_available_raw_input())
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chris/.local/pipx/venvs/jmespath-community-terminal/lib/python3.11/site-packages/urwid/raw_display.py", line 449, in get_available_raw_input
    codes = self._get_gpm_codes() + self._get_keyboard_codes()
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chris/.local/pipx/venvs/jmespath-community-terminal/lib/python3.11/site-packages/urwid/raw_display.py", line 523, in _get_keyboard_codes
    code = self._getch_nodelay()
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/chris/.local/pipx/venvs/jmespath-community-terminal/lib/python3.11/site-packages/urwid/raw_display.py", line 661, in _getch_nodelay
    return self._getch(0)
           ^^^^^^^^^^^^^^
  File "/home/chris/.local/pipx/venvs/jmespath-community-terminal/lib/python3.11/site-packages/urwid/raw_display.py", line 571, in _getch
    return ord(os.read(fd, 1))
           ^^^^^^^^^^^^^^^^^^^
TypeError: ord() expected a character, but string of length 0 found

But writing a file and opening it work fine:

cat defaults/main.yml | yq -o=json > ~/tmp/ansible_defaults.json
jpterm ~/tmp/ansible_defaults.json

This isn't a big or urgent problem!

This is on Debian Bookworm with a pipx installed version:

which jpterm
/home/chris/.local/bin/jpterm
/home/chris/.local/bin/jpterm --version
jmespath-term 1.1.1
/usr/bin/python3 --version
Python 3.11.2
springcomp commented 1 year ago

This unfortunately is a bug in urwid. I have no idea how to solve this ☹

chriscroome commented 1 year ago

The urwid library looks like it needs some updating... perhaps simply remove support for piping or just update the documentation to say it doesn't work for now? :shrug:

springcomp commented 1 year ago

The urwid library looks like it needs some updating... perhaps simply remove support for piping or just update the documentation to say it doesn't work for now? 🤷

In fact, even if I disable piping from jpterm the very fact of piping is detected by the underlying urwid library. Somehow, I need to find how to instructions to disable piping at the urwid level. But I have a hard time finding relevant documentation.

In any case, sure, I will eventually update the README anyway and include a Known Issues section.