Skip to content

Commit

Permalink
fix python search
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanCarloMachado committed Oct 19, 2024
1 parent ea704bd commit 540aa0e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 32 deletions.
Binary file modified .DS_Store
Binary file not shown.
13 changes: 1 addition & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,17 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry.scripts]
pys = 'python_search.python_search_cli:main'
python_search = 'python_search.python_search_cli:main'
python_search_search = 'python_search.search.search_ui.kitty:main'
pss = 'python_search.search.search_ui.kitty_search:main'
collect_input = 'python_search.apps.collect_input:main'
clipboard = 'python_search.apps.clipboard:main'
notify_send = 'python_search.apps.notification_ui:main'
browser = 'python_search.apps.browser:main'
run_entry = 'python_search.entry_runner:main'
run_key = 'python_search.entry_runner:main'
generic_data_collector = 'python_search.data_collector:GenericDataCollector.initialize'
ps_container = 'python_search.container:start'
ps_webapi = 'python_search.sdk.web_api_sdk:main'
aps_webapi = 'python_search.sdk.web_api_sdk:main'
chat_gpt = 'python_search.chat_gpt:main'
term_ui = 'python_search.search.search_ui.terminal_ui:main'
entry_builder = 'python_search.entry_capture.entry_inserter_gui.entry_inserter_gui:main'
prompt_editor = 'python_search.apps.prompt_editor:main'
entry_embeddings = 'python_search.next_item_predictor.features.entry_embeddings:main'
entries_editor = 'python_search.entry_capture.entries_editor:main'
register_new_launch_ui = 'python_search.entry_capture.entry_inserter_gui.register_new_gui:launch_ui'
share_entry = 'python_search.share_entry:main'
error_panel = 'python_search.error.error_pane:main'
google_it = 'python_search.apps.google_it:main'
recent_keys = 'python_search.events.latest_used_entries:main'
entry_generator = 'python_search.entry_generator:main'
ps_text_next_predictor = 'python_search.textual_next_predictor.predictor:main'

2 changes: 1 addition & 1 deletion python_search/apps/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ def wrap_cmd_into_terminal(


def get_kitty_cmd(self):
from python_search.search.search_ui.kitty import get_kitty_cmd
from python_search.search.search_ui.kitty_search import get_kitty_cmd
return get_kitty_cmd()
2 changes: 1 addition & 1 deletion python_search/entry_capture/entries_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from python_search.apps.terminal import KittyTerminal
from python_search.core_entities import Key
from python_search.search.search_ui.kitty import get_kitty_cmd
from python_search.search.search_ui.kitty_search import get_kitty_cmd


class EntriesEditor:
Expand Down
5 changes: 3 additions & 2 deletions python_search/python_search_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from python_search.events.run_performed.writer import LogRunPerformedClient
from python_search.host_system.window_hide import HideWindow
from python_search.search.entries_loader import EntriesLoader
from python_search.search.search_ui.kitty import KittySearch
from python_search.search.search_ui.kitty_search import KittySearch
from python_search.search.search_ui.semantic_search import SemanticSearch


Expand Down Expand Up @@ -73,8 +73,9 @@ def __init__(self, configuration: Optional[PythonSearchConfiguration] = None):
self.events = python_search.events
self._semantic_search = SemanticSearch
self._entries_loader = EntriesLoader
self._kitty_search = KittySearch

def search(self, only_fzf=False):
def search(self):
"""
Opens the Search UI. Main entrypoint of the application
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
from python_search.apps.terminal import KittyTerminal
from python_search.host_system.system_paths import SystemPaths
from python_search.environment import is_mac
import sys


SOCKET_PATH = "/tmp/mykitty"
class KittySearch:
"""
Renders the search ui using fzf + termite terminal
Expand Down Expand Up @@ -58,6 +59,8 @@ def get_kitty_complete_cmd(self) -> str:
theme = get_current_theme()
return f"""{self.get_kitty_cmd()} \
--title {self._title} \
--listen-on unix:{SOCKET_PATH} \
-o allow_remote_control=yes \
-o window_padding_width=0 \
-o placement_strategy=center \
-o window_border_width=0 \
Expand All @@ -71,32 +74,38 @@ def get_kitty_complete_cmd(self) -> str:
-o foreground={theme.text} \
-o font_size="{theme.font_size}" \
{terminal.GLOBAL_TERMINAL_PARAMS} \
{SystemPaths.BINARIES_PATH}/term_ui
{SystemPaths.BINARIES_PATH}/term_ui &
"""

@staticmethod
def run() -> None:
if not KittySearch.try_to_focus():
KittySearch().launch()

@staticmethod
def try_to_focus():
def try_to_focus() -> bool:
"""
Focuses the terminal if it is already open
"""
home = os.path.expanduser("~")
if not os.path.exists(f"{home}/mykitty"):
if not os.path.exists(SOCKET_PATH):
print(f"File {SOCKET_PATH} not found")
return False

result = os.system(f'kitty @ --to unix:{home}/mykitty focus-window')
print(result)
cmd = f'{SystemPaths.KITTY_BINNARY} @ --to unix:{SOCKET_PATH} focus-window '
print("Cmd: ", cmd)
result = os.system(cmd)
print(result, "Type: ", type(result))
sys.exit(0)

return result == True
return result == 0

@staticmethod
def focus_or_open(configuration=None):
#if not KittySearch.try_to_focus():
#print("Opening kitty")
if os.environ.get("SKIP_FOCUS"):
KittySearch(configuration).launch()
return

print("Trying to focus")
if KittySearch.try_to_focus():
print("Focused instead of launching")
os.exit(0)
return

KittySearch(configuration).launch()

def get_kitty_cmd(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion python_search/shortcut/mac.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import shutil
from typing import Optional

from python_search.search.search_ui.kitty import KittySearch
from python_search.search.search_ui.kitty_search import KittySearch
from python_search.host_system.system_paths import SystemPaths


Expand Down

0 comments on commit 540aa0e

Please sign in to comment.