Small print tool for implementing chat in the terminal
Project description
Small print tool for implementing chat in the terminal.
https://pypi.org/project/print_chat/
Usage example
import print_chat as pc
pct = pc.print_chat()
sender = 'Charls'
pct.set_colors([('Charls', 'green')])
while True:
post = str(input('> '))
if post == 'exit':
break
else:
pct.up_on_occupied_rows(len(post) + len(sender) + 2)
pct.add_message('Charls', post)
pct.close()
For testing the main functionality:
import print_chat as pc
pct = pc.print_chat(time=True)
s = 0 # sender iterator
senders = ['Charls', 'Max', 'Karl']
pct.set_colors([
(senders[0], 'green'),
(senders[1], 'red'),
(senders[2], 'yellow')
])
pct.set_header('-Test chat-\n-----------') # adding a header to the dialog
while True:
post = str(input('> '))
pct.up_on_occupied_rows(len(post) + len(senders[s]) + 2)
command = post.split(' ')
if post == 'exit': break
elif command[0] == 'remove': pct.remove(int(command[1]))
elif command[0] == 'edit': pct.edit(int(command[1]), ' '.join(command[2:]))
elif command[0] == 'reload': pct.reload(int(command[1]))
elif command[0] == 'add_skip': pct.add_skip(int(command[1]), str(' '.join(command[2:])))
elif command[0] == 'edit_skip': pct.edit_skip(int(command[1]), ' '.join(command[2:]))
elif command[0] == 'remove_skip': pct.remove_skip(int(command[1]))
elif command[0] == 'add_mark': pct.add_mark(int(command[1]), str(command[2]))
elif command[0] == 'edit_mark': pct.edit_mark(int(command[1]), str(command[2]))
elif command[0] == 'remove_mark': pct.remove_mark(int(command[1]))
elif post == 'cs': s = (s+1) % len(senders) # change sender to next
else: pct.add_message(senders[s], post)
pct.close()
Important
Numbering starts at 1, at the end of the message list
This is not a bug this is a feature
Create object
default:
pct = print_chat.print_chat(time=False)
time - show message sending time
Method list
.add_message(sender, text, time=’’, skip=[], mark=[])
.add_message_top(sender, text, time=’’, skip=[], mark=[], prnt=True)
.reload(number)
.remove(number)
.edit(number, text)
.add_skip(number, text)
.edit_skip(number, text)
.remove_skip(number)
.add_mark(number, text)
.edit_mark(number, text)
.remove_mark(number)
.close(clr) - closes the dialog, with or without screen clearing
.set_header(string)
- .set_colors(colors) - takes a list [[sender, color],..]
- colors list:
grey
red
green
yellow
blue
magenta
cyan
white
.get_num_messages() - returns the number of messages
.get_messages()
.get_messages_from(sender)
.up_on_occupied_rows(len_str)
.up_on_message(number)
.up_on_rows(number)
.clear_row()
._clear_screen()
.get_senders() - returns a list of dictionaries
Installation
$ pip install print_chat
or
Repository cloning
$ git clone https://github.com/IVIGOR13/print_chat.git
Tuning
$ pip install termcolor
$ pip install colorama
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file print_chat-0.4.tar.gz
.
File metadata
- Download URL: print_chat-0.4.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15122a02a0de60727d23bc380adf5fbd0ff27d9ddf8bc6333d11b0b5b4eed139 |
|
MD5 | c68ec484278f9977b726c30274a49b3f |
|
BLAKE2b-256 | 570a74c119b687f1f8bb5b2314767e4ef4b0ab006584c2159797ea1b5b49c3e1 |