2011-12-02 41 views

回答

12

根據終端的ECMA-48標準,SGR(Select Graphic Rendition)代碼9應該能夠實現劃叉文本。然而,維基百科頁面說,它沒有得到廣泛的支持,我不知道有這樣做。我懷疑那是因爲DEC的VTxxx系列didn't support it

+0

我的'libvterm' /'pangoterm'可以做到這一點。請參閱[鏈接](http://leonerds-code.blogspot.com/2011/09/libvtermpangoterm-and-tickit.html)中的第二個屏幕截圖 – LeoNerd

+3

實際上,一組優秀的shell終端似乎支持它(這包括''guake'',''terminator'',''gnome-terminal'',...)。 http://misc.flogisoft.com/bash/tip_colors_and_formatting#terminals_compatibility。快速測試:''echo -e「\ e [9mtest \ e [0m」''。 – vaab

4

用C11或C++ 11編寫的應用程序的替代解決方案是使用Unicode combining long stroke overlay字符。

在C++ 11,你可以編寫代碼是這樣的:

#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; 
} 

代碼前綴每個字符與行程覆蓋\u0336輸入text。請注意,該函數假定text採用單字節編碼(如ASCII或拉丁文)進行編碼。如果輸入爲UTF-8,則必須首先將其轉換爲UTF-32以獲取字符邊界。

然後輸出爲s̶t̶r̶i̶k̶e̶t̶h̶r̶o̶u̶g̶h在UTF-8能力的終端。我不知道爲什麼第一個角色沒有穿透力,一定是終極問題。我可以通過在刪除線函數調用之前至少打印一個字符來解決此問題。

與上面提到的ANSI轉義序列相比,Unicode解決方案還會在我的終端(terminator)中生成稍微不同的鎖定。前者使文本正好在文本的中間,而後者使文本略低於文本。

相關問題