Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
A module to create a frame when printing a list of strings, with control on the alignment of the text and frame. In addition can be configured to act as 'input()'.
is an updated version of borders: it enhances the functionality of creating frames around text output adding new features, and improving existing ones. Borders creates a frame around a string or a list of strings where any item is considered a new line.
frame()
function in place of input()
to create a framed prompt for user input.Borders relies on the Python standard library, textlinebreaker and polychromy libraries, and if your system is Windows
in addition it might requirecolorama
to fix color compatibility.
pip install borders
pip install --upgrade borders
from borders import frame
Add the following line in your code to import the module
from borders import frame
Simply use the function frame()
instead of print()
to print a frame around your output.
Alternatively set the parameter window = "input"
to use frame()
in place of input()
.
The text to be printed can be a mixed list of:
37
.0
.37
.0
.'single'
, 'double'
, 'double horizontal'
, 'double vertical'
, 'dots'
, None
'double'
'left'
, 'centre'
, 'center'
, 'right'
'left'
'left'
, 'centre'
, 'center'
, 'right'
'left'
0 to 3
1
8
, 'max'
(this value assign to the frame the width of the terminal)42
8
, 'max'
(this value assign to the frame the width of the terminal)70
'print'
, 'input'
'print'
Here are some examples of how to use the frame() function with different parameters.
Simply using frame()
will print a frame around a given output.
from borders import frame
# Example 1: Default settings
output = ["Hello,", "World!"]
frame(output)
We can set a colour for the text (e.g. 34 for Blue) and one for the frame (e.g. 31 for Red)
from borders import frame
# Example 2: Setting text and frame colours
output = ["Hello,", "World!"]
frame(output, colour="34", frame_colour="31")
Using a tuple we can set different colours for each line, let's try setting blue, and red as general colours for the text and the frame.
Then let's set one line with yellow text, one with green, and highlight one in white.
from borders import frame
# Example 3: Using tuple to set different colours for each line
output = [
"This text's color is Blue (System Color)",
("This text's color is Aquamarine", "Aquamarine"),
("This text's color is Coral","255;127;80"),
("This text's color is Cosmic Latte","#FFF8E7"),
("This text is highlighted in Yellow", "", "x226"),
("Frame's color is Red (System Color)", 31),
"This text's color is back to Blue (System Color)"
]
frame(output, colour=34, frame_colour=31)
from borders import frame
# Example 4: Setting a different styles for the frame
styles = ["single", "double", "double horizontal", "double vertical", "dots", None]
for s in styles:
# Print out the name of the style in a frame of that style.
frame(f"{s}", frame_colour="Red", frame_background="Gainsboro", alignment="centre", frame_style=s)
The parameteralignment
allows you to change the alignment of the text inside the frame.
Withalignment="right"
will allign the text to the right of the frame.
from borders import frame
# Example 5: Setting lines width equal to 60,
# the general alignment of the text to the right,
# and the alignment of the second line to the left
output = ["There are only 10 kinds of people in this world:", ("Those who know binary and Those who don't.","left"), "Anonymous"]
frame(output, min_width=60, alignment="right")
The parameterdisplay
allows you to change the position of the frame inside the terminal.
from borders import frame
# Example 6: Setting the position of the frame in the centre of the terminal
# and the alignment of the text to the right
output = ["There are only 10 kinds of people in this world:", "Those who know binary and Those who don't.", "Anonymous"]
frame(output, alignment="right", display="centre")
Specifying different values for the parameterspacing
, you can increase or decrease the space between text and frame.
Withspacing=2
it will leave 2 blank lines at the top and the bottom, and 8 blank spaces before and after the text.
from borders import frame
# Example 7: Setting the spacing between the text and the frame equal to 2
output = ["Hello,", "World!"]
frame(output, spacing=2)
Withspacing=0
it will create the frame around the text with no spaces.
from borders import frame
# Example 8: Setting the spacing between the text and the frame equal to 0
output = ["Hello,", "World!"]
frame(output, spacing=0)
The parameter min_width
set the minimum width inside the frame.
Withmin_width=30
the output frame will have a wider space on the left.
from borders import frame
# Example 9:
output = ["Hello,", "World!"]
frame(output, min_width=30)
The parameter max_width
set the max length of text on a line.
Let's see what happens to the following string: "There are only 10 kinds of people in this world: Those who know binary and Those who don’t."
from borders import frame
# Example 10:
output = ["There are only 10 kinds of people in this world: Those who know binary and Those who don't."]
frame(output, max_width=100)
from borders import frame
# Example 11:
output = ["There are only 10 kinds of people in this world: Those who know binary and Those who don't."]
frame(output, max_width=50)
from borders import frame
# Example 12:
output = ["There are only 10 kinds of people in this world: Those who know binary and Those who don't."]
frame(output, max_width=25)
You can use the function frame()
in place of input()
to create a frame around the prompt and get the input from the user.
from borders import frame
# Example 13: Using frame() in place of input()
num1 = int(frame(["Please,", "enter a number"], window="input"))
num2 = num1 * 2
output = [f"The double of {num1}",f"is {num2}"]
frame(output)
If you'd like to contribute to this project, please follow these steps:
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
A module to create a frame when printing a list of strings, with control on the alignment of the text and frame. In addition can be configured to act as 'input()'.
We found that borders demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.