認爲我已經完成並準備好提交這個小項目,直到我找到這個意外的曲線球。 目標是使用令牌詞法分析器來製作解析器。 實質上 <underline><red> R <green> G </green> <blue> B </blue> and back to red </red></underline>
將輸出爲:「RGB和回到紅色」在他們各自的顏色和屬性。使用cout << term_cc <color,default,attrib>在Windows終端上輸出顏色和屬性的C++輸出到Windows終端上,但不是在Linux上正確輸出顏色和屬性
一切正常工作在Windows上,但當我把它移到Linux系統它輸出的顏色代碼沒有任何事情發生。
#include <iostream>
#include <sstream>
#include <stack>
#include <map>
#include <cstdlib>
#include <vector>
#include "cmd.h"
#include "Lexer.h" // you should make use of the provided Lexer
#include "term_control.h"
#include "error_handling.h"
using namespace std;
map<string, term_colors_t> colorMap;
map<string, term_attrib_t> attribMap;
string display(const string& expression)
{
if(validate(expression) == "VALID") {
Lexer lex;
Token tok;
vector<term_colors_t> colorVect;
vector<term_attrib_t> attribVect;
lex.set_input(expression);
while(lex.has_more_token()){
tok = lex.next_token();
string sTok = tok.value;
if(tok.type == TAG && tok.value.at(0) != '/'){
cout<<term_cc(colorMap[tok.value], DEFAULT_COLOR, attribMap[tok.value]);
colorVect.push_back(colorMap[tok.value]);
attribVect.push_back(attribMap[tok.value]);
}
if(tok.type == TAG && tok.value.at(0) == '/'){
colorVect.pop_back();
cout<<term_cc(colorVect.back(), DEFAULT_COLOR, attribVect.back());
}
if(tok.type != TAG){
cout<<tok.value;
}
}
}
else if(validate(expression) != "VALID") return validate(expression);
return "";
}
_
cout<term_cc(Color, DEFAULT_COLOR, Attribute)
是specfic方法,其中的問題是躲在我一直在尋找周圍,似乎無法找到正確的方法。
cout<<term_fg(color)
該方法在Linux系統上正確顯示顏色,但我不能使用該方法的屬性。
我一直在閱讀的一切都只涉及顏色而不是顏色和屬性,他們也使用echo命令和特定終端的硬編碼顏色。這些都需要對我的所有代碼進行重大更改,並導致它無法在Windows上運行,只能在Linux上運行,所以我試圖避免這種情況。
在此先感謝有關此問題的任何建議,我希望每個人都能夠在12之前得到這個結果!
什麼是'term_cc'或'term_fg'?你在用圖書館嗎?如果是這樣,它應該在問題或標籤中提及。 – 2014-09-24 01:38:08
您是否在您提供的代碼中表示cout
2014-09-24 01:41:23
添加了一切抱歉的混蛋傢伙。 和cout << term_cc @MichaelPetch – Michael 2014-09-24 01:54:41