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

Rofi mode does not support --use-icons #202

Open
coloursofnoise opened this issue Oct 9, 2024 · 1 comment
Open

Rofi mode does not support --use-icons #202

coloursofnoise opened this issue Oct 9, 2024 · 1 comment

Comments

@coloursofnoise
Copy link

The rofi (non-standalone) mode does not support the --use-icons option, only --hidden-descriptions. I've included a patch that shares code between the standalone and rofi modes (see note for a potential caveat).

Using lbonn's fork for rofi on Wayland.

Note

rofi (at least lbonn's wayland fork) does not use the same entry parsing for the script and dmenu modes. As a result, in script mode I have found that I have to add an empty space at the beginning of every entry: format_characters(...).replace("\x00", " \x00").


diff --git a/src/picker/mode.py b/src/picker/mode.py
index 533bba7..f4be821 100644
--- a/src/picker/mode.py
+++ b/src/picker/mode.py
@@ -16,6 +16,7 @@ from .models import Action, CharacterEntry
 from .paths import *
 from .recent import load_recent_characters, save_recent_characters
 from .typer.typer import Typer
+from .selector.rofi import format_characters
 
 
 class Step(IntEnum):
@@ -128,10 +129,12 @@ class ModeRofimoji:
         if len(recent_characters) > 0:
             state.output += f"\x00message\x1f{recent_characters}\n"
         state.output += "\n".join(
-            self.__format_characters(
+            format_characters(
                 read_characters_from_files(
                     self.args.files, load_frecent_characters() if self.args.frecency else [], self.args.use_additional
-                )
+                ),
+                self.args.use_icons,
+                self.args.show_description
             )
         )
         state.output += "\n"
@@ -143,20 +146,6 @@ class ModeRofimoji:
 
         return " | ".join(pairings)
 
-    def __format_characters(self, characters: List[CharacterEntry]) -> List[str]:
-        if self.args.show_description:
-            return [
-                f"{character.character} {character.description}"
-                for character in characters
-                if character.description != ""
-            ]
-        else:
-            return [
-                f"{character.character}\0meta\x1f{character.description}"
-                for character in characters
-                if character.description != ""
-            ]
-
     def handle_shortcuts(self, state: State) -> None:
         if 10 <= state.return_code <= 19:
             state.processed_characters = load_recent_characters(self.args.max_recent, self.args.files)[
diff --git a/src/picker/selector/rofi.py b/src/picker/selector/rofi.py
index 5062672..81d3f9c 100644
--- a/src/picker/selector/rofi.py
+++ b/src/picker/selector/rofi.py
@@ -5,6 +5,17 @@ from ..abstractionhelper import is_installed
 from ..models import CANCEL, DEFAULT, Action, CharacterEntry, Shortcut
 from .selector import Selector
 
+def format_characters(
+    characters: List[CharacterEntry], use_icons: bool, show_description: bool
+) -> List[str]:
+    if use_icons and not show_description:
+        return [f"\0meta\x1f{entry.description}\x1ficon\x1f<span>{entry.character}</span>" for entry in characters]
+    elif use_icons and show_description:
+        return [f"{entry.description}\0icon\x1f<span>{entry.character}</span>" for entry in characters]
+    elif not use_icons and show_description:
+        return [f"{entry.character} {entry.description}" for entry in characters]
+    else:
+        return [f"{entry.character}\0meta\x1f{entry.description}" for entry in characters]
 
 class Rofi(Selector):
     @staticmethod
@@ -56,7 +67,7 @@ class Rofi(Selector):
 
         rofi = run(
             parameters,
-            input="\n".join(self.__format_characters(characters, use_icons, show_description)),
+            input="\n".join(format_characters(characters, use_icons, show_description)),
             capture_output=True,
             encoding="utf-8",
         )
@@ -81,18 +92,6 @@ class Rofi(Selector):
             action = DEFAULT()
         return action, [characters[int(index)].character for index in rofi.stdout.splitlines()]
 
-    def __format_characters(
-        self, characters: List[CharacterEntry], use_icons: bool, show_description: bool
-    ) -> List[str]:
-        if use_icons and not show_description:
-            return [f"\0meta\x1f{entry.description}\x1ficon\x1f<span>{entry.character}</span>" for entry in characters]
-        elif use_icons and show_description:
-            return [f"{entry.description}\0icon\x1f<span>{entry.character}</span>" for entry in characters]
-        elif not use_icons and show_description:
-            return self.basic_format_characters(characters)
-        else:
-            return [f"{entry.character}\0meta\x1f{entry.description}" for entry in characters]
-
     def __format_recent_characters(self, recent_characters: List[str]) -> str:
         pairings = [f"\u200e{(index + 1) % 10}: {character}" for index, character in enumerate(recent_characters)]
@fdw
Copy link
Owner

fdw commented Oct 9, 2024

Hey, thank you. Could you use your patch to open a PR? That would be easier to review and merge than the patch.

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

2 participants