TERMINALFUNC, a python library with every terminal manuplation function you will ever need (probably)!
- func
stopSleep()
: stop idle sleep while current process exists. Only works on OSX - func
getPosition()
: get current cursor position. Position is returned in{"row":row, "column":column}
Note: it will clear stdin - func
getTerminalSize()
: get current terminal size. Size is returned in{"columns":columns,"rows":lines}
- func
print(string,newline=False,stdout=True,flush=True,moveCursor=True,crIfRaw=True)
: function to printstring
.- kwarg If
newline
is not changed toTrue
,string
will be printed without newlines after it. - kwarg If
stdout
is not changed toFalse
, it will usesys.stdout.write()
to outputstring
- kwarg If
flush
is not changed toFalse
, it will dosys.stdout.flush()
after outputtingstring
withsys.stdout.write()
- kwarg If
moveCursor
is changed toFalse
, it will move cursor back to it's original position after outputtingstring
. - kwarg If
crIfRaw
is not changed toTrue
, it will use\n\r
asnewline
when inraw
mode
- kwarg If
- func
checkStdinForData()
: checks stdin for data. If there is data, it returnsTrue
,False
otherwise - func
getLastChar(block=False,includeNewline=True)
: gets the last character in stdin.- kwarg If block is not changed to
True
, it will returnNone
if there is no data in stdin. If it is changed toTrue
, it will wait for data. - kwarg If
includeNewline
is changed toFalse
, it will returnNone
when it finds a newline, useful when getting stdin data fromcooked
mode, which needs an extra\n
to push data to stdin.
- kwarg If block is not changed to
- func
echoKeys(enable=False,disable=False)
: change whether to echo key presses to stdout- kwarg If
enable
is changed toTrue
, echoing keys will be enabled. - kwarg If
disable
is changed toTrue
, echoing keys will be disabled. - kwarg If nothing is changed, it will return if echoing keys is enabled.
- kwarg If
- func
clear(screen=False,scrollback=False,line=False,fromCursor=False,toEnd=False,toStart=False)
: clear certain parts of the screen.- kwarg If
fromCursor
is changed toTrue
:- kwarg If
toEnd
is changed toTrue
:- kwarg If
line
is changed toTrue
, it will clear from the cursor to the end of the line - kwarg If
screen
is changed toTrue
, it will clear from the cursor to the end of the screen.
- kwarg If
- kwarg If
toStart
is changed toTrue
:- kwarg If
line
is changed toTrue
, it will clear from the cursor to the end of the line - kwarg If
screen
is changed toTrue
, it will clear from the cursor to the end of the screen.
- kwarg If
- kwarg If
- Else:
- kwarg If
screen
is changed toTrue
, it will clear the screen - kwarg If
scrollback
is changed toTrue
, it will clear the scrollback - kwarg If
line
is changed toTrue
, it will clear the line that the cursor is currently on
- kwarg If
- kwarg If
- func
clearer(screen=False,scrollback=False,line=False,fromCursor=False,toEnd=False,toStart=False)
: its the same asclear()
but it returns a string that will have the same effect when printed - obj
CursorSaver()
: a object with cursor-saving and loading utils it usesgetPosition()
, causing it to clear stdin- func
self.save(id)
: save cursor withid
as the id.id
must be hashable - func
self.get(id)
: get the position withid
. Returns with the same format asgetPosition()
- func
self.load(id)
: go to the position inid
- func
- func
raw(enable=False,disable=False)
: set raw mode.- kwarg If
enable
is changed toTrue
, it will enable raw mode - kwarg If
disable
is changed toTrue
, it will disable raw mode - kwarg If nothing is changed, it will return whether raw mode is activated
- kwarg If
- func
cursorVisibility(hide=False,show=False)
: set raw mode.- kwarg If
show
is changed toTrue
, it will show the cursor - kwarg If
hide
is changed toTrue
, it will hide the cursor - kwarg If nothing is changed, it will return whether cursor is visible
- kwarg If
- func
bell()
: makes the terminal ring - func
backspace()
: prints a backspace - func
fillWithSpaces(saveCursor=True)
: fill the screen with spaces, pushing everything above into scrollback and allowing the cursor to move everywhere- kwarg if
saveCursor
isFalse
, it will not get the cursor position and therefore not clear stdin
- kwarg if
- func
fillRowWithSpaces()
: fill the current row with spaces - func
changeStyle(background=False,foreground=False,color8=False,color256=False,reset=False,bold=False,dim=False,italic=False,underline=False,blink=False,invert=False,invisible=False,strikethrough=False)
: change the current text style/color- kwarg If
reset
is changed to True, all text printed after changing style will be reset - kwarg If
bold
is changed to True, all text printed after changing style will be bold - kwarg If
dim
is changed to True, all text printed after changing style will be dim - kwarg If
italic
is changed to True, all text printed after changing style will be italic - kwarg If
underline
is changed to True, all text printed after changing style will be underline - kwarg If
blink
is changed to True, all text printed after changing style will be blink - kwarg If
invert
is changed to True, all text printed after changing style will be inverted - kwarg If
invisible
is changed to True, all text printed after changing style will be invisible - kwarg If
strikethrough
is changed to True, all text printed after changing style will be strikethrough'd - kwarg If
background
is changed to True:- kwarg If
color8
is notFalse
, and is one of these:black
red
green
yellow
blue
magenta
cyan
white
, it will make the background of all text printed after changing stylecolor8
colored
- kwarg If
color256
is notFalse
and is aint
from0
to256
, it will make the background of all text printed after changing stylecolor256
colored
- kwarg If
- kwarg If
foreground
is changed to True:- kwarg If
color8
is notFalse
, and is one of these:blue
black
red
green
yellow
magenta
cyan
white
, it will make the foreground of all text printed after changing stylecolor8
colored - kwarg If
color256
is notFalse
and is aint
from0
to256
, it will make the foreground of all text printed after changing stylecolor256
colored
- kwarg If
- kwarg If
- func
style(background=False,foreground=False,color8=False,color256=False,reset=False,bold=False,dim=False,italic=False,underline=False,blink=False,invert=False,invisible=False,strikethrough=False)
: its the same aschangeStyle()
but it returns a string that will have the same effect when printed - func
moveCursor(to=False,column=False,up=False,down=False,left=False,right=False,home=False)
: move the cursor- kwarg If
to
is notFalse
, it will move the cursor to columnto["column"]
and rowto["row"]
- kwarg If
column
is notFalse
, it will move the cursor to columncolumn
- kwarg If
up
is notFalse
, it will move the cursor upup
spaces - kwarg If
down
is notFalse
, it will move the cursor downdown
spaces - kwarg If
left
is notFalse
, it will move the cursor leftleft
spaces - kwarg If
right
is notFalse
, it will move the cursor rightright
spaces
- kwarg If
- func
cursor(to=False,column=False,up=False,down=False,left=False,right=False,home=False)
: its the same asmoveCursor()
but it returns a string that will have the same effect when printed - obj
KeyLogger()
: logs keys
it adds logged keys toself.keys
list in the format of {time.time()
output:key}
it is accurate to about 1/100th of a second- func
self.keyHandler()
: logs keys - func
self.start()
: startskeyHandler()
in another thread - func
self.halt(wait=True)
stops the keyHandler in the other thread (if it is running, or it errors)- kwarg If
wait
isTrue
, it will wait untill the other thread is stopped before continuing
- kwarg If
- bool
self.stop
: cause the keyHandler to end if it is set toTrue
- func
- obj
KeyHandler(functions)
: calls a function when a key is pressed
functions are passed in the following format:
{key1:[func1,(arg1,arg2)],key2:[func2,(arg1,arg2)],...,"default":defaultFunc}
thedefault
func is not needed but is called when there isnt a mapping for the key already in the dictionary
the key is passed to thedefault
function- func
self.keyHandler()
: handles keys - func
self.start()
: startskeyHandler()
in another thread - func
self.halt(wait=True)
stops the keyHandler in the other thread (if it is running, or it errors)- kwarg If
wait
isTrue
, it will wait untill the other thread is stopped before continuing
- kwarg If
- bool
self.stop
: cause the keyHandler to end if it is set toTrue
- dict
self.actions
: the key-to-function mappings, from the time of initiation. You can change this directly.
- func
- obj
FramerateLimiter(fps)
: limits framerate accurately- arg
fps
is the fps to limit at - func
startFrame()
: start a frame - func
endFrame()
: end a frame, making a frame - func
delayTillNextFrame()
: delays till the end of the previous frame - int
frameTime
: time taken for the previous frame, in ns
- arg
- obj
FramerateTracker()
: tracks framerate accurately- func
startFrame()
: start a frame - func
endFrame()
: end a frame, making a frame - func
calculateAverageFPS()
: calculate the average FPS - func
calculateCurrentFPS()
: calculate the fps based on the previous frame - func
calculateAverageFrameTime()
: get the average time taken to make a frame, in seconds - func
calculateCurrentFrameTime()
: calculate the time that the previous frame took, in seconds - func
resetFrameMeasurements()
: reset the frame time measurements - int
frames
: the number of frames that have been captured - int
frameTime
: the amount of time taken for the last frame in ns - list<int>
frameTimes
: the amount of time taken by all the frames, in ns
- func
- install ESCAPES
- install FUNC
- Run this:
PYPATH=$(python3 -c "import os;print(os.__file__.replace('os.py',''))")
curl https://raw.githubusercontent.com/lomnom/TERMINALFUNC/main/TERMINALFUNC.py > "$PYPATH"TERMINALFUNC.py
- uninstall ESCAPES
- uninstall FUNC
- Run this:
PYPATH=$(python3 -c "import os;print(os.__file__.replace('os.py',''))")
rm "$PYPATH"TERMINALFUNC.py
Example: https://github.com/lomnom/PI