Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to manually select the syntax highlighting language #73

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ if (TURBO_BUILD_APP)
target_link_libraries(${TURBO} PRIVATE
${TURBO}-core
)
target_link_libraries(${TURBO} PRIVATE -ltomlcpp)
install(TARGETS ${TURBO} RUNTIME DESTINATION bin)

if (WIN32)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Then, make sure the following dependencies are installed:
* CMake.
* A compiler supporting C++17.
* `libncursesw` (note the 'w') (Unix only).
* [`libtomlcpp`](https://github.com/cktan/tomlcpp/) (for saving editor config in `~/.config/turbo.toml`)

Additionally, you may also want to install these optional dependencies:

Expand Down
1 change: 0 additions & 1 deletion include/turbo/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class Editor : protected TScintillaParent
bool drawLock {false}; // To avoid recursive draws.
bool reflowLock {false}; // When true, text stops flowing on resize.

void drawViews() noexcept;
void updateMarginWidth() noexcept;

protected:
Expand Down
4 changes: 2 additions & 2 deletions include/turbo/fileeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class FileEditor : public Editor
inline void setFilePath(Path &&path);
void beforeSave() noexcept;
void afterSave() noexcept;
void detectLanguage() noexcept;

public:

Expand All @@ -110,8 +109,9 @@ class FileEditor : public Editor
bool close(FileDialogs & = showAllDialogs) noexcept;

// Called when 'filePath' is set. The default implementation calls
// 'detectLanguage'.
// 'setLanguage'.
virtual void onFilePathSet() noexcept;
void setLanguage(const Language *lang) noexcept;
};

inline FileEditor::FileEditor(TScintilla &aScintilla, std::string aFilePath) noexcept :
Expand Down
55 changes: 31 additions & 24 deletions include/turbo/styles.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace turbo {

struct Language
{
TStringView lineComment {};
TStringView name {};
TStringView lineComment {}; // These are used by the editor to toggle comments on lines
TStringView blockCommentOpen {};
TStringView blockCommentClose {};

Expand All @@ -23,41 +24,47 @@ struct Language
return !blockCommentOpen.empty() && !blockCommentClose.empty();
}

static const Language
CPP,
Makefile,
enum {
Ada = 0,
Asm,
JavaScript,
Rust,
Python,
Bash,
Basic,
Batch,
CPP,
CSS,
CSharp,
Diff,
JSON,
Erlang,
HTML,
XML,
VB,
Perl,
Batch,
JSON,
JavaScript,
LaTex,
Lua,
Ada,
Lisp,
Lua,
MATLAB,
Makefile,
Markdown,
NuShell,
Pascal,
Perl,
Properties,
Python,
Ruby,
Rust,
SQL,
Smalltalk,
Tcl,
VB,
VBScript,
MATLAB,
CSS,
XML,
YAML,
Erlang,
Smalltalk,
Markdown,
Properties,
CSharp,
Basic,
Pascal,
SQL;

COUNT
};
};

extern const Language languages[Language::COUNT]; // Array of Language structs that should be indexed with the Language::* enum.

enum TextStyle : uchar
{
sNormal,
Expand Down
6 changes: 3 additions & 3 deletions source/turbo-core/fileeditor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,16 @@ void FileEditor::afterSave() noexcept
call(scintilla, SCI_SETSAVEPOINT, 0U, 0U);
}

void FileEditor::detectLanguage() noexcept
void FileEditor::setLanguage(const Language *language) noexcept
{
language = detectFileLanguage(filePath.c_str());
this->language = language;
lexer = findBuiltInLexer(language);
applyTheming(lexer, scheme, scintilla);
}

void FileEditor::onFilePathSet() noexcept
{
detectLanguage();
setLanguage(detectFileLanguage(filePath.c_str()));
}

ShowAllDialogs showAllDialogs;
Expand Down
Loading