canonical / jhack

Chock-full of Juju hackery.
Apache License 2.0
48 stars 23 forks source link

fix(tail): Restore cursor after empty 'tail' session #117

Closed thp-canonical closed 6 months ago

thp-canonical commented 7 months ago

When running jhack tail and keyboard-interrupting the session without any events observed, live.stop() will never be called, resulting in the terminal cursor state to get corrupted (cursor is hidden in shell).

Fix this by moving the call to live.stop() to the finally block, so that it will always be called.

The cause of this bug is that processor.quit() has an early exit that ended up never calling live.stop():

if not self._rendered:
    self.live.update("No events caught.", refresh=True)
    return

(alternatively, self.live.stop() could be called before the return in the if not self._rendered block)

The rich.live.Live object could be used as a context manager to avoid having to call .stop() explicitly, but for this fix I opted for a minimally-intrusive change. One could create a context manager scope with a Live object in _tail_events() and pass that into Processor's constructor (and move initialization of console and color out of it, most likely).

PietroPasotti commented 6 months ago

Thanks a lot! I've had a shot at this a couple of times before but never figured out why it was happening :)