-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow using LexTerminal for wxVersion < 3.3
Signed-off-by: Eran Ifrah <[email protected]>
- Loading branch information
Showing
7 changed files
with
229 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include "ConsoleLexer.hpp" | ||
|
||
#include "ExtraLexers.h" | ||
#include "file_logger.h" | ||
|
||
namespace | ||
{ | ||
class StcAccessor : public AccessorInterface | ||
{ | ||
public: | ||
StcAccessor(wxStyledTextCtrl* ctrl) | ||
: m_ctrl(ctrl) | ||
{ | ||
} | ||
const char operator[](size_t index) const override { return SafeGetCharAt(index); } | ||
char SafeGetCharAt(size_t index, char chDefault = ' ') const override | ||
{ | ||
if (index >= m_ctrl->GetLength()) { | ||
return chDefault; | ||
} | ||
return m_ctrl->GetCharAt(index); | ||
} | ||
|
||
/// Style from the current position to the `pos` | ||
void ColourTo(size_t pos, int style) override | ||
{ | ||
pos += 1; | ||
size_t last_styled_pos = m_ctrl->GetEndStyled(); | ||
CHECK_COND_RET(pos > last_styled_pos); | ||
m_ctrl->SetStyling(pos - last_styled_pos, style); | ||
} | ||
|
||
void StartAt(size_t start) override { m_ctrl->StartStyling(start); } | ||
void StartSegment(size_t pos) override { m_ctrl->StartStyling(pos); } | ||
int GetPropertyInt(const std::string& name, int defaultVal = 0) const override | ||
{ | ||
wxUnusedVar(name); | ||
wxUnusedVar(defaultVal); | ||
return 1; | ||
}; | ||
|
||
private: | ||
wxStyledTextCtrl* m_ctrl = nullptr; | ||
}; | ||
} // namespace | ||
|
||
ConsoleLexer::ConsoleLexer(wxStyledTextCtrl* stc) | ||
: m_stc(stc) | ||
{ | ||
m_stc->Bind(wxEVT_STC_STYLENEEDED, &ConsoleLexer::OnStyleNeeded, this); | ||
CallAfter(&ConsoleLexer::SetStyles); | ||
} | ||
|
||
ConsoleLexer::~ConsoleLexer() { m_stc->Unbind(wxEVT_STC_STYLENEEDED, &ConsoleLexer::OnStyleNeeded, this); } | ||
|
||
/// Apply the lexer's "terminal" styles for this instance managed wxSTC | ||
void ConsoleLexer::SetStyles() | ||
{ | ||
m_stc->SetProperty("lexer.errorlist.escape.sequences", "1"); | ||
m_stc->SetProperty("lexer.errorlist.value.separate", "1"); | ||
m_stc->SetProperty("lexer.terminal.escape.sequences", "1"); | ||
m_stc->SetProperty("lexer.terminal.value.separate", "1"); | ||
|
||
// Hide escape sequence styles | ||
m_stc->StyleSetVisible(wxSTC_TERMINAL_ESCSEQ, false); | ||
m_stc->StyleSetVisible(wxSTC_TERMINAL_ESCSEQ_UNKNOWN, false); | ||
} | ||
|
||
void ConsoleLexer::OnStyleNeeded(wxStyledTextEvent& e) | ||
{ | ||
e.Skip(); | ||
int startPos = m_stc->GetEndStyled(); | ||
int endPos = e.GetPosition(); | ||
|
||
StcAccessor styler(m_stc); | ||
::LexerTerminalStyle(startPos, (endPos - startPos), styler); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#pragma once | ||
|
||
#include "codelite_exports.h" | ||
|
||
#include <memory> | ||
#include <wx/stc/stc.h> | ||
|
||
#define CONSOLE_LEXER_DEFAULT 0 | ||
#define CONSOLE_LEXER_PYTHON 1 | ||
#define CONSOLE_LEXER_GCC_ERROR 2 | ||
#define CONSOLE_LEXER_GCC_INCLUDED_FROM 22 | ||
#define CONSOLE_LEXER_GCC_WARNING 56 | ||
#define CONSOLE_LEXER_GCC_EXCERPT 25 | ||
#define CONSOLE_LEXER_GCC_NOTE 57 | ||
#define CONSOLE_LEXER_ESCSEQ 23 | ||
#define CONSOLE_LEXER_ESCSEQ_UNKNOWN 24 | ||
#define CONSOLE_LEXER_ANSI_BLACK 40 | ||
#define CONSOLE_LEXER_ANSI_RED 41 | ||
#define CONSOLE_LEXER_ANSI_GREEN 42 | ||
#define CONSOLE_LEXER_ANSI_BROWN 43 | ||
#define CONSOLE_LEXER_ANSI_BLUE 44 | ||
#define CONSOLE_LEXER_ANSI_MAGENTA 45 | ||
#define CONSOLE_LEXER_ANSI_CYAN 46 | ||
#define CONSOLE_LEXER_ANSI_GRAY 47 | ||
#define CONSOLE_LEXER_ANSI_DARK_GRAY 48 | ||
#define CONSOLE_LEXER_ANSI_BRIGHT_RED 49 | ||
#define CONSOLE_LEXER_ANSI_BRIGHT_GREEN 50 | ||
#define CONSOLE_LEXER_ANSI_YELLOW 51 | ||
#define CONSOLE_LEXER_ANSI_BRIGHT_BLUE 52 | ||
#define CONSOLE_LEXER_ANSI_BRIGHT_MAGENTA 53 | ||
#define CONSOLE_LEXER_ANSI_BRIGHT_CYAN 54 | ||
#define CONSOLE_LEXER_ANSI_WHITE 55 | ||
|
||
class WXDLLIMPEXP_SDK ConsoleLexer : public wxEvtHandler | ||
{ | ||
using Ptr_t = std::unique_ptr<ConsoleLexer>; | ||
|
||
public: | ||
ConsoleLexer(wxStyledTextCtrl* stc); | ||
virtual ~ConsoleLexer(); | ||
|
||
/** | ||
* @brief initialize the control styles and colours | ||
*/ | ||
void SetStyles(); | ||
|
||
protected: | ||
void OnStyleNeeded(wxStyledTextEvent& e); | ||
|
||
wxStyledTextCtrl* m_stc = nullptr; | ||
}; | ||
|
||
class WXDLLIMPEXP_SDK ConsoleLexerClientData : public wxClientData | ||
{ | ||
public: | ||
ConsoleLexerClientData(wxStyledTextCtrl* ctrl) | ||
: m_lexer(ctrl) | ||
{ | ||
} | ||
virtual ~ConsoleLexerClientData() {} | ||
|
||
ConsoleLexer& GetLexer() { return m_lexer; } | ||
|
||
private: | ||
ConsoleLexer m_lexer; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters