d0c-s4vage / lookatme

An interactive, terminal-based markdown presenter
https://lookatme.readthedocs.io/en/latest/
MIT License
2.1k stars 62 forks source link

Pressing `q` does not quit presentation after leaving embedded terminal #188

Open napmn opened 1 year ago

napmn commented 1 year ago

Describe the bug Can't use q to quit presentation after using terminal from terminal extension. Using q to quit works when terminal is not used.

To Reproduce Steps to reproduce the behavior:

  1. Open presentation that is using terminal extension (e.g. from examples).
  2. Focus terminal, then press ctrl+a to get focus back to presentation.
  3. If presentation has multiple slides navigate using j / k -> works
  4. Press q to quit presentation -> presentation does not quit but freezes

Expected behavior Pressing q after exiting terminal will quit presentation.

Screenshots Original terminal after killing process from other terminal (i pressed multiple q and Q when trying to exit presentation):

Screenshot 2022-12-11 at 9 42 51

Weird stuff copying into prompt when clicking anywhere in the terminal:

Screenshot 2022-12-11 at 9 43 16

Environment (please complete the following information):

Additional context

Log output:

DEBUG:lookatme.RENDER:Rendering slide 0 DEBUG:lookatme.RENDER: Rendering token {'type': 'heading', 'level': 1, 'text': 'A Plain Terminal'} DEBUG:lookatme.RENDER: Rendering token {'type': 'paragraph', 'text': 'A plain bash terminal:'} DEBUG:lookatme.RENDER: Rendering token {'type': 'code', 'lang': 'md', 'text': 'terminal8\nbash -il\n'} DEBUG:lookatme:Took 1.4066696166992188e-05s to render 25 bytes DEBUG:lookatme.RENDER: Rendering token {'type': 'code', 'lang': 'terminal8', 'text': 'bash -il'} DEBUG:lookatme.RENDER: Rendering token {'type': 'heading', 'level': 1, 'text': 'A Plain Terminal'} DEBUG:lookatme.RENDER: Rendering token {'type': 'paragraph', 'text': 'A plain bash terminal:'} DEBUG:lookatme.RENDER: Rendering token {'type': 'code', 'lang': 'md', 'text': 'terminal8\nbash -il\n'} DEBUG:lookatme:Took 8.106231689453125e-06s to render 25 bytes DEBUG:lookatme.RENDER: Rendering token {'type': 'code', 'lang': 'terminal8', 'text': 'bash -il'} DEBUG:lookatme.RENDER:Rendered slide 0 in 0.14720892906188965 DEBUG:lookatme.RENDER:Rendering slide 1 DEBUG:lookatme.RENDER: Rendering token {'type': 'heading', 'level': 1, 'text': 'Next slide'} DEBUG:lookatme.RENDER: Rendering token {'type': 'paragraph', 'text': 'This is next slide'} DEBUG:lookatme.RENDER: Rendering token {'type': 'heading', 'level': 1, 'text': 'Next slide'} DEBUG:lookatme.RENDER: Rendering token {'type': 'paragraph', 'text': 'This is next slide'} DEBUG:lookatme.RENDER:Rendered slide 1 in 0.0011858940124511719 DEBUG:lookatme:KEY: e DEBUG:lookatme:KEY: c DEBUG:lookatme:KEY: h DEBUG:lookatme:KEY: o DEBUG:lookatme:KEY:
DEBUG:lookatme:KEY: t DEBUG:lookatme:KEY: e DEBUG:lookatme:KEY: s DEBUG:lookatme:KEY: t DEBUG:lookatme:KEY: enter DEBUG:lookatme:KEY: ctrl a DEBUG:lookatme:KEY: j DEBUG:lookatme:KEY: k DEBUG:lookatme:KEY: q DEBUG:lookatme:KEY: backspace DEBUG:lookatme:KEY: ctrl a DEBUG:lookatme:KEY: j DEBUG:lookatme:KEY: q DEBUG:lookatme:Terminating terminal 1/2 DEBUG:lookatme:Terminating terminal 2/2

Let me know if you need some additional info. Thanks!

napmn commented 1 year ago

Some additional info: Pressing q sometimes works when i follow these steps:

  1. starting terminal with bash: bash -il
  2. entering zsh
  3. press ctrl+a
  4. press q

I wrote that it works sometimes because I often get error mention in #139 when entering zsh. I also get this error from time to time if I put zsh as a starting command for the terminal. What I noticed is that this error occurs if the zsh shell is loaded instantly (sometimes it takes ~1sec and in that case the error does not occur).

napmn commented 1 year ago

I just found a solution specific for my setup. My default shell is zsh. When I use bash -il as default terminal command I'm not able to use q to quit. When I use zsh as default terminal command it often crashes as mentioned in the comment above. When I use zsh -fdi (removing all configuration) as default terminal command I am able to navigate and quit after using embedded terminal! 🎉 I'm using oh-my-zsh so that may have some effect I guess.

I'm not sure @d0c-s4vage if this is worth investigating further. If not, feel free to close the issue.

d0c-s4vage commented 1 year ago

@napmn there's some oddness in how the embedded terminal captures keypresses, and especially with knowing if the terminal has focus, and how to make it let go of that focus.

I thought I had an issue open to make this easier to work with, but I'm not finding it. I'll make a new one to specifically address that with:

d0c-s4vage commented 1 year ago

As for the error that you experience sometimes, I haven't been able to reproduce it yet. I'll spend some time trying to figure that one out.

For now though, #191 should handle the visual updates to the terminal. #161 is the issue I was thinking of to make sure keybindings to escape the terminal are set/working correctly

d0c-s4vage commented 1 year ago

Hmm, zsh -fdi doesn't have the same problem... for reference:

wrigleyster commented 1 year ago

typing exit or pressing Ctrl+D, while on an empty line in the terminal, will kill bash, and will subsequently ensure that pressing q exits the presentation without hanging.