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

WIP: towards detecting arbitrary URLs and make them clickable #1079

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ IncludeCategories:
Priority: 3
- Regex: '^<(vtrasterizer)/'
Priority: 4
- Regex: '^<(regex_dfa)/'
Priority: 5
- Regex: '^<(text_shaper)/'
Priority: 5
- Regex: '^<(crispy)/'
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ jobs:
cmake -DCMAKE_BUILD_TYPE=Debug -DLIBTERMINAL_BUILD_BENCH_HEADLESS=ON -DCONTOUR_QT_VERSION=6 -S . -B build
cmake --build build/ -j2
./build/src/crispy/crispy_test
./build/src/regex_dfa/regex_dfa_test
./build/src/vtparser/vtparser_test
./build/src/vtbackend/vtbackend_test
rm -rf _deps build
Expand Down Expand Up @@ -257,6 +258,8 @@ jobs:
run: cmake --build build/
- name: "test: crispy"
run: ./build/src/crispy/crispy_test
- name: "test: regex_dfa"
run: ./build/src/regex_dfa/regex_dfa_test
- name: "test: vtparser"
run: ./build/src/vtparser/vtparser_test
- name: "test: vtbackend"
Expand Down Expand Up @@ -326,6 +329,8 @@ jobs:
run: cmake --build build/ --config Release
- name: "test: crispy"
run: .\build\src\crispy\Release\crispy_test.exe
- name: "test: regex_dfa"
run: .\build\src\regex_dfa\Release\regex_dfa_test.exe
- name: "test: vtparser"
run: .\build\src\vtparser\Release\vtparser_test.exe
- name: "test: vtbackend"
Expand Down Expand Up @@ -450,6 +455,8 @@ jobs:
run: cmake --build build/ -- -j3
- name: "test: crispy"
run: ./build/src/crispy/crispy_test
- name: "test: regex_dfa"
run: ./build/src/regex_dfa/regex_dfa_test
- name: "test: vtparser"
run: ./build/src/vtparser/vtparser_test
- name: "test: vtbackend"
Expand All @@ -461,6 +468,7 @@ jobs:
name: contour-ubuntu2204-tests
path: |
build/src/crispy/crispy_test
build/src/regex_dfa/regex_dfa_test
build/src/vtparser/vtparser_test
build/src/vtbackend/vtbackend_test
build/src/vtbackend/bench-headless
Expand Down Expand Up @@ -516,6 +524,8 @@ jobs:
# run: cmake --build build/ -- -j3
# - name: "test: crispy"
# run: ./build/src/crispy/crispy_test
# - name: "test: regex_dfa"
# run: ./build/src/regex_dfa/regex_dfa_test
# - name: "test: vtparser"
# run: ./build/src/vtparser/vtparser_test
# - name: "test: vtbackend"
Expand Down Expand Up @@ -664,6 +674,8 @@ jobs:
run: cmake --build build/ -- -j3
- name: "test: crispy"
run: ./build/src/crispy/crispy_test
- name: "test: regex_dfa"
run: ./build/src/regex_dfa/regex_dfa_test
- name: "test: vtparser"
run: ./build/src/vtparser/vtparser_test
- name: "test: vtbackend"
Expand Down Expand Up @@ -728,6 +740,8 @@ jobs:
valgrind
- name: "test: crispy (via valgrind)"
run: valgrind --error-exitcode=64 ./build/src/crispy/crispy_test
- name: "test: regex_dfa"
run: valgrind --error-exitcode=64 ./build/src/regex_dfa/regex_dfa_test
- name: "test: vtparser (via valgrind)"
run: valgrind --error-exitcode=64 ./build/src/vtparser/vtparser_test
- name: "test: vtbackend (via valgrind)"
Expand Down
4 changes: 4 additions & 0 deletions cmake/ContourThirdParties.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
ContourThirdParties_Embed_boxed_cpp()
set(THIRDPARTY_BUILDIN_boxed_cpp "embedded")

ContourThirdParties_Embed_ctre()

Check failure on line 133 in cmake/ContourThirdParties.cmake

View workflow job for this annotation

GitHub Actions / Windows

Unknown CMake command "ContourThirdParties_Embed_ctre".
set(THIRDPARTY_BUILDIN_ctre "embedded")

