Skip to content

Commit

Permalink
updating browser-style
Browse files Browse the repository at this point in the history
  • Loading branch information
xyzpw committed Mar 7, 2024
1 parent 5fb468d commit a077b0b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
hc-client/__pycache__/
venv/
env/
.venv/
.env/
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# hc-client
![GitHub Downloads (all assets, all releases)](https://img.shields.io/github/downloads/xyzpw/hc-client/total)
![python-version](https://img.shields.io/badge/python->=3.10-blue)

A script to connect to [hack.chat](https://hack.chat/) through your terminal.<br><br>

![hc-client-v5-preview](https://github.com/xyzpw/hc-client/assets/76017734/68f662a5-b0a4-42f4-9015-215f5f12cd96)


Expand All @@ -13,8 +17,25 @@ If you are getting execution errors on Linux, you have to add execution perms, y
$ cd $FOLDERNAME
$ pip3 install -r requirements.txt
```
You may have to run `pip3 uninstall websocket` in order to import websocket-client. <br>
The default websocket module is not the one used for this script, but they are both imported with the same name.
If you are not using a pip virtual environment, may may have to run `pip3 uninstall websocket`<br>
The default websocket module is not the one used for this script, but they are both imported with the same name.<br>
#### Creating a Virtual Environment
Using a virtual environment will allow you to use these packages without uninstalling some packages.<br>
This following codeblock will demonstrate how to create one
```bash
$ cd hc-client/
$ python3 -m venv .env
```
You can name your virtual environment anything, but it's recommended to stick with .env or .venv for Github repos.<br>
##### Using Virtual Environments
To enable your virtual environment via bash
```bash
$ source .env/bin/activate
```
To disable
```bash
$ deactivate
```
### Installation via Git
```bash
$ git clone https://github.com/xyzpw/hc-client.git
Expand Down
5 changes: 4 additions & 1 deletion hc-client/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,17 @@ def browserStyle(text, initialColor, resetColorAfterHighlight=True):
if re.search(r"^>.*?$", text):
return text
#NOTE: some terminals don't have support for these
makePattern = lambda val: rf"(?<!(?:`|<|@)){val}(?!\s|\\)(?P<sentence>[^`]*?)(?<!\s|\\){val}(?!(?:`|>))"
makePattern = lambda val: rf"(?<!(?:`|<|@)){val}(?!\s|\\)(?P<sentence>[^`]*?)(?<!\s|\\){val}(?!(?:\x1b|`|>))"
text = re.sub(makePattern("__"), "\x1b[1m\g<sentence>\x1b[22m", text)
text = re.sub(makePattern('_'), "\x1b[3m\g<sentence>\x1b[23m", text)
text = re.sub(makePattern("\*\*"), "\x1b[1m\g<sentence>\x1b[22m", text)
text = re.sub(makePattern("\*"), "\x1b[3m\g<sentence>\x1b[23m", text)
text = re.sub(makePattern("~~"), "\x1b[9m\g<sentence>\x1b[29m", text)
text = removeUnwantedChars(text)
text = re.sub(r"(?<!\S)--(?!\S)", "\u2013", text) # en dash
text = re.sub(r"\(tm\)", "\u2122", text, flags=(re.MULTILINE | re.DOTALL | re.IGNORECASE))
text = re.sub(r"\(c\)", '\u00a9', text, flags=(re.MULTILINE | re.DOTALL | re.IGNORECASE))
text = re.sub(r"\(r\)", "\u00AE", text, flags=(re.MULTILINE | re.DOTALL | re.IGNORECASE))
if resetColorAfterHighlight:
text = re.sub(makePattern("=="), f"{colorama.Back.GREEN}{getColor('black')}\g<sentence>{colorama.Back.RESET}{getColor('reset')}", text)
else:
Expand Down

0 comments on commit a077b0b

Please sign in to comment.