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
newlineis not changed toTrue,stringwill be printed without newlines after it. - kwarg If
stdoutis not changed toFalse, it will usesys.stdout.write()to outputstring - kwarg If
flushis not changed toFalse, it will dosys.stdout.flush()after outputtingstringwithsys.stdout.write() - kwarg If
moveCursoris changed toFalse, it will move cursor back to it's original position after outputtingstring. - kwarg If
crIfRawis not changed toTrue, it will use\n\rasnewlinewhen inrawmode
- kwarg If
- func
checkStdinForData(): checks stdin for data. If there is data, it returnsTrue,Falseotherwise - func
getLastChar(block=False,includeNewline=True): gets the last character in stdin.- kwarg If block is not changed to
True, it will returnNoneif there is no data in stdin. If it is changed toTrue, it will wait for data. - kwarg If
includeNewlineis changed toFalse, it will returnNonewhen it finds a newline, useful when getting stdin data fromcookedmode, which needs an extra\nto 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
enableis changed toTrue, echoing keys will be enabled. - kwarg If
disableis 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
fromCursoris changed toTrue:- kwarg If
toEndis changed toTrue:- kwarg If
lineis changed toTrue, it will clear from the cursor to the end of the line - kwarg If
screenis changed toTrue, it will clear from the cursor to the end of the screen.
- kwarg If
- kwarg If
toStartis changed toTrue:- kwarg If
lineis changed toTrue, it will clear from the cursor to the end of the line - kwarg If
screenis changed toTrue, it will clear from the cursor to the end of the screen.
- kwarg If
- kwarg If
- Else:
- kwarg If
screenis changed toTrue, it will clear the screen - kwarg If
scrollbackis changed toTrue, it will clear the scrollback - kwarg If
lineis 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 withidas the id.idmust 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
enableis changed toTrue, it will enable raw mode - kwarg If
disableis 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
showis changed toTrue, it will show the cursor - kwarg If
hideis 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
saveCursorisFalse, 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
resetis changed to True, all text printed after changing style will be reset - kwarg If
boldis changed to True, all text printed after changing style will be bold - kwarg If
dimis changed to True, all text printed after changing style will be dim - kwarg If
italicis changed to True, all text printed after changing style will be italic - kwarg If
underlineis changed to True, all text printed after changing style will be underline - kwarg If
blinkis changed to True, all text printed after changing style will be blink - kwarg If
invertis changed to True, all text printed after changing style will be inverted - kwarg If
invisibleis changed to True, all text printed after changing style will be invisible - kwarg If
strikethroughis changed to True, all text printed after changing style will be strikethrough'd - kwarg If
backgroundis changed to True:- kwarg If
color8is notFalse, and is one of these:blackredgreenyellowbluemagentacyanwhite, it will make the background of all text printed after changing stylecolor8colored
- kwarg If
color256is notFalseand is aintfrom0to256, it will make the background of all text printed after changing stylecolor256colored
- kwarg If
- kwarg If
foregroundis changed to True:- kwarg If
color8is notFalse, and is one of these:blueblackredgreenyellowmagentacyanwhite, it will make the foreground of all text printed after changing stylecolor8colored - kwarg If
color256is notFalseand is aintfrom0to256, it will make the foreground of all text printed after changing stylecolor256colored
- 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
tois notFalse, it will move the cursor to columnto["column"]and rowto["row"] - kwarg If
columnis notFalse, it will move the cursor to columncolumn - kwarg If
upis notFalse, it will move the cursor upupspaces - kwarg If
downis notFalse, it will move the cursor downdownspaces - kwarg If
leftis notFalse, it will move the cursor leftleftspaces - kwarg If
rightis notFalse, it will move the cursor rightrightspaces
- 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.keyslist 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
waitisTrue, 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}thedefaultfunc is not needed but is called when there isnt a mapping for the key already in the dictionary
the key is passed to thedefaultfunction- 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
waitisTrue, 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
fpsis 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