[vte/wip/rishi/precmd-preexec: 1/4] Support preexec notifications from an interactive shell
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte/wip/rishi/precmd-preexec: 1/4] Support preexec notifications from an interactive shell
- Date: Mon, 21 May 2018 09:39:33 +0000 (UTC)
commit 0924f742c448fb5a585b4b2edc451667227d5874
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Jan 7 16:01:00 2015 +0100
Support preexec notifications from an interactive shell
Add sequences
OSC 777 ; preexec BEL
OSC 777 ; preexec ST
that can be used from an interactive shell's preexec hook to notify
the terminal emulator that a new command is about to be executed.
Examples of such hooks are Bash's PS0 and Zsh's preexec.
The OSC 777 escape sequence is taken from Enlightenment's Terminology:
https://phab.enlightenment.org/T1765
https://bugzilla.gnome.org/show_bug.cgi?id=711059
https://bugzilla.gnome.org/show_bug.cgi?id=711060
src/vte.cc | 7 +++++++
src/vte.sh | 2 +-
src/vte/vteterminal.h | 4 +++-
src/vtegtk.cc | 18 ++++++++++++++++++
src/vtegtk.hh | 1 +
src/vteinternal.hh | 5 +++++
src/vteseq.cc | 19 ++++++++++++++++++-
7 files changed, 53 insertions(+), 3 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index 2a76632..1a7b533 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -10762,6 +10762,13 @@ VteTerminalPrivate::emit_pending_signals()
emit_adjustment_changed();
+ if (m_shell_preexec) {
+ _vte_debug_print (VTE_DEBUG_SIGNALS,
+ "Emitting `shell-preexec'.\n");
+ g_signal_emit(object, signals[SIGNAL_SHELL_PREEXEC], 0);
+ m_shell_preexec = FALSE;
+ }
+
if (m_window_title_changed) {
if (m_window_title != m_window_title_pending) {
m_window_title.swap(m_window_title_pending);
diff --git a/src/vte.sh b/src/vte.sh
index 5fb1699..4ade59d 100644
--- a/src/vte.sh
+++ b/src/vte.sh
@@ -57,7 +57,7 @@ __vte_prompt_command() {
case "$TERM" in
xterm*|vte*)
- [ -n "$BASH_VERSION" ] && PROMPT_COMMAND="__vte_prompt_command"
+ [ -n "$BASH_VERSION" ] && PROMPT_COMMAND="__vte_prompt_command" && PS0=$(printf
"\u009D777;preexec\u009C")
[ -n "$ZSH_VERSION" ] && precmd_functions+=(__vte_osc7)
;;
esac
diff --git a/src/vte/vteterminal.h b/src/vte/vteterminal.h
index 8c493bc..5f3d325 100644
--- a/src/vte/vteterminal.h
+++ b/src/vte/vteterminal.h
@@ -104,8 +104,10 @@ struct _VteTerminalClass {
void (*bell)(VteTerminal* terminal);
+ void (*shell_preexec)(VteTerminal* terminal);
+
/* Padding for future expansion. */
- gpointer padding[16];
+ gpointer padding[15];
VteTerminalClassPrivate *priv;
};
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index 4d74b21..1e5282c 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -700,6 +700,7 @@ vte_terminal_class_init(VteTerminalClass *klass)
klass->child_exited = NULL;
klass->encoding_changed = NULL;
klass->char_size_changed = NULL;
+ klass->shell_preexec = NULL;
klass->window_title_changed = NULL;
klass->icon_title_changed = NULL;
klass->selection_changed = NULL;
@@ -776,6 +777,23 @@ vte_terminal_class_init(VteTerminalClass *klass)
1, G_TYPE_INT);
/**
+ * VteTerminal::shell-preexec:
+ * @vteterminal: the object which received the signal
+ *
+ * Emitted when the interactive shell has read in a complete
+ * command and is about to execute it.
+ */
+ signals[SIGNAL_SHELL_PREEXEC] =
+ g_signal_new(I_("shell-preexec"),
+ G_OBJECT_CLASS_TYPE(klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(VteTerminalClass, shell_preexec),
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ /**
* VteTerminal::window-title-changed:
* @vteterminal: the object which received the signal
*
diff --git a/src/vtegtk.hh b/src/vtegtk.hh
index c49754e..cb7b02f 100644
--- a/src/vtegtk.hh
+++ b/src/vtegtk.hh
@@ -52,6 +52,7 @@ enum {
SIGNAL_RESIZE_WINDOW,
SIGNAL_RESTORE_WINDOW,
SIGNAL_SELECTION_CHANGED,
+ SIGNAL_SHELL_PREEXEC,
SIGNAL_TEXT_DELETED,
SIGNAL_TEXT_INSERTED,
SIGNAL_TEXT_MODIFIED,
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 737678a..1c1db50 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -572,6 +572,8 @@ public:
gboolean m_cursor_moved_pending;
gboolean m_contents_changed_pending;
+ gboolean m_shell_preexec;
+
std::string m_window_title{};
std::string m_current_directory_uri{};
std::string m_current_file_uri{};
@@ -1315,6 +1317,9 @@ public:
int osc) noexcept;
/* OSC handlers */
+ void handle_urxvt_extension(vte::parser::Sequence const& seq,
+ vte::parser::StringTokeniser::const_iterator& token,
+ vte::parser::StringTokeniser::const_iterator const& endtoken) noexcept;
void set_color(vte::parser::Sequence const& seq,
vte::parser::StringTokeniser::const_iterator& token,
vte::parser::StringTokeniser::const_iterator const& endtoken,
diff --git a/src/vteseq.cc b/src/vteseq.cc
index ba97480..5c6492a 100644
--- a/src/vteseq.cc
+++ b/src/vteseq.cc
@@ -1339,6 +1339,20 @@ VteTerminalPrivate::delete_lines(vte::grid::row_t param)
m_text_deleted_flag = TRUE;
}
+void
+VteTerminalPrivate::handle_urxvt_extension(vte::parser::Sequence const& seq,
+ vte::parser::StringTokeniser::const_iterator& token,
+ vte::parser::StringTokeniser::const_iterator const& endtoken)
noexcept
+{
+ if (token == endtoken) {
+ return;
+ }
+
+ if (*token == "preexec") {
+ m_shell_preexec = TRUE;
+ }
+}
+
bool
VteTerminalPrivate::get_osc_color_index(int osc,
int value,
@@ -6342,6 +6356,10 @@ VteTerminalPrivate::OSC(vte::parser::Sequence const& seq)
reset_color(VTE_HIGHLIGHT_FG, VTE_COLOR_SOURCE_ESCAPE);
break;
+ case VTE_OSC_URXVT_EXTENSION:
+ handle_urxvt_extension(seq, it, cend);
+ break;
+
case VTE_OSC_XTERM_SET_ICON_TITLE:
case VTE_OSC_XTERM_SET_XPROPERTY:
case VTE_OSC_XTERM_SET_COLOR_MOUSE_CURSOR_FG:
@@ -6382,7 +6400,6 @@ VteTerminalPrivate::OSC(vte::parser::Sequence const& seq)
case VTE_OSC_URXVT_SET_FONT_BOLD_ITALIC:
case VTE_OSC_URXVT_VIEW_UP:
case VTE_OSC_URXVT_VIEW_DOWN:
- case VTE_OSC_URXVT_EXTENSION:
case VTE_OSC_YF_RQGWR:
default:
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]