commit:     9bf46138dbd6577a4346da1cef967bec911fe385
Author:     Ionen Wolkens <ionen <AT> gentoo <DOT> org>
AuthorDate: Wed Aug  7 23:22:25 2024 +0000
Commit:     Ionen Wolkens <ionen <AT> gentoo <DOT> org>
CommitDate: Wed Aug  7 23:25:20 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=9bf46138

app-misc/ranger: backport color-related crash fix

Signed-off-by: Ionen Wolkens <ionen <AT> gentoo.org>

 .../files/ranger-1.9.3-color-crash-fix.patch       | 25 ++++++++++++++++++++++
 ...nger-1.9.3-r1.ebuild => ranger-1.9.3-r2.ebuild} |  4 ++++
 2 files changed, 29 insertions(+)

diff --git a/app-misc/ranger/files/ranger-1.9.3-color-crash-fix.patch 
b/app-misc/ranger/files/ranger-1.9.3-color-crash-fix.patch
new file mode 100644
index 000000000000..4d28c529eca2
--- /dev/null
+++ b/app-misc/ranger/files/ranger-1.9.3-color-crash-fix.patch
@@ -0,0 +1,25 @@
+Backport of crash fix when previewing some files with colors.
+https://forums.gentoo.org/viewtopic-t-1170286.html
+https://github.com/ranger/ranger/commit/82eef55b1664
+https://github.com/ranger/ranger/commit/642d594b8328 (also needed)
+--- a/ranger/gui/color.py
++++ b/ranger/gui/color.py
+@@ -20,5 +20,6 @@
+ DEFAULT_FOREGROUND = curses.COLOR_WHITE
+ DEFAULT_BACKGROUND = curses.COLOR_BLACK
+-COLOR_PAIRS = {10: 0}
++# Color pair 0 is wired to white on black and cannot be changed
++COLOR_PAIRS = {(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND): 0}
+ 
+ 
+@@ -31,4 +32,10 @@
+         try:
+             curses.init_pair(size, fg, bg)
++        except ValueError:
++            # We're trying to add more pairs than the terminal can store,
++            # approximating to the closest color pair that's already stored
++            # would be cool but the easier solution is to just fall back to 
the
++            # default fore and background colors, pair 0
++            COLOR_PAIRS[key] = 0
+         except curses.error:
+             # If curses.use_default_colors() failed during the initialization

diff --git a/app-misc/ranger/ranger-1.9.3-r1.ebuild 
b/app-misc/ranger/ranger-1.9.3-r2.ebuild
similarity index 94%
rename from app-misc/ranger/ranger-1.9.3-r1.ebuild
rename to app-misc/ranger/ranger-1.9.3-r2.ebuild
index 161d96848cd0..28989e2d080d 100644
--- a/app-misc/ranger/ranger-1.9.3-r1.ebuild
+++ b/app-misc/ranger/ranger-1.9.3-r2.ebuild
@@ -25,6 +25,10 @@ SLOT="0"
 
 distutils_enable_tests pytest
 
+PATCHES=(
+       "${FILESDIR}"/${P}-color-crash-fix.patch
+)
+
 src_prepare() {
        distutils-r1_src_prepare
 

Reply via email to