Skip to content

Pyfancy v3 develop #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions pyfancy/demo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pyfancy import pyfancy

pyfancy().clear()
pyfancy().red("Hello").raw(", ").blue("world!").output()
pyfancy().multi("Multicolored text").output()
pyfancy().rainbow("Rainbow text").output()
Expand All @@ -14,4 +15,5 @@
pyfancy().black().gray_bg("Gray background").output()
pyfancy().read("pyfancy/demo/import.txt").output()
pyfancy().red("This should not be seen!").reset().output()
pyfancy().blue("this").next().red("and").next(3).green("that")
print(pyfancy().red("Hello").raw(", ").blue("world!").strip())
39 changes: 18 additions & 21 deletions pyfancy/pyfancy.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
# Provides methods for manipulating text styling in specific terminals.
# Uses a basic chaining method where text properties are added by calling
# methods with related names.
# Pyfancy 3.dev
#
# For example, to print "Hello, world!" in red:
# print pyfancy().red("Hello, world!").get()
# Pyfancy 3 will allow not only focus on terminal color styling
# but become the one stop shop for terminal interactions.
#
# Styles can be changed for different text components. Example:
# print pyfancy().red("Hello").raw(", ").blue("world!").get()
#
# No output text is necessary when calling a styling method. This allows
# styles to be stacked:
# print pyfancy().red().bold("Hello, world!").get()
#
# There are two provided ways to access the modified text. The first is
# direct access to the string object called "out". However, accessing this
# object will not reset the style, so any text outputted after will have
# the same style as whatever the text was at the end of the chain.
#
# The get() method is better for accessing text because it resets the text
# style so no new text will have unwanted styling.
# Join the discussion: https://github.com/ilovecode1/Pyfancy-2/issues/51

import os

class pyfancy:

Expand Down Expand Up @@ -96,6 +82,18 @@ def read(self, file):
self.parse(f.read())
f.close()
return self

def next(self, times=1):
self.out += ('\n' * times)
return self

def clear(self):
if os.name == "posix":
os.system('clear')
elif os.name in ("nt", "dos", "ce"):
os.system('CLS')
else:
print('\n' * 100)

def reset(self):
self.out = ''
Expand Down Expand Up @@ -191,7 +189,7 @@ def multi(self, string):
i = 31 # ID of escape code; starts at 31 (red) and goes to 36 (cyan)
for c in string: # Iterate through string
self.out += '\033[' + str(i) + 'm' + c
i += 1 # Why u no have ++i? >:(
i += 1
if(i > 36):
i = 31
return self
Expand All @@ -200,7 +198,6 @@ def multi(self, string):
# and formatting code
# This shouldn't be exported


def _add(name, number):
def inner(self, addition=''):
self.out += '\033[%dm%s' % (number, addition)
Expand Down