ansi-escape

Remove all ANSI colors/styles from strings

◇◆丶佛笑我妖孽 提交于 2019-11-30 08:27:48
I use a library that adds ANSI colors / styles to strings. For example: > "Hello World".rgb(255, 255, 255) '\u001b[38;5;231mHello World\u001b[0m' > "Hello World".rgb(255, 255, 255).bold() '\u001b[1m\u001b[38;5;231mHello World\u001b[0m\u001b[22m' When I do: console.log('\u001b[1m\u001b[38;5;231mHello World\u001b[0m\u001b[22m') a "Hello World" white and bold message will be output. Having a string like '\u001b[1m\u001b[38;5;231mHello World\u001b[0m\u001b[22m' how can these elements be removed? foo('\u001b[1m\u001b[38;5;231mHello World\u001b[0m\u001b[22m') //=> "Hello World" Maybe a good regular

Is it possible to display text in a console with a strike-through effect?

心已入冬 提交于 2019-11-30 02:44:42
问题 I have already looked into ANSI escape codes, but it looks like only underlining is supported. Do I miss something or is there another option? If it is not possible, is there something equivalent in the meaning of "this is deprecated"? 回答1: According to the ECMA-48 standard for terminals, SGR (Select Graphic Rendition) code number 9 is supposed to enable crossed-out text. However, the ANSI escape code wikipedia page says that it's not widely supported, and I'm not aware of any that do. I'd

How to print a string literally in Python

大城市里の小女人 提交于 2019-11-30 01:17:42
问题 this is probably really simple but I can't find it. I need to print what a string in Python contains. I'm collecting data from a serial port and I need to know if it is sending CR or CRLF + other control codes that are not ascii. As an example say I had s = "ttaassdd\n\rssleeroo" then I would like to do is: print s Where it would show the \n\r rather than covert them into escape characters. 回答1: Try with: print repr(s) >>> 'ttaassdd\n\rssleeroo' 回答2: Saving your string as 'raw' string could

tmux man-page search highlighting

狂风中的少年 提交于 2019-11-29 22:57:36
When I search in, for example, man ls while in a tmux session, the search strings don't appear highlighted - the page jumps down so that the search string is on the top line of the buffer, as expected, but it's not highlighted. Doing the same thing in the same shell while not in a tmux session results in highlighted search strings. I have no idea where to start looking to solve this. Any hints are appreciated. Based on Less Colors For Man Pages by Gen2ly , here is my man page and how to do it: Preview This is a shell, not a web page ! How to (optional) I'm using Tomorrow theme for Konsole

ANSI Color Specific RGB Sequence Bash

丶灬走出姿态 提交于 2019-11-29 19:53:22
I know that in bash terminals a reliable way to change color is using ANSI escape sequences. For example: echo -e "\033[0;31mbrown text\033[0;00m" should output brown text (in brown) Is there a way to output color using a specific RGB set with ANSI? Say I want bright red: echo -e "**\033[255:0:0m**red text\033[0;00m" Does this sort of thing exist? I just want to use standard bash. Both answers here fail to mention the Truecolor ANSI support for 8bpc color. This will get the RGB color the OP originally asked for. Instead of ;5 , use ;2 , and specify the R , G , and B values (0-255) in the

Save and restore terminal content

风格不统一 提交于 2019-11-29 13:35:17
I am writing automation scripts ( perl / bash ). Many of them benefit from some basic terminal GUI. I figured I'd use standard ANSI sequences for basic drawing. Before drawing in terminal I do clear but doing that I lose some terminal command history. I want to be able to restore terminal command history when my program exists. Many terminal programs (e.g. less , man , vim , htop , nmon , whiptail , dialog etc) do exactly that. All of them restore terminal window bringing the user back to where he was prior to calling the program with all the history of commands previously executed. To be

How do i print escape characters as characters?

血红的双手。 提交于 2019-11-29 12:36:44
I'm trying to print escape characters as characters or strings using this code: while((c = fgetc(fp))!= EOF) { if(c == '\0') { printf(" \0"); } else if(c == '\a') { printf(" \a"); } else if(c == '\b') { printf(" \b"); } else if(c == '\f') { printf(" \f"); } else if(c == '\n') { printf(" \n"); } else if(c == '\r') { printf(" \r"); } else if(c == '\t') { printf(" \t"); } else if(c == '\v') { printf(" \v"); } } but when i try it, it actually prints the escape sequence. Escape the slashes (use " \\a" ) so they won't get interpreted specially. Also you might want to use a lookup table or a switch

Clear command prompt with C on windows

匆匆过客 提交于 2019-11-29 11:46:53
Is it possible to clear the output at the command prompt using C on windows? For example, on linux I could do printf("\033[2J"); But as far as I know windows doesn't recognise the ANSI escape codes Thanks. EDIT: I guess I'll also need to get the cursor back to 0,0 fo r the next output after the clear... There are many way to do that on windows. You include conio.h and call _clrscr(); Or you can call system("cls"); Just as an alternative to the conio.h or the system call, just an implementation (i suposse that similar to the conio library) of how it is supossed to be done in windows. #include

Reading the Device Status Report ANSI escape sequence reply

被刻印的时光 ゝ 提交于 2019-11-29 10:05:55
I'm trying to retrieve the coordinates of cursor in a VT100 terminal using the following code: void getCursor(int* x, int* y) { printf("\033[6n"); scanf("\033[%d;%dR", x, y); } I'm using the following ANSI escape sequence: Device Status Report - ESC[6n Reports the cursor position to the application as (as though typed at the keyboard) ESC[n;mR, where n is the row and m is the column. The code compiles and the ANSI sequence is sent, but, upon receiving it, the terminal prints the ^[[x;yR string to the stdout instead of stdin making it imposible for me to retrieve it from the program: Clearly,

Remove all ANSI colors/styles from strings

旧时模样 提交于 2019-11-29 06:00:50
问题 I use a library that adds ANSI colors / styles to strings. For example: > "Hello World".rgb(255, 255, 255) '\u001b[38;5;231mHello World\u001b[0m' > "Hello World".rgb(255, 255, 255).bold() '\u001b[1m\u001b[38;5;231mHello World\u001b[0m\u001b[22m' When I do: console.log('\u001b[1m\u001b[38;5;231mHello World\u001b[0m\u001b[22m') a "Hello World" white and bold message will be output. Having a string like '\u001b[1m\u001b[38;5;231mHello World\u001b[0m\u001b[22m' how can these elements be removed?