~marnold128/vsss

9347f4d73c21fbb27ccce0a9ed17a450828ca8e6 — Matt Arnold a month ago 2423c48
Spot the bug
3 files changed, 36 insertions(+), 6 deletions(-)

M emojifilter.py
M vsss.conf.in.matt
M vsss_cmd.sh
M emojifilter.py => emojifilter.py +27 -2
@@ 7,9 7,30 @@ import re
import json
from sys import stdin, stdout, exit
import emoji
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('-s', '--scope', help='a context scope for filtering')
args = parser.parse_args()

def extract_urls(text):
    """Extract URLs from a given text."""
    url_pattern = re.compile(r'(?i)\b((?:https?|ftp|gopher|gemini|ssh)://(?:www\.)?[^\s/$.?#].[^\s]*)\b')
    return url_pattern.findall(text)

def replace_urls(text, urls):
    """Replace URLs in the text with their corresponding numbers."""
    for i, url in enumerate(urls, start=1):
        text = text.replace(url, f'[{i}]')
    return text

if not args.scope:
    replfile = os.path.expanduser("~/.vsss/replace.json")
else:
    if not args.scope.endswith(".json"):
        args.scope = args.scope + ".json"
    replfile = os.path.join(os.path.expanduser("~/.vsss"), args.scope)

replfile = os.path.expanduser("~/.vsss/replace.json")
output = StringIO()

repld = {}


@@ 23,16 44,20 @@ newout = None
with open(replfile) as fp:
    repld = json.loads(fp.read())

urls_list = extract_urls(ourinput)
newout = replace_urls(ourinput, urls_list)

for key in repld:
    newout = re.sub(key, repld[key], ourinput)


for ch in newout:
    if emoji.is_emoji(ch):
        output.write(emoji.demojize(ch))
    else:
        output.write(ch)

for i, url in enumerate(urls_list, start=1):
    output.write(f"[{i}]: {url}\n")
# Now we come to the weird/non self explainitory parts
# we need to copy the output buffer char by char ending 
# in \n for follow along highlighting to work properly for backends

M vsss.conf.in.matt => vsss.conf.in.matt +3 -3
@@ 4,8 4,8 @@ PIPE_COLOR="1;33;45m"
export PIPE_COLOR
audio_bckend="padsp"
spkedit="pluma" 
PATH=/home/matt/pkg/bin:$PATH
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/matt/pkg/lib64
#PATH=/home/matt/pkg/bin:$PATH
#LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/matt/pkg/lib64
speak_bckend() {
    if [ -f /tmp/vsss.lock ]
    then


@@ 15,7 15,7 @@ speak_bckend() {
	touch /tmp/vsss.lock
    fi
    cat $1 | ./emojifilter.py > $1.new
    mv $1.new $1
    cat $1.new > $1
    $audio_bckend swift -n $VOX -p "speech/rate=$rate" -f $1 -m text -t |  ./pcg 
    rm /tmp/vsss.lock
    return 1

M vsss_cmd.sh => vsss_cmd.sh +6 -1
@@ 7,7 7,12 @@
## Modified: 2/15/2014
. ./vsss_funclib.sh


export progname="VSSS"
unix=`uname`
if [ $unix == "Linux" ];
then 
	printf $progname > /proc/$$/comm
fi
# SNARF_CMD  gets the current clipboard contents
# Ways of doing this will very depending on desktop env/window managers