Package: ansi-escapes
ansi-escapesANSI escape codesfor manipulating the terminalA port of the Node.js packageansi-escapesto Python.Installpython3 -m pip install -U ansi-escapesUsagefromansi_escapesimportansiEscapesimportsys# Moves the cursor two rows up and to the leftsys.stdout.write(ansiEscapes.cursorUp(2)+ansiEscapes.cursorLeft)#>>> '\u001B[2A\u001B[1000D'APIcursorTo(x, y?)Set the absolute position of the cursor.x0y0is the top left of the screen.cursorMove(x, y?)Set the position of the cursor relative to its current position.cursorUp(count)Move cursor up a specific amount of rows. Default is1.cursorDown(count)Move cursor down a specific amount of rows. Default is1.cursorForward(count)Move cursor forward a specific amount of columns. Default is1.cursorBackward(count)Move cursor backward a specific amount of columns. Default is1.cursorLeftMove cursor to the left side.cursorSavePositionSave cursor position.cursorRestorePositionRestore saved cursor position.cursorGetPositionGet cursor position.cursorNextLineMove cursor to the next line.cursorPrevLineMove cursor to the previous line.cursorHideHide cursor.cursorShowShow cursor.eraseLines(count)Erase from the current cursor position up the specified amount of rows.eraseEndLineErase from the current cursor position to the end of the current line.eraseStartLineErase from the current cursor position to the start of the current line.eraseLineErase the entire current line.eraseDownErase the screen from the current line down to the bottom of the screen.eraseUpErase the screen from the current line up to the top of the screen.eraseScreenErase the screen and move the cursor the top left position.scrollUpScroll display up one line.scrollDownScroll display down one line.clearScreenClear the terminal screen. (Viewport)clearTerminalClear the whole terminal, including scrollback buffer. (Not just the visible part of it)beepOutput a beeping sound.link(text, url)Create a clickable link.Supported terminals.Usesupports-hyperlinksto detect link support.image(filePath, options?)(Not yet implemented.)Display an image.Currently only supported on iTerm2 >=3Seeterm-imgfor a higher-level module.inputType:BufferBuffer of an image. Usually read in withfs.readFile().optionsType:objectwidthheightType:string | numberThe width and height are given as a number followed by a unit, or the word "auto".N: N character cells.Npx: N pixels.N%: N percent of the session's width or height.auto: The image's inherent size will be used to determine an appropriate dimension.preserveAspectRatioType:booleanDefault:trueiTerm.setCwd(path?)Type:stringDefault:process.cwd()Inform iTerm2of the current directory to help semantic history and enableCmd-clicking relative paths.iTerm.annotation(message, **options)Creates an escape code to display an "annotation" in iTerm2.An annotation looks like this when shown:See theiTerm Proprietary Escape Codes documentationfor more information.messageType:stringThe message to display within the annotation.The|character is disallowed and will be stripped.optionsType:objectlengthType:numberDefault: The remainder of the lineNonzero number of columns to annotate.xType:numberDefault: Cursor positionStarting X coordinate.Must be used withyandlength.yType:numberDefault: Cursor positionStarting Y coordinate.Must be used withxandlength.isHiddenType:booleanDefault:falseCreate a "hidden" annotation.Annotations created this way can be shown using the "Show Annotations" iTerm command.Relatedansi-styles- ANSI escape codes for styling strings in the terminalLicenseMITContactA library byShawn Presser. If you found it useful, please considerjoining my patreon!My Twitter DMs are always open; you shouldsend me one! It's the best way to reach me, and I'm always happy to hear from you.Twitter:@theshawwnPatreon:https://www.patreon.com/shawwnHN:sillysaurusxWebsite:shawwn.com