From d237f21a83fb395617acd79d12e13fb648c88631 Mon Sep 17 00:00:00 2001 From: Ari Archer Date: Sun, 28 Nov 2021 20:20:01 +0200 Subject: [PATCH] improved config --- README.md | 2 +- arigram/config.py | 15 +++++++-------- arigram/controllers.py | 22 +++++++++++++--------- arigram/models.py | 2 +- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 6c2c09e..39f20d4 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ This option is recommended: git clone https://github.com/TruncatedDinosour/arigram.git cd git pip install --upgrade --user -r requirements.txt -pip install . +pip install --upgrade --user . ``` And add this to `~/.bashrc` or whatever POSIX complient shell you use: diff --git a/arigram/config.py b/arigram/config.py index 0cdea44..e168992 100644 --- a/arigram/config.py +++ b/arigram/config.py @@ -8,7 +8,6 @@ import runpy from typing import Any, Dict, Optional _os_name = platform.system() -_darwin = "Darwin" _linux = "Linux" @@ -48,8 +47,8 @@ else: ) # TODO: use mailcap instead of editor -LONG_MSG_CMD = "vim + -c 'startinsert' {file_path}" -EDITOR = os.environ.get("EDITOR", "vi") +EDITOR = os.environ.get("EDITOR", "vim") +LONG_MSG_CMD = f"{EDITOR} -- {{file_path}}" if _os_name == _linux: DEFAULT_OPEN = "xdg-open {file_path}" @@ -60,7 +59,7 @@ if _os_name == _linux: if os.environ.get("WAYLAND_DISPLAY"): COPY_CMD = "wl-copy" else: - COPY_CMD = "xclip -selection c" + COPY_CMD = "xclip -selection cliboard" else: COPY_CMD = "pbcopy" @@ -70,7 +69,7 @@ MSG_FLAGS: Dict[str, str] = {} ICON_PATH = os.path.join(os.path.dirname(__file__), "resources", "arigram.png") -URL_VIEW = "urlview" +URL_VIEW = None USERS_COLORS = tuple(range(2, 16)) @@ -94,11 +93,11 @@ else: if not PHONE: print( - "Enter your phone number in international format (including country code)" + "Enter your phone number in international format, including country code (example: +5037754762346)" ) - PHONE = input("phone> ") + PHONE = input("phone: ") if not PHONE.startswith("+"): PHONE = "+" + PHONE - with open(CONFIG_FILE, "w") as f: + with open(CONFIG_FILE, "a") as f: f.write(f"PHONE = '{PHONE}'\n") diff --git a/arigram/controllers.py b/arigram/controllers.py index 6db942c..fd53fc6 100644 --- a/arigram/controllers.py +++ b/arigram/controllers.py @@ -2,6 +2,7 @@ import logging import os import random import shlex +import webbrowser from datetime import datetime from functools import partial, wraps from queue import Queue @@ -120,7 +121,7 @@ class Controller: def open_url(self) -> None: msg = MsgProxy(self.model.current_msg) if not msg.is_text: - return self.present_error("Does not contain urls") + return self.present_error("Does not contain text") text = msg["content"]["text"]["text"] urls = [] for entity in msg["content"]["text"]["entities"]: @@ -137,13 +138,16 @@ class Controller: if not urls: return self.present_error("No url to open") if len(urls) == 1: - with suspend(self.view) as s: - s.call( - config.DEFAULT_OPEN.format(file_path=shlex.quote(urls[0])) - ) + with suspend(self.view) as _: + webbrowser.open(urls[0]) return with suspend(self.view) as s: - s.run_with_input(config.URL_VIEW, "\n".join(urls)) + if config.URL_VIEW is not None: + s.run_with_input(config.URL_VIEW, "\n".join(urls)) + else: + fzf = pyfzf.FzfPrompt() + url = fzf.prompt(urls)[0] + webbrowser.open(url) @staticmethod def format_help(bindings: Dict[str, HandlerType]) -> str: @@ -334,7 +338,7 @@ class Controller: if not self.can_send_msg() or chat_id is None: self.present_info("Can't send msg in this chat") return - with NamedTemporaryFile("r+", suffix=".txt") as f, suspend( + with NamedTemporaryFile("r+", suffix=".md") as f, suspend( self.view ) as s: self.tg.send_chat_action(chat_id, ChatAction.chatActionTyping) @@ -528,7 +532,7 @@ class Controller: def _open_msg(self, msg: MsgProxy, cmd: str = None) -> None: if msg.is_text: - with NamedTemporaryFile("w", suffix=".txt") as f: + with NamedTemporaryFile("w", suffix=".md") as f: f.write(msg.text_content) f.flush() with suspend(self.view) as s: @@ -576,7 +580,7 @@ class Controller: if not msg.can_be_edited: return self.present_error("Meessage can't be edited!") - with NamedTemporaryFile("r+", suffix=".txt") as f, suspend( + with NamedTemporaryFile("r+", suffix=".md") as f, suspend( self.view ) as s: f.write(msg.text_content) diff --git a/arigram/models.py b/arigram/models.py index 7b6a040..b5f946a 100644 --- a/arigram/models.py +++ b/arigram/models.py @@ -604,7 +604,7 @@ class MsgModel: # tdlib could doesn't guarantee number of messages, so we need to # send another request on demand # see https://github.com/tdlib/td/issues/168 - for i in range(3): + for _ in range(3): if len(messages) >= limit + offset: break result = self.tg.get_chat_history(