Coder Social home page Coder Social logo

ansi's People

Contributors

fidian avatar joseluis avatar jumanjiman avatar kennethho avatar marxbro avatar rk295 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansi's Issues

Release

Hi, I'm trying to get your package into homebrew, is it possible to do a release?

How to move the cursor right?

How to move the cursor to the right in Ubuntu 20.04.3 LTS in Actions on github? Just like echo -en "\033[70G[ ", export ANSI_FORCE_SUPPORT=anything has been added, ansi --color-table
ansi --color-codes can run normally, thank you!

Couple of questions

Hi,

I made a formatting library when developing my own dotfiles and now came across this awesome library (thanks to awesome-shell). I am thinking about migrating to your library because I am in the middle of refactoring it and I would almost certainly ended up doing what you have already done.

I have 2 questions, though:

  1. It seems your library doesn't support debugging (I guess since it's been 'on the market' for a long time, all bugs has been squished) in a sense of outputting raw data (aka eg. \e[1m\e[38;5;33mJiří Málek\e[m). Are you planning to implement that?

  2. I tried using your library for formatting prompt and it works with no issues. When I was developing mine, it had a nasty bug which caused cursor to behave weird. It would jump around and stuff. I was able to find the cause (after reading a lot of zsh manual) and the fix was to enclose all formatting in prompt with %{ and %} (eg. %{\e[1m\e[38;5;33m%}Jiří Málek%{\e[m%}). It didn't matter if I was generating escape sequences with tput or manually. Did you ever come across this issue?

Thank you

Discussion on an alternative solution (mine)

Hi,
I just discovered your project yesterday, and well done 👏 it's well explained and appears to work exactly as advertised !

I have been using ANSI colors in bash scripts for years, with a completely different approach that I somewhat perceive as simpler and faster. Don't want to brag, not at all, I simply wanted to share it, in order to initiate a discussion: I'm curious to see the advantages and drawbacks of the two solutions.

ansi

Instead of a script that has to be called for each colored section, I use env variables. ansi works like:

$ echo "French flag is $(ansi --blue blue), $(ansi --white white) and $(ansi --red red)."
French flag is blue, white, and red.
  • - This opens three pipes, so it can be slow,
  • - The syntax is long, and repetitive (ansi -- is repeated),
  • + No need to remember about resetting to default or white after each colored part, so easy to use.

.color.sh

My approach also uses a script, but do not need to call it for each colored section.
The script is here: .color.sh, and I source it in my bashrc. It simply defines variables that correspond to the ANSI color code. One for each color, background color etc.
To use it in a script, first I do:

[ -x "$HOME/.color.sh" ] && . "$HOME/.color.sh"  # source color variables if available

And use it like this:

$ echo -e "French flag is ${blue}blue${white}, white, and ${red}red${white}."
French flag is blue, white, and red.
  • - It relies on Bash env variables, which can be overridden in the script (even though it's easy not to, and the variables names are explicitly colors which usually are not use for this),
  • - It needs to have the .color.sh script path known explicitly,
  • - Need to remember to do ${white} after every colored section,
  • + No pipe, so it is probably faster,
  • + Cleaner and shorter syntax,
  • + I also provide a .nocolor.sh script, which simply dereferenced all the variables, so it is easy to add a cli option like --noANSI or --color=none to a script, and source .nocolor.sh if it is given (see example here)

Screenshot

Here is a short illustration of these two examples:
demo_ansi_vs_colorsh
I tested my approach on sh, bash, but not on fish and zsh even though it should work.


Discussion

So basically I would just like to hear your point of view @fidian on this discussion: do you agree with the - drawbacks and + advantages of both approaches ? Do you see others?
Many thanks in advance!

ansi::insertLines does not insert newlines as expected

After calling source ansi, inserting new lines via ansi::insertLines N does not insert any new lines.
Likewise, ansi --insert-lines=N does not insert any new lines.

I'm not sure if I'm using this function correctly, so I provide some concrete examples with precise output below. If you could give me some guidance regarding my use of your scripts, that'd be great.

# using ansi
...$ ansi --insert-lines=5 hello world
hello world
...$ ...
# using ansi::insertLines
...$ ansi::insertLines 5
...$ ...

I am using Ubuntu 22.04 under WSL. My version of bash is provided below. I will also include some potentially useful information regarding ANSI_* variables defined ansi.

...$ echo "$ANSI_ESC"

...$ echo "$ANSI_CSI"

...$ echo "$ANSI_OSC"
...$ echo "$ANSI_ST"

...$ bash --version
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Thanks!
Matthew J

bash: shift: shift count out of range

When ansi is called with no arguments other than flags, it prints an error.

For example:

$ ansi --report-position
3,1
bash: shift: shift count out of range

(Was is tested with Bash version 5.1.8(1)-release (x86_64-pc-linux-gnu) on Ubuntu 20.10.)

Proposed Solution

Change

ansi/ansi

Line 1603 in 225a28e

shift || :
to

shift 2> /dev/null || :

Unbound variable $1

Hi,

I am running script with set -euo pipefail and the library produces unbound variable error and stops the script.

#! /usr/bin/env bash

set -euo pipefail

. vendor/fidian/ansi/ansi

echo "this line gets printed"

fmt_bold="$(ansi --bold --no-restore)"

echo "this one does not"

ansi --underline --no-restore

echo "neither this one"
$ ./ansi-test.sh
this line gets printed
vendor/fidian/ansi/ansi: line 868: $1: unbound variable

UTF-8 encoded strings are not interpreted

Hi,

I finally migrated my dotfiles to ansi library. I am using as mark that my commits are being signed. Sadly, I am currently not able to print this mark using UTF-8 encoded syntax.

ansi --bold --color=64 "\xE2\x9C\x94" prints \xE2\x9C\x94 instead of .

Escapes not evaluating correctly

Greetings,

I gave your script a try, but unfortunately it didn't seem to work for me..

lylemoffitt% ls
LICENSE.md README.md  ansi       examples   images                                                                                                                                                                 lylemoffitt% ansi --color-table
bold \e[1mSample\e[22m               faint \e[2mSample\e[22m              italic \e[3mSample\e[23m
underline \e[4mSample\e[24m          blink \e[5mSample\e[25m              inverse \e[7mSample\e[27m
invisible \e[8mSample\e[28m
strike \e[9mSample\e[29m             fraktur \e[20mSample\e[23m            double-underline \e[21mSample\e[24m
frame \e[51mSample\e[54m              encircle \e[52mSample\e[54m           overline \e[53mSample\e[55m

             black   red     green   yellow  blue    magenta cyan    white
bg-black     \e[40;30m\e[2mf\e[22mn\e[1mb\e[22m\e[90m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[40;31m\e[2mf\e[22mn\e[1mb\e[22m\e[91m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[40;32m\e[2mf\e[22mn\e[1mb\e[22m\e[92m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[40;33m\e[2mf\e[22mn\e[1mb\e[22m\e[93m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[40;34m\e[2mf\e[22mn\e[1mb\e[22m\e[94m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[40;35m\e[2mf\e[22mn\e[1mb\e[22m\e[95m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[40;36m\e[2mf\e[22mn\e[1mb\e[22m\e[96m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[40;37m\e[2mf\e[22mn\e[1mb\e[22m\e[97m\e[2mF\e[22mN\e[1mB\e[22m\e[0m
  +intense   \e[100;30m\e[2mf\e[22mn\e[1mb\e[22m\e[90m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[100;31m\e[2mf\e[22mn\e[1mb\e[22m\e[91m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[100;32m\e[2mf\e[22mn\e[1mb\e[22m\e[92m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[100;33m\e[2mf\e[22mn\e[1mb\e[22m\e[93m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[100;34m\e[2mf\e[22mn\e[1mb\e[22m\e[94m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[100;35m\e[2mf\e[22mn\e[1mb\e[22m\e[95m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[100;36m\e[2mf\e[22mn\e[1mb\e[22m\e[96m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[100;37m\e[2mf\e[22mn\e[1mb\e[22m\e[97m\e[2mF\e[22mN\e[1mB\e[22m\e[0m
bg-red       \e[41;30m\e[2mf\e[22mn\e[1mb\e[22m\e[90m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[41;31m\e[2mf\e[22mn\e[1mb\e[22m\e[91m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[41;32m\e[2mf\e[22mn\e[1mb\e[22m\e[92m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[41;33m\e[2mf\e[22mn\e[1mb\e[22m\e[93m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[41;34m\e[2mf\e[22mn\e[1mb\e[22m\e[94m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[41;35m\e[2mf\e[22mn\e[1mb\e[22m\e[95m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[41;36m\e[2mf\e[22mn\e[1mb\e[22m\e[96m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[41;37m\e[2mf\e[22mn\e[1mb\e[22m\e[97m\e[2mF\e[22mN\e[1mB\e[22m\e[0m
  +intense   \e[101;30m\e[2mf\e[22mn\e[1mb\e[22m\e[90m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[101;31m\e[2mf\e[22mn\e[1mb\e[22m\e[91m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[101;32m\e[2mf\e[22mn\e[1mb\e[22m\e[92m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[101;33m\e[2mf\e[22mn\e[1mb\e[22m\e[93m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[101;34m\e[2mf\e[22mn\e[1mb\e[22m\e[94m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[101;35m\e[2mf\e[22mn\e[1mb\e[22m\e[95m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[101;36m\e[2mf\e[22mn\e[1mb\e[22m\e[96m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[101;37m\e[2mf\e[22mn\e[1mb\e[22m\e[97m\e[2mF\e[22mN\e[1mB\e[22m\e[0m
bg-green     \e[42;30m\e[2mf\e[22mn\e[1mb\e[22m\e[90m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[42;31m\e[2mf\e[22mn\e[1mb\e[22m\e[91m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[42;32m\e[2mf\e[22mn\e[1mb\e[22m\e[92m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[42;33m\e[2mf\e[22mn\e[1mb\e[22m\e[93m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[42;34m\e[2mf\e[22mn\e[1mb\e[22m\e[94m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[42;35m\e[2mf\e[22mn\e[1mb\e[22m\e[95m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[42;36m\e[2mf\e[22mn\e[1mb\e[22m\e[96m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[42;37m\e[2mf\e[22mn\e[1mb\e[22m\e[97m\e[2mF\e[22mN\e[1mB\e[22m\e[0m
  +intense   \e[102;30m\e[2mf\e[22mn\e[1mb\e[22m\e[90m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[102;31m\e[2mf\e[22mn\e[1mb\e[22m\e[91m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[102;32m\e[2mf\e[22mn\e[1mb\e[22m\e[92m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[102;33m\e[2mf\e[22mn\e[1mb\e[22m\e[93m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[102;34m\e[2mf\e[22mn\e[1mb\e[22m\e[94m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[102;35m\e[2mf\e[22mn\e[1mb\e[22m\e[95m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[102;36m\e[2mf\e[22mn\e[1mb\e[22m\e[96m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[102;37m\e[2mf\e[22mn\e[1mb\e[22m\e[97m\e[2mF\e[22mN\e[1mB\e[22m\e[0m
bg-yellow    \e[43;30m\e[2mf\e[22mn\e[1mb\e[22m\e[90m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[43;31m\e[2mf\e[22mn\e[1mb\e[22m\e[91m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[43;32m\e[2mf\e[22mn\e[1mb\e[22m\e[92m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[43;33m\e[2mf\e[22mn\e[1mb\e[22m\e[93m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[43;34m\e[2mf\e[22mn\e[1mb\e[22m\e[94m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[43;35m\e[2mf\e[22mn\e[1mb\e[22m\e[95m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[43;36m\e[2mf\e[22mn\e[1mb\e[22m\e[96m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[43;37m\e[2mf\e[22mn\e[1mb\e[22m\e[97m\e[2mF\e[22mN\e[1mB\e[22m\e[0m
  +intense   \e[103;30m\e[2mf\e[22mn\e[1mb\e[22m\e[90m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[103;31m\e[2mf\e[22mn\e[1mb\e[22m\e[91m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[103;32m\e[2mf\e[22mn\e[1mb\e[22m\e[92m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[103;33m\e[2mf\e[22mn\e[1mb\e[22m\e[93m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[103;34m\e[2mf\e[22mn\e[1mb\e[22m\e[94m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[103;35m\e[2mf\e[22mn\e[1mb\e[22m\e[95m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[103;36m\e[2mf\e[22mn\e[1mb\e[22m\e[96m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[103;37m\e[2mf\e[22mn\e[1mb\e[22m\e[97m\e[2mF\e[22mN\e[1mB\e[22m\e[0m
bg-blue      \e[44;30m\e[2mf\e[22mn\e[1mb\e[22m\e[90m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[44;31m\e[2mf\e[22mn\e[1mb\e[22m\e[91m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[44;32m\e[2mf\e[22mn\e[1mb\e[22m\e[92m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[44;33m\e[2mf\e[22mn\e[1mb\e[22m\e[93m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[44;34m\e[2mf\e[22mn\e[1mb\e[22m\e[94m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[44;35m\e[2mf\e[22mn\e[1mb\e[22m\e[95m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[44;36m\e[2mf\e[22mn\e[1mb\e[22m\e[96m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[44;37m\e[2mf\e[22mn\e[1mb\e[22m\e[97m\e[2mF\e[22mN\e[1mB\e[22m\e[0m
  +intense   \e[104;30m\e[2mf\e[22mn\e[1mb\e[22m\e[90m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[104;31m\e[2mf\e[22mn\e[1mb\e[22m\e[91m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[104;32m\e[2mf\e[22mn\e[1mb\e[22m\e[92m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[104;33m\e[2mf\e[22mn\e[1mb\e[22m\e[93m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[104;34m\e[2mf\e[22mn\e[1mb\e[22m\e[94m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[104;35m\e[2mf\e[22mn\e[1mb\e[22m\e[95m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[104;36m\e[2mf\e[22mn\e[1mb\e[22m\e[96m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[104;37m\e[2mf\e[22mn\e[1mb\e[22m\e[97m\e[2mF\e[22mN\e[1mB\e[22m\e[0m
bg-magenta   \e[45;30m\e[2mf\e[22mn\e[1mb\e[22m\e[90m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[45;31m\e[2mf\e[22mn\e[1mb\e[22m\e[91m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[45;32m\e[2mf\e[22mn\e[1mb\e[22m\e[92m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[45;33m\e[2mf\e[22mn\e[1mb\e[22m\e[93m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[45;34m\e[2mf\e[22mn\e[1mb\e[22m\e[94m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[45;35m\e[2mf\e[22mn\e[1mb\e[22m\e[95m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[45;36m\e[2mf\e[22mn\e[1mb\e[22m\e[96m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[45;37m\e[2mf\e[22mn\e[1mb\e[22m\e[97m\e[2mF\e[22mN\e[1mB\e[22m\e[0m
  +intense   \e[105;30m\e[2mf\e[22mn\e[1mb\e[22m\e[90m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[105;31m\e[2mf\e[22mn\e[1mb\e[22m\e[91m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[105;32m\e[2mf\e[22mn\e[1mb\e[22m\e[92m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[105;33m\e[2mf\e[22mn\e[1mb\e[22m\e[93m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[105;34m\e[2mf\e[22mn\e[1mb\e[22m\e[94m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[105;35m\e[2mf\e[22mn\e[1mb\e[22m\e[95m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[105;36m\e[2mf\e[22mn\e[1mb\e[22m\e[96m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[105;37m\e[2mf\e[22mn\e[1mb\e[22m\e[97m\e[2mF\e[22mN\e[1mB\e[22m\e[0m
bg-cyan      \e[46;30m\e[2mf\e[22mn\e[1mb\e[22m\e[90m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[46;31m\e[2mf\e[22mn\e[1mb\e[22m\e[91m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[46;32m\e[2mf\e[22mn\e[1mb\e[22m\e[92m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[46;33m\e[2mf\e[22mn\e[1mb\e[22m\e[93m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[46;34m\e[2mf\e[22mn\e[1mb\e[22m\e[94m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[46;35m\e[2mf\e[22mn\e[1mb\e[22m\e[95m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[46;36m\e[2mf\e[22mn\e[1mb\e[22m\e[96m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[46;37m\e[2mf\e[22mn\e[1mb\e[22m\e[97m\e[2mF\e[22mN\e[1mB\e[22m\e[0m
  +intense   \e[106;30m\e[2mf\e[22mn\e[1mb\e[22m\e[90m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[106;31m\e[2mf\e[22mn\e[1mb\e[22m\e[91m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[106;32m\e[2mf\e[22mn\e[1mb\e[22m\e[92m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[106;33m\e[2mf\e[22mn\e[1mb\e[22m\e[93m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[106;34m\e[2mf\e[22mn\e[1mb\e[22m\e[94m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[106;35m\e[2mf\e[22mn\e[1mb\e[22m\e[95m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[106;36m\e[2mf\e[22mn\e[1mb\e[22m\e[96m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[106;37m\e[2mf\e[22mn\e[1mb\e[22m\e[97m\e[2mF\e[22mN\e[1mB\e[22m\e[0m
bg-white     \e[47;30m\e[2mf\e[22mn\e[1mb\e[22m\e[90m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[47;31m\e[2mf\e[22mn\e[1mb\e[22m\e[91m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[47;32m\e[2mf\e[22mn\e[1mb\e[22m\e[92m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[47;33m\e[2mf\e[22mn\e[1mb\e[22m\e[93m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[47;34m\e[2mf\e[22mn\e[1mb\e[22m\e[94m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[47;35m\e[2mf\e[22mn\e[1mb\e[22m\e[95m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[47;36m\e[2mf\e[22mn\e[1mb\e[22m\e[96m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[47;37m\e[2mf\e[22mn\e[1mb\e[22m\e[97m\e[2mF\e[22mN\e[1mB\e[22m\e[0m
  +intense   \e[107;30m\e[2mf\e[22mn\e[1mb\e[22m\e[90m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[107;31m\e[2mf\e[22mn\e[1mb\e[22m\e[91m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[107;32m\e[2mf\e[22mn\e[1mb\e[22m\e[92m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[107;33m\e[2mf\e[22mn\e[1mb\e[22m\e[93m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[107;34m\e[2mf\e[22mn\e[1mb\e[22m\e[94m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[107;35m\e[2mf\e[22mn\e[1mb\e[22m\e[95m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[107;36m\e[2mf\e[22mn\e[1mb\e[22m\e[96m\e[2mF\e[22mN\e[1mB\e[22m\e[0m  \e[107;37m\e[2mf\e[22mn\e[1mb\e[22m\e[97m\e[2mF\e[22mN\e[1mB\e[22m\e[0m

Legend:
    Normal color:  f = faint, n = normal, b = bold.
    Intense color:  F = faint, N = normal, B = bold.
lylemoffitt%

I got the same results in BASH and ZSH (login shell). This is on OSX 10.8.


In any case I ended up going with chalk in node.js, so don't worry about fixing it or anything. I just thought this info might be interesting to you.

Incorrect echos with `ansi::reportPosition` and the Linux console

Running ansi::reportPosition on a Linux console sometimes shows the escaped version of the report, as shown in the following example.

$ source s/ansi.git/ansi
$ ansi::reportPosition
3,1
$ ansi::reportPosition
\[[5;1R5,1

What I think is happening is that the report "[[5;1R" is getting echoed when it shouldn't be.

Note that by "Linux console" I mean what you get with "Ctrl-Alt-F3", not a terminal emulator like gnome-terminal.

Also note that this is a very inconsistent bug. Sometimes ansi::reportPosition behaves correctly, as in the first invocation above. Sometimes, it behaves incorrectly, as in the second invocation above. Thus, for testing, be sure to run ansi::reportPosition multiple times (e.g., run for i in $(seq 1 100); do ansi::reportProblem; done), and even run it a few times).

Proposed Solution

Using the -p option of read instead of printf seems to resolve this issue. (I don't know why it resolves it, just that it does.)

Thus, the problem is fixed by changing the following lines

ansi/ansi

Lines 543 to 547 in 225a28e

# Write to stderr to bypass piping, which lets this work:
# ansi --report-window-chars | cut -d , -f 1
printf "%s%s" "$ANSI_CSI" "$1" >&2
report=""
read -r -N "${#2}" -s -t 1 buff
to

    report=""
    # Note: `read` bypasses piping, which lets this work:
    # ansi --report-window-chars | cut -d , -f 1
    read -p "$ANSI_CSI""$1" -r -N "${#2}" -s -t 1 buff

(Sorry to not make a proper pull request of this fix. I'm busy working on other things and just happened to notice this problem.)

There is not --reset-all option

Hi,

in the README, there is an example of option --reset and its equivalent. --reset-all doesn't exist.

# Reset the terminal colors, reset to the default font, move the cursor
# to row 1 column 1, and show the cursor if it was previously hidden.
# This is the same as the --reset option.
ansi --erase-display=2 --reset-all --position=1,1 --show-cursor \
    --reset-font
$ ansi --reset-all test
--reset-all test

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.