Skip to content

Commit 83c2d3d

Browse files
author
Tim-ats-d
committed
Optimisation of getkey method. Rewrite of code documentation. text argument is now wrapped to not go out the dialog box. Add posssibility to pass curses attrbuts via text_attributes argument in word_by_word and char_by_char methods and in dialog box title. Title of dialog box is now set to bold by default. Add a new example file nammed text_attributes.py. Add and improve code comments and examples. Fix some typo in file.
1 parent 9db0ebd commit 83c2d3d

File tree

6 files changed

+536
-200
lines changed

6 files changed

+536
-200
lines changed

README.md

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,60 @@
1-
# Visual Dialog (BETA)
2-
A library to make easier **dialog box** in **terminal** with [curses](https://docs.python.org/3/library/curses.html).
1+
<p align="center">
2+
<img width="300" src="https://user-images.githubusercontent.com/59396366/100594532-188c6900-32fa-11eb-8372-4796f53b122f.png" alt="Visual-dialog">
3+
<br><br>
4+
Library to make easier dialog box in terminal.
5+
</p>
36

4-
![example](https://user-images.githubusercontent.com/59396366/98136859-a9218600-1ec1-11eb-9419-4ac5bfde2406.png)
7+
<p align="center">
8+
<a href="#features">Features</a> •
9+
<a href="#installation">Installation</a> •
10+
<a href="#documentation">Documentation</a> •
11+
<a href="#quick-start ">Usage</a> •
12+
<a href="#contributing">Contributing</a> •
13+
<a href="#license">License</a>
14+
</p>
515

16+
<div align="center">
17+
<img src="https://user-images.githubusercontent.com/59396366/100640592-e3523c00-3336-11eb-8793-19a0543be8d0.gif" alt="Demo">
18+
</div>
619

7-
## Documentation
8-
Coming soon.
20+
## Features
21+
22+
📃 Automatic text scrolling.
923

24+
🔖 Text coloring and formatting.
1025

11-
### Quick start :
12-
* `pip install git+git://github.com/Tim-ats-d/Visual-dialog` (The lib is not yet available on **pypy**).
13-
* Read this [examples](https://github.com/Tim-ats-d/Visual-dialog/blob/main/doc/examples).
26+
⚙️ Hackable and configurable .
1427

28+
## Installation
1529

16-
## Requirements
30+
### Using pip
31+
`pip install git+git://github.com/Tim-ats-d/Visual-dialog`
32+
(The lib is not yet available on **pypy**).
33+
34+
### Requirements
1735
* **Python 3.6** or more.
36+
* [`curses`](https://docs.python.org/3/library/curses.html) module (available on **UNIX** system by default).
1837
* Knowledge of [`curses`](https://docs.python.org/3/library/curses.html) librairie.
38+
39+
## Quick-start
40+
41+
Read these [examples](doc/examples/).
42+
43+
## Documentation
44+
45+
Coming soon !
46+
47+
48+
## Contributing
49+
50+
We would love for you to contribute to improve **Visual-dialog**.
51+
52+
Take a look at our [Contributing guide](CONTRIBUTING) to get started.
53+
54+
## License
55+
56+
Distributed under the **GPL-2.0 License** . See [LICENSE](LICENSE) for more information.
57+
58+
## Acknowledgements
59+
60+
Thanks to all those who contributed to **Visual-dialog** !

doc/examples/confrontation.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,75 +16,78 @@ def main(stdscr):
1616
curses.init_pair(2, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
1717
curses.init_pair(3, curses.COLOR_RED, curses.COLOR_BLACK)
1818

19-
textbox_position = (20, 15) # Position 20;15 in terminal.
19+
textbox_position = (10, 10) # Position 10;10 in terminal.
2020
textbox_dimension = (40, 6) # Length and width (in character).
2121

22-
phoenix_textbox = DialogBox(
22+
phoenix_wright = DialogBox(
2323
*textbox_position,
2424
*textbox_dimension,
2525
title="Phoenix", title_colors_pair_nb=1 # Title and color_pair used to colored title.
2626
)
2727

28-
april_may_textbox = DialogBox(
28+
april_may = DialogBox(
2929
*textbox_position,
3030
*textbox_dimension,
3131
title="April", title_colors_pair_nb=2 # Title and color_pair used to colored title.
3232
)
3333

34-
edgeworth_textbox = DialogBox(
34+
miles_edgeworth = DialogBox(
3535
*textbox_position,
3636
*textbox_dimension,
37-
title="Edgeworth", title_colors_pair_nb=3
37+
title="Edgeworth", title_colors_pair_nb=3 # Title and color_pair used to colored title.
3838
)
3939

4040
# Definition of accepted key codes to pass a dialog.
4141
# See documentation of curses constants for more informations.
42-
phoenix_textbox.confirm_dialog_key = (10, 32) # Key Enter and Space.
43-
april_may_textbox.confirm_dialog_key = (10, 32) # Key Enter and Space.
44-
edgeworth_textbox.confirm_dialog_key = (10, 32) # Key Enter and Space.
42+
phoenix_wright.confirm_dialog_key = (10, 32) # Key Enter and Space.
43+
april_may.confirm_dialog_key = (10, 32) # Key Enter and Space.
44+
miles_edgeworth.confirm_dialog_key = (10, 32) # Key Enter and Space.
4545

46-
phoenix_textbox.char_by_char(stdscr,
46+
phoenix_wright.char_by_char(stdscr,
4747
"This testimony is a pure invention !",
4848
colors_pair_nb=0,
4949
delay=0.03)
5050

51-
phoenix_textbox.getkey(stdscr) # Wait until a key in phoenix_textbox.confirm_dialog_key list is pressed.
51+
phoenix_wright.getkey(stdscr) # Wait until a key contained in phoenix_wright.confirm_dialog_key is pressed.
5252
stdscr.clear() # Clear the screen.
5353

54-
phoenix_textbox.char_by_char(stdscr,
54+
phoenix_wright.char_by_char(stdscr,
5555
"You're lying April May !",
5656
colors_pair_nb=0,
5757
flash_screen=True,
58-
delay=0.03)
58+
delay=0.03,
59+
text_attributes=(curses.A_BOLD,))
5960

60-
phoenix_textbox.getkey(stdscr)
61+
phoenix_wright.getkey(stdscr) # Wait until a key contained in phoenix_wright.confirm_dialog_key is pressed.
6162
stdscr.clear()
6263

63-
april_may_textbox.char_by_char(stdscr,
64+
april_may.char_by_char(stdscr,
6465
"Arghh !",
6566
colors_pair_nb=0,
66-
delay=0.02)
67+
delay=0.02,
68+
text_attributes=(curses.A_ITALIC,))
6769

68-
april_may_textbox.getkey(stdscr) # Wait until a key in april_may_textbox.confirm_dialog_key list is pressed.
70+
april_may.getkey(stdscr) # Wait until a key contained in april_may.confirm_dialog_key is pressed.
6971
stdscr.clear()
7072

71-
edgeworth_textbox.char_by_char(stdscr,
73+
miles_edgeworth.char_by_char(stdscr,
7274
"OBJECTION !",
7375
colors_pair_nb=0,
7476
flash_screen=True,
75-
delay=0.03)
77+
delay=0.03,
78+
text_attributes=(curses.A_BOLD,)
79+
)
7680

77-
edgeworth_textbox.getkey(stdscr) # Wait until a key in edgeworth_textbox.confirm_dialog_key list is pressed.
81+
miles_edgeworth.getkey(stdscr) # Wait until a key contained in miles_edgeworth.confirm_dialog_key is pressed.
7882
stdscr.clear()
7983

80-
edgeworth_textbox.char_by_char(stdscr,
84+
miles_edgeworth.char_by_char(stdscr,
8185
"These accusations are irrelevant !",
8286
colors_pair_nb=0,
8387
delay=0.03)
8488

85-
edgeworth_textbox.getkey(stdscr)
89+
miles_edgeworth.getkey(stdscr)
8690
stdscr.clear()
8791

8892

89-
# Execution of the function.
90-
curses.wrapper(main)
93+
curses.wrapper(main) # Execution of the function.

doc/examples/context.py

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,53 @@
11
#!/usr/bin/env python3
2-
# context.py
2+
# monologue.py
33

44
import curses
55

66
from visualdialog import DialogBox
77

88

99
def main(stdscr):
10-
monologue = (
11-
"I will be the narrator of this story.",
12-
"I will guide you throughout your adventure."
13-
)
14-
1510
# Makes the cursor invisible.
1611
curses.curs_set(0)
1712

1813
# Definition of several colors pairs.
1914
curses.start_color()
20-
curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK)
21-
curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_BLACK)
22-
23-
with DialogBox(
24-
5, 5, # Position 5;5 in terminal.
25-
40, 6, # Length and width (in character).
26-
title="Narrator", title_colors_pair_nb=1) as narrator: # We catch the dialog box with as.
27-
28-
# Definition of accepted key codes to pass a dialog.
29-
# See documentation of the curses constants for more informations.
30-
narrator.confirm_dialog_key = (10, 32) # Key Enter and Space.
31-
32-
# We iterate on each sentence contained in monologue.
33-
for text in monologue:
34-
narrator.char_by_char(stdscr,
35-
text,
36-
2) # Display of the reply variable colored with color pair 2.
37-
38-
narrator.getkey(stdscr) # Waiting for a key press.
39-
stdscr.clear() # Clear the screen.
40-
41-
42-
# Execution of the function.
43-
curses.wrapper(main)
15+
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
16+
curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK)
17+
18+
textbox = DialogBox(
19+
0, 0, # Position 0;0 in terminal.
20+
40, 6, # Length and width (in character).
21+
title="Tim-ats-d",
22+
title_colors_pair_nb=1, # Title and color_pair used to colored title.
23+
title_text_attributes=(curses.A_UNDERLINE, )) # Attribute to underline the title.
24+
# It is necessary to think of passing a tuple even if it contains only one element
25+
# (see doc for more informations).
26+
27+
# Definition of accepted key codes to pass a dialog.
28+
# See documentation of the curses constants for more informations.
29+
textbox.confirm_dialog_key = (10, 32) # Key Enter and Space.
30+
31+
sentences = {
32+
"An important text.": (curses.A_BOLD, ),
33+
"An action performed by a character.": (curses.A_ITALIC, ),
34+
"An underlined text.": (curses.A_UNDERLINE, ),
35+
"A very important text.": (curses.A_BOLD, curses.A_ITALIC),
36+
"Incomprehensible gibberish ": (curses.A_ALTCHARSET, ),
37+
"The colors of the front and the background reversed.":
38+
(curses.A_REVERSE, ),
39+
}
40+
41+
for text, attributs in sentences.items():
42+
textbox.char_by_char(
43+
stdscr,
44+
text,
45+
2, # Display of the reply variable colored with color pair 2.
46+
text_attributes=attributs) # Pass the attributes to the text.
47+
48+
# Wait until a key contained in textbox.confirm_dialog_key is pressed.
49+
textbox.getkey(stdscr)
50+
stdscr.clear() # Clear the screen.
51+
52+
53+
curses.wrapper(main) # Execution of the function.

doc/examples/text_attributes.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python3
2+
# monologue.py
3+
4+
import curses
5+
6+
from visualdialog import DialogBox
7+
8+
9+
def main(stdscr):
10+
# Makes the cursor invisible.
11+
curses.curs_set(0)
12+
13+
# Definition of several colors pairs.
14+
curses.start_color()
15+
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
16+
curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK)
17+
18+
textbox = DialogBox(
19+
0, 0, # Position 0;0 in terminal.
20+
40, 6, # Length and width (in character).
21+
title="Tim-ats-d",
22+
title_colors_pair_nb=1, # Title and color_pair used to colored title.
23+
title_text_attributes=(curses.A_UNDERLINE, )) # Attribute to underline the title.
24+
# It is necessary to think of passing a tuple even if it contains only one element
25+
# (see doc for more informations).
26+
27+
# Definition of accepted key codes to pass a dialog.
28+
# See documentation of the curses constants for more informations.
29+
textbox.confirm_dialog_key = (10, 32) # Key Enter and Space.
30+
31+
sentences = {
32+
"An important text.": (curses.A_BOLD, ),
33+
"An action performed by a character.": (curses.A_ITALIC, ),
34+
"An underlined text.": (curses.A_UNDERLINE, ),
35+
"A very important text.": (curses.A_BOLD, curses.A_ITALIC),
36+
"Incomprehensible gibberish ": (curses.A_ALTCHARSET, ),
37+
"The colors of the front and the background reversed.":
38+
(curses.A_REVERSE, ),
39+
}
40+
41+
for text, attributs in sentences.items():
42+
textbox.char_by_char(
43+
stdscr,
44+
text,
45+
2, # Display of the reply variable colored with color pair 2.
46+
text_attributes=attributs) # Pass the attributes to the text.
47+
48+
# Wait until a key contained in textbox.confirm_dialog_key is pressed.
49+
textbox.getkey(stdscr)
50+
stdscr.clear() # Clear the screen.
51+
52+
53+
curses.wrapper(main) # Execution of the function.

setup.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,21 @@
22

33
from setuptools import setup, find_packages
44

5-
65
setup(
76
name="visualdialog",
8-
version=0.4,
7+
version=0.6,
98
packages=find_packages(),
109
author="Arnouts Timéo",
1110
author_email="[email protected]",
12-
description="A librairie to make easier dialog box in terminal.",
11+
description="A library to make easier dialog box in terminal.",
1312
long_description=open("README.md").read(),
1413
include_package_data=True,
1514
url="https://github.com/Tim-ats-d/Visual-dialog",
1615
classifiers=[
17-
"Development Status :: 3 - Alpha",
18-
"Environment :: Console :: Curses",
16+
"Development Status :: 3 - Alpha", "Environment :: Console :: Curses",
1917
"Intended Audience :: Developers",
2018
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
21-
"Natural Language :: English",
22-
"Natural Language :: French",
19+
"Natural Language :: English", "Natural Language :: French",
2320
"Operating System :: POSIX :: Linux",
2421
"Programming Language :: Python :: 3.0",
2522
"Programming Language :: Python :: 3.1",
@@ -34,5 +31,5 @@
3431
"Programming Language :: Python :: 3.9",
3532
"Programming Language :: Python :: Implementation",
3633
"Topic :: Games/Entertainment :: Role-Playing",
37-
"Topic :: Software Development :: Libraries :: Python Modules"]
38-
)
34+
"Topic :: Software Development :: Libraries :: Python Modules"
35+
])

0 commit comments

Comments
 (0)