ansi-escape

ANSI Color Specific RGB Sequence Bash

早过忘川 提交于 2019-11-28 15:39:34
问题 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. 回答1: Both answers here fail to mention the Truecolor ANSI support for 8bpc color. This will get the RGB color the

Save and restore terminal content

随声附和 提交于 2019-11-28 07:46:44
问题 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

How do i print escape characters as characters?

前提是你 提交于 2019-11-28 06:27:21
问题 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. 回答1: Escape the slashes

Clear command prompt with C on windows

旧街凉风 提交于 2019-11-28 05:45:02
问题 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... 回答1: There are many way to do that on windows. You include conio.h and call _clrscr(); Or you can call system("cls"); 回答2: Just as an alternative to the conio.h or the system call, just an

How to use ANSI escape codes inside mvwprintw in ncurses?

痞子三分冷 提交于 2019-11-28 01:25:27
Is there a way to use ANSI escape codes inside mvwprintw ? mvwprintw(window, 0, 0,"%c[%dmCOLORED_TEXT!\n", 0x1B, 32);//doesn't work even though: printf("%c[%dmCOLORED_TEXT\n", 0x1B, 32); //works This would be for cases where using wattron / wattroff is not convenient; for example, when redirecting output from stdout of a process that outputs such escape codes. No. The only way to make that work would be to parse the string yourself, turning escape codes back into the appropriate curses commands, to issue along with your output. One thing you should realize is that those codes, although widely

Python module to enable ANSI colors for stdout on Windows?

折月煮酒 提交于 2019-11-27 22:14:33
I am looking for a Python module that would add ANSI support under Windows. This means that after importing the module, if you output ANSI escaped strings, they will appear accordingly. There are two python modules that are able to do this colorama and tendo.ansiterm module, which was originally written for waf . By initial tests indicate that colorama is more mature, even if it requires two lines of code instead of one. import sys try: import colorama colorama.init() except: try: import tendo.ansiterm except: pass sys.stdout.write"\033[33mYellow Submarine" sys.stderr.write"\033[31mred, red ,

How to distinguish between Escape and Escape Sequence

两盒软妹~` 提交于 2019-11-27 06:22:08
问题 My end goal is to distinguish between my pressing Esc (ASCII 27 ) on my keyboard, and me pressing the → key on my keyboard (which translates to a sequence of 27 91 67 ). I am using termios to put my terminal into non-Canonical mode. I think I understand there are two options: Wait some arbitrary amount of time to see if something comes in (seems hacky) Check STDIN to see if it is empty I'm trying to do the latter. To that end, I'm trying to use select to see if stdin is empty or not. The

Python: How can I make the ANSI escape codes to work also in Windows?

不想你离开。 提交于 2019-11-27 01:59:35
If I run this in python under linux it works: start = "\033[1;31m" end = "\033[0;0m" print "File is: " + start + "<placeholder>" + end But if I run it in Windows it doesn't work, how can I make the ANSI escape codes work also on Windows? pr0gg3d You could check Python module to enable ANSI colors for stdout on Windows? to see if it's useful. The colorama module seems to be cross-platform. You install colorama: pip install colorama Then: import colorama colorama.init() start = "\033[1;31m" end = "\033[0;0m" print "File is: " + start + "<placeholder>" + end You could take a look at https:/

Removing colors from output

[亡魂溺海] 提交于 2019-11-26 23:49:25
I have some script that produces output with colors and I need to remove the ANSI codes. #!/bin/bash exec > >(tee log) # redirect the output to a file but keep it on stdout exec 2>&1 ./somescript The output is (in log file): java (pid 12321) is running...@[60G[@[0;32m OK @[0;39m] I didn't know how to put the ESC character here, so I put @ in its place. I changed the script into: #!/bin/bash exec > >(tee log) # redirect the output to a file but keep it on stdout exec 2>&1 ./somescript | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" But now it gives me (in log file): java (pid 12321) is

Filtering out ANSI escape sequences [duplicate]

天涯浪子 提交于 2019-11-26 21:39:36
问题 This question already has answers here : How can I remove the ANSI escape sequences from a string in python (6 answers) Closed 9 months ago . I have a python script that's trying to interpret a trace of data written to and read from stdout and stdin, respectively. The problem is that this data is riddled with ANSI escapes I don't care about. These escapes are JSON encoded, so they look like "\033[A" and "\033]0;". I don't actually need to interpret the codes, but I do need to know how many