Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"?

like image 263
soc Avatar asked Dec 02 '11 13:12

soc


People also ask

Can you put a strikethrough text?

Apply or remove single-line strikethrough formatting Select the text that you want to format. Go to Home > Strikethrough.

How do you strikethrough text in JavaScript?

To create a strikethrough text with JavaScript, use the strike() method. This method causes a string to be displayed as struck-out text as if it were in a <strike> tag.

What does strike through text mean?

A strikethrough is a horizontal line drawn through text, used to indicate the deletion of an error or the removal of text in a draft.

What is crossed out text called?

Strikethrough is a typographical presentation of words with a horizontal line through their center, resulting in text like this. Contrary to censored or sanitized (redacted) texts, the words remain readable.


3 Answers

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 suspect that's because DEC's VTxxx series didn't support it.

like image 195
ak2 Avatar answered Oct 04 '22 03:10

ak2


This works for me.

$ echo -e `echo "this is a strikethrough text" | sed 's/.\{1\}/&\\\u0336/g'`

like image 42
Nitin Avatar answered Oct 04 '22 03:10

Nitin


An alternative solution for applications written in C11 or C++11 is to use the Unicode combining long stroke overlay character.

In C++11 you can write code something like this:

#include <iostream>
#include <string>

std::string strikethrough(const std::string& text) {
  std::string result;
  for (auto ch : text) {
    result.append(u8"\u0336");
    result.push_back(ch);
  }
  return result;
}

int main() {
  std::cout << strikethrough("strikethrough") << std::endl;
}

The code prefixes each character in the input text with the stroke overlay \u0336. Note that the function assumes that text is encoded in a singlebyte encoding such as ASCII or Latin. If the input is in UTF-8 it must be converted to UTF-32 first to get the character boundaries.

The output then is s̶t̶r̶i̶k̶e̶t̶h̶r̶o̶u̶g̶h in a UTF-8 capable terminal. I don't know why the first character has no strike-through, must be a terminal issue. I could work around this by printing at least one character before the strikethrough function call.

The Unicode solution also generates a slightly different locking in my terminal (terminator) compared to the ANSI escape sequence mentioned above. The former renders the line exactly in the middle of the text whereas the latter renders it a bit below.

like image 30
Martin Trenkmann Avatar answered Oct 04 '22 01:10

Martin Trenkmann