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

Add paste selection option to evaluate selection via shell #1556

Merged
merged 2 commits into from
Jul 28, 2024
Merged
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 metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<li>Add support for highlighting matches of the currently selected text area (beyond double click)</li>
<li>When switching to normal mode screen will stay in same position (#808)</li>
<li>Add customizable per-input-mode default text/background coloring for indicator statusline (#1528)</li>
<li>Add option PasteSelection to paste text as a shell input (#1549)</li>
<li>Add case-insensitive smart search (#1410)</li>
<li>Add OpenBSD support</li>
<li>Update of contour.desktop file (#1423)</li>
Expand Down
7 changes: 5 additions & 2 deletions src/contour/Actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct OpenConfiguration{};
struct OpenFileManager{};
struct OpenSelection{};
struct PasteClipboard{ bool strip = false; };
struct PasteSelection{};
struct PasteSelection{ bool evaluateInShell = false;};
struct Quit{};
struct ReloadConfig{ std::optional<std::string> profileName; };
struct ResetConfig{};
Expand Down Expand Up @@ -182,7 +182,10 @@ namespace documentation
"Pastes clipboard to standard input. Pass boolean parameter 'strip' to indicate whether or not to "
"strip repetitive whitespaces down to one and newlines to whitespaces."
};
constexpr inline std::string_view PasteSelection { "Pastes current selection to standard input." };
constexpr inline std::string_view PasteSelection { "Pastes current selection to standard input."
"Option `evaluate_in_shell` specify if pasted text "
"must be appended with linefeed and used as an input "
"for the running shell" };
constexpr inline std::string_view Quit { "Quits the application." };
constexpr inline std::string_view ReloadConfig { "Forces a configuration reload." };
constexpr inline std::string_view ResetConfig {
Expand Down
8 changes: 8 additions & 0 deletions src/contour/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,14 @@ std::optional<actions::Action> YAMLConfigReader::parseAction(YAML::Node const& n
}
}

if (holds_alternative<actions::PasteSelection>(action))
{
if (auto eval = node["evaluate_in_shell"]; eval && eval.IsScalar())
{
return actions::PasteSelection { eval.as<bool>() };
}
}

if (holds_alternative<actions::WriteScreen>(action))
{
if (auto chars = node["chars"]; chars.IsScalar())
Expand Down
7 changes: 5 additions & 2 deletions src/contour/TerminalSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,12 +1129,15 @@ bool TerminalSession::operator()(actions::PasteClipboard paste)
return true;
}

bool TerminalSession::operator()(actions::PasteSelection)
bool TerminalSession::operator()(actions::PasteSelection paste)
{
if (QClipboard* clipboard = QGuiApplication::clipboard(); clipboard != nullptr)
{
string const text = normalize_crlf(clipboard->text(QClipboard::Selection));
terminal().sendPaste(string_view { text });
if (paste.evaluateInShell)
terminal().sendRawInput(string_view { text + "\n" });
else
terminal().sendPaste(string_view { text });
}

return true;
Expand Down
Loading