macro(ContourThirdPartiesSummary2)
message(STATUS "==============================================================================")
message(STATUS " Contour ThirdParties")
Expand All @@ -144,5 +147,6 @@
message(STATUS "libunicode ${THIRDPARTY_BUILTIN_unicode_core} (${LIBUNICODE_LIBS})")
message(STATUS "yaml-cpp ${THIRDPARTY_BUILTIN_yaml_cpp}")
message(STATUS "boxed-cpp ${THIRDPARTY_BUILDIN_boxed_cpp}")
message(STATUS "CTRE ${THIRDPARTY_BUILDIN_ctre}")
message(STATUS "------------------------------------------------------------------------------")
endmacro()
11 changes: 11 additions & 0 deletions scripts/install-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ fetch_and_unpack_termbenchpro()
termbench_pro
}

fetch_and_unpack_ctre()
{
local ctre_git_sha="0fdd96db416188a07833606b16633fb977c0cc11"
fetch_and_unpack \
compile-time-regular-expressions-$ctre_git_sha \
ctre-$ctre_git_sha.tar.gz \
https://github.com/hanickadot/compile-time-regular-expressions/archive/$ctre_git_sha.tar.gz \
ctre
}

fetch_and_unpack_boxed()
{
local boxed_cpp_git_sha="daa702e22e71f3da3eef838e4946b6c3df1f16b1"
Expand Down Expand Up @@ -573,6 +583,7 @@ main()

fetch_and_unpack_boxed
fetch_and_unpack_termbenchpro
fetch_and_unpack_ctre
}

main $*
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ endif()
include(PedanticCompiler)

add_subdirectory(crispy)
add_subdirectory(regex_dfa)
add_subdirectory(text_shaper)
add_subdirectory(vtpty)
add_subdirectory(vtparser)
Expand Down
2 changes: 2 additions & 0 deletions src/contour/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ struct TerminalProfile
bool highlightDoubleClickedWord = true;
terminal::StatusDisplayType initialStatusDisplayType = terminal::StatusDisplayType::None;

std::string urlPattern = R"((https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|])";

terminal::Opacity backgroundOpacity; // value between 0 (fully transparent) and 0xFF (fully visible).
bool backgroundBlur; // On Windows 10, this will enable Acrylic Backdrop.

Expand Down
1 change: 1 addition & 0 deletions src/contour/TerminalSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ namespace
settings.primaryScreen.allowReflowOnResize = config.reflowOnResize;
settings.highlightDoubleClickedWord = profile.highlightDoubleClickedWord;
settings.highlightTimeout = profile.highlightTimeout;
settings.urlPattern = profile.urlPattern;

return settings;
}
Expand Down
56 changes: 56 additions & 0 deletions src/regex_dfa/Alphabet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// This file is part of the "klex" project, http://github.com/christianparpart/klex>
// (c) 2018 Christian Parpart <christian@parpart.family>
//
// Licensed under the MIT License (the "License"); you may not use this
// file except in compliance with the License. You may obtain a copy of
// the License at: http://opensource.org/licenses/MIT

#include <regex_dfa/Alphabet.h>
#include <regex_dfa/Symbols.h>

#include <iomanip>
#include <iostream>
#include <sstream>

using namespace std;

namespace regex_dfa
{

#if 0
#define DEBUG(msg, ...) \
do \
{ \
cerr << fmt::format(msg, __VA_ARGS__) << "\n"; \
} while (0)
#else
#define DEBUG(msg, ...) \
do \
{ \
} while (0)
#endif

void Alphabet::insert(Symbol ch)
{
if (_alphabet.find(ch) == _alphabet.end())
{
DEBUG("Alphabet: insert '{:}'", prettySymbol(ch));
_alphabet.insert(ch);
}
}

string Alphabet::to_string() const
{
stringstream sstr;

sstr << '{';

for (Symbol c: _alphabet)
sstr << prettySymbol(c);

sstr << '}';

return sstr.str();
}

} // namespace regex_dfa
60 changes: 60 additions & 0 deletions src/regex_dfa/Alphabet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// This file is part of the "klex" project, http://github.com/christianparpart/klex>
// (c) 2018 Christian Parpart <christian@parpart.family>
//
// Licensed under the MIT License (the "License"); you may not use this
// file except in compliance with the License. You may obtain a copy of
// the License at: http://opensource.org/licenses/MIT
#pragma once

