Skip to content

Commit

Permalink
Add paste selection option to evaluate selection via shell
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaraslaut committed Jul 4, 2024
1 parent ff7fc99 commit c28ebf3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<li>Add key bindings disabled indicator for status line (#783)</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>Update of contour.desktop file (#1423)</li>
<li>Changed configuration entry values for `font_locator` down to `native` and `mock` only (#1538).</li>
<li>Do not export the `TERM` environment variable on Windows OS (when using ConPTY).</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 @@ -1126,12 +1126,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

0 comments on commit c28ebf3

Please sign in to comment.