improved config

This commit is contained in:
Ari Archer 2021-11-28 20:20:01 +02:00
parent 5a7f8469b0
commit d237f21a83
Signed by untrusted user who does not match committer: ari
GPG key ID: A50D5B4B599AF8A2
4 changed files with 22 additions and 19 deletions

View file

@ -69,7 +69,7 @@ This option is recommended:
git clone https://github.com/TruncatedDinosour/arigram.git git clone https://github.com/TruncatedDinosour/arigram.git
cd git cd git
pip install --upgrade --user -r requirements.txt 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: And add this to `~/.bashrc` or whatever POSIX complient shell you use:

View file

@ -8,7 +8,6 @@ import runpy
from typing import Any, Dict, Optional from typing import Any, Dict, Optional
_os_name = platform.system() _os_name = platform.system()
_darwin = "Darwin"
_linux = "Linux" _linux = "Linux"
@ -48,8 +47,8 @@ else:
) )
# TODO: use mailcap instead of editor # TODO: use mailcap instead of editor
LONG_MSG_CMD = "vim + -c 'startinsert' {file_path}" EDITOR = os.environ.get("EDITOR", "vim")
EDITOR = os.environ.get("EDITOR", "vi") LONG_MSG_CMD = f"{EDITOR} -- {{file_path}}"
if _os_name == _linux: if _os_name == _linux:
DEFAULT_OPEN = "xdg-open {file_path}" DEFAULT_OPEN = "xdg-open {file_path}"
@ -60,7 +59,7 @@ if _os_name == _linux:
if os.environ.get("WAYLAND_DISPLAY"): if os.environ.get("WAYLAND_DISPLAY"):
COPY_CMD = "wl-copy" COPY_CMD = "wl-copy"
else: else:
COPY_CMD = "xclip -selection c" COPY_CMD = "xclip -selection cliboard"
else: else:
COPY_CMD = "pbcopy" COPY_CMD = "pbcopy"
@ -70,7 +69,7 @@ MSG_FLAGS: Dict[str, str] = {}
ICON_PATH = os.path.join(os.path.dirname(__file__), "resources", "arigram.png") ICON_PATH = os.path.join(os.path.dirname(__file__), "resources", "arigram.png")
URL_VIEW = "urlview" URL_VIEW = None
USERS_COLORS = tuple(range(2, 16)) USERS_COLORS = tuple(range(2, 16))
@ -94,11 +93,11 @@ else:
if not PHONE: if not PHONE:
print( 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("+"): if not PHONE.startswith("+"):
PHONE = "+" + PHONE PHONE = "+" + PHONE
with open(CONFIG_FILE, "w") as f: with open(CONFIG_FILE, "a") as f:
f.write(f"PHONE = '{PHONE}'\n") f.write(f"PHONE = '{PHONE}'\n")

View file

@ -2,6 +2,7 @@ import logging
import os import os
import random import random
import shlex import shlex
import webbrowser
from datetime import datetime from datetime import datetime
from functools import partial, wraps from functools import partial, wraps
from queue import Queue from queue import Queue
@ -120,7 +121,7 @@ class Controller:
def open_url(self) -> None: def open_url(self) -> None:
msg = MsgProxy(self.model.current_msg) msg = MsgProxy(self.model.current_msg)
if not msg.is_text: 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"] text = msg["content"]["text"]["text"]
urls = [] urls = []
for entity in msg["content"]["text"]["entities"]: for entity in msg["content"]["text"]["entities"]:
@ -137,13 +138,16 @@ class Controller:
if not urls: if not urls:
return self.present_error("No url to open") return self.present_error("No url to open")
if len(urls) == 1: if len(urls) == 1:
with suspend(self.view) as s: with suspend(self.view) as _:
s.call( webbrowser.open(urls[0])
config.DEFAULT_OPEN.format(file_path=shlex.quote(urls[0]))
)
return return
with suspend(self.view) as s: 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 @staticmethod
def format_help(bindings: Dict[str, HandlerType]) -> str: 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: if not self.can_send_msg() or chat_id is None:
self.present_info("Can't send msg in this chat") self.present_info("Can't send msg in this chat")
return return
with NamedTemporaryFile("r+", suffix=".txt") as f, suspend( with NamedTemporaryFile("r+", suffix=".md") as f, suspend(
self.view self.view
) as s: ) as s:
self.tg.send_chat_action(chat_id, ChatAction.chatActionTyping) 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: def _open_msg(self, msg: MsgProxy, cmd: str = None) -> None:
if msg.is_text: if msg.is_text:
with NamedTemporaryFile("w", suffix=".txt") as f: with NamedTemporaryFile("w", suffix=".md") as f:
f.write(msg.text_content) f.write(msg.text_content)
f.flush() f.flush()
with suspend(self.view) as s: with suspend(self.view) as s:
@ -576,7 +580,7 @@ class Controller:
if not msg.can_be_edited: if not msg.can_be_edited:
return self.present_error("Meessage can't 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 self.view
) as s: ) as s:
f.write(msg.text_content) f.write(msg.text_content)

View file

@ -604,7 +604,7 @@ class MsgModel:
# tdlib could doesn't guarantee number of messages, so we need to # tdlib could doesn't guarantee number of messages, so we need to
# send another request on demand # send another request on demand
# see https://github.com/tdlib/td/issues/168 # see https://github.com/tdlib/td/issues/168
for i in range(3): for _ in range(3):
if len(messages) >= limit + offset: if len(messages) >= limit + offset:
break break
result = self.tg.get_chat_history( result = self.tg.get_chat_history(