#include <regex_dfa/Symbols.h>

#include <fmt/format.h>

#include <set>
#include <string>

namespace regex_dfa
{

/**
* Represents the alphabet of a finite automaton or regular expression.
*/
class Alphabet
{
public:
using set_type = std::set<Symbol>;
using iterator = set_type::iterator;

[[nodiscard]] size_t size() const noexcept { return _alphabet.size(); }

void insert(Symbol ch);

[[nodiscard]] std::string to_string() const;

[[nodiscard]] iterator begin() const { return _alphabet.begin(); }
[[nodiscard]] iterator end() const { return _alphabet.end(); }

private:
set_type _alphabet;
};

} // namespace regex_dfa

namespace fmt
{
template <>
struct formatter<regex_dfa::Alphabet>
{
template <typename ParseContext>
constexpr auto parse(ParseContext& ctx)
{
return ctx.begin();
}

template <typename FormatContext>
constexpr auto format(const regex_dfa::Alphabet& v, FormatContext& ctx)
{
return fmt::format_to(ctx.out(), "{}", v.to_string());
}
};
} // namespace fmt
43 changes: 43 additions & 0 deletions src/regex_dfa/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
add_library(regex_dfa STATIC
Alphabet.cpp
Compiler.cpp
DFA.cpp
DFABuilder.cpp
DFAMinimizer.cpp
DotWriter.cpp
MultiDFA.cpp
NFA.cpp
NFABuilder.cpp
RegExpr.cpp
RegExprParser.cpp
RuleParser.cpp
State.cpp
Symbols.cpp
Report.cpp
SourceLocation.cpp
)

target_include_directories(regex_dfa PUBLIC ${PROJECT_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src)
target_link_libraries(regex_dfa PUBLIC fmt::fmt-header-only)

# ----------------------------------------------------------------------------
option(REGEX_DFA_TESTING "Enables building of unittests for regex_dfa library [default: ON]" ON)
if(REGEX_DFA_TESTING)
enable_testing()
add_executable(regex_dfa_test
regex_dfa_test.cpp
DFABuilder_test.cpp
DotWriter_test.cpp
Lexer_test.cpp
NFA_test.cpp
RegExprParser_test.cpp
RuleParser_test.cpp
State_test.cpp
Symbols_test.cpp
util/iterator_test.cpp
)

target_link_libraries(regex_dfa_test PUBLIC regex_dfa)
target_link_libraries(regex_dfa_test PUBLIC Catch2::Catch2)
target_link_libraries(regex_dfa_test PUBLIC fmt::fmt-header-only)
endif(REGEX_DFA_TESTING)
67 changes: 67 additions & 0 deletions src/regex_dfa/CharStream.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// This file is part of the "klex" project, http://github.com/christianparpart/klex>
// (c) 2018 Christian Parpart <christian@parpart.family>
//
// Licensed under the MIT License (the "License"); you may not use this
// file except in compliance with the License. You may obtain a copy of
// the License at: http://opensource.org/licenses/MIT
#pragma once

#include <iosfwd>
#include <istream>
#include <string>

namespace regex_dfa
{

class CharStream
{
public:
virtual ~CharStream() = default;

[[nodiscard]] virtual bool isEof() const noexcept = 0;
virtual char get() = 0;
virtual void rollback(int count) = 0;
virtual void rewind() = 0;
};

class StringStream: public CharStream
{
public:
explicit StringStream(std::string&& s): _source { std::move(s) } {}

[[nodiscard]] bool isEof() const noexcept override { return _pos >= _source.size(); }
char get() override { return _source[_pos++]; }
void rollback(int count) override { _pos -= count; }
void rewind() override { _pos = 0; }

private:
std::string _source;
size_t _pos = 0;
};

class StandardStream: public CharStream
{
public:
explicit StandardStream(std::istream* source);

[[nodiscard]] bool isEof() const noexcept override { return !_source->good(); }
char get() override { return static_cast<char>(_source->get()); }

void rollback(int count) override
{
_source->clear();
_source->seekg(-count, std::ios::cur);
}

void rewind() override
{
_source->clear();
_source->seekg(_initialOffset, std::ios::beg);
}

private:
std::istream* _source;
std::streamoff _initialOffset;
};

} // namespace regex_dfa
Loading
Loading