Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ranger crashes when trying to preview a jupyter notebook file #2948

Open
amirhosseindavoody opened this issue Feb 12, 2024 · 2 comments
Open

Comments

@amirhosseindavoody
Copy link

Runtime Environment

  • Operating system and version: SUSE12
  • Terminal emulator and version: zsh 5.0.5
  • Python version: 3.12
  • Ranger version/commit: 1.9.3
  • Locale: en_US.UTF-8

Current Behavior

Ranger crashes when trying to preview a jupyter notebook file.

Expected Behavior

Show the ipynb file preview or at the very least doe not crash and show blank.

Context

Possible Solutions

Steps to reproduce

  1. Open ranger
  2. Move the file selector to a jupyter notebook file

Traceback

ranger version: ranger 1.9.3ll 52.7K 2024-02-09 15:29                                                                                                                                   99.9M sum, 741G free  15/38  12%
Python version: 3.12.1 | packaged by conda-forge | (main, Dec 23 2023, 08:03:24) [GCC 12.3.0]
Locale: en_US.UTF-8
Current file: '/path/to/jupyter/notebook/file/data_cleanup.ipynb'

Traceback (most recent call last):
  File "/nfs/site/home/adavoody/.pixi/envs/ranger-fm/lib/python3.12/site-packages/ranger/core/main.py", line 201, in main
    fm.loop()
  File "/nfs/site/home/adavoody/.pixi/envs/ranger-fm/lib/python3.12/site-packages/ranger/core/fm.py", line 377, in loop
    ui.redraw()
  File "/nfs/site/home/adavoody/.pixi/envs/ranger-fm/lib/python3.12/site-packages/ranger/gui/ui.py", line 333, in redraw
    self.draw()
  File "/nfs/site/home/adavoody/.pixi/envs/ranger-fm/lib/python3.12/site-packages/ranger/gui/ui.py", line 360, in draw
    DisplayableContainer.draw(self)
  File "/nfs/site/home/adavoody/.pixi/envs/ranger-fm/lib/python3.12/site-packages/ranger/gui/displayable.py", line 260, in draw
    displayable.draw()
  File "/nfs/site/home/adavoody/.pixi/envs/ranger-fm/lib/python3.12/site-packages/ranger/gui/widgets/view_miller.py", line 100, in draw
    DisplayableContainer.draw(self)
  File "/nfs/site/home/adavoody/.pixi/envs/ranger-fm/lib/python3.12/site-packages/ranger/gui/displayable.py", line 260, in draw
    displayable.draw()
  File "/nfs/site/home/adavoody/.pixi/envs/ranger-fm/lib/python3.12/site-packages/ranger/gui/widgets/browsercolumn.py", line 187, in draw
    self._draw_file()
  File "/nfs/site/home/adavoody/.pixi/envs/ranger-fm/lib/python3.12/site-packages/ranger/gui/widgets/browsercolumn.py", line 214, in _draw_file
    Pager.draw(self)
  File "/nfs/site/home/adavoody/.pixi/envs/ranger-fm/lib/python3.12/site-packages/ranger/gui/widgets/pager.py", line 109, in draw
    self._draw_line(i, line)
  File "/nfs/site/home/adavoody/.pixi/envs/ranger-fm/lib/python3.12/site-packages/ranger/gui/widgets/pager.py", line 139, in _draw_line
    self.set_fg_bg_attr(*chunk)
  File "/nfs/site/home/adavoody/.pixi/envs/ranger-fm/lib/python3.12/site-packages/ranger/gui/curses_shortcuts.py", line 89, in set_fg_bg_attr
    self.win.attrset(curses.color_pair(get_color(fg, bg)) | attr)
                                       ^^^^^^^^^^^^^^^^^
  File "/nfs/site/home/adavoody/.pixi/envs/ranger-fm/lib/python3.12/site-packages/ranger/gui/color.py", line 32, in get_color
    curses.init_pair(size, fg, bg)
ValueError: Color number is greater than COLORS-1 (7).
@lkschu
Copy link

lkschu commented Apr 4, 2024

I can not reproduce this. What terminal emulator are you using? Are you using the default color scheme or have other modifications?
If I am using a terminal which does not support 256 colors (i.e. TERM=xterm), ranger will not initialize colors.

@Rom1deTroyes
Copy link

Python notebooks are basically JSON files, so they can be previewed out of the box as this :

Preview as JSON file (unhandled type) :
ipynb detected as json file

Preview as UTF8 Unicode Text (whell, it's still Json, but too long ?) :
ipynb preview as json file

Note the filetype of the 2 files :
image

The ValueError here may be related to highlighting setting ?

Can you previsualize a basic JSON file ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants