diff options
author | Christian Persch <chpe@src.gnome.org> | 2022-12-20 22:11:56 +0100 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2022-12-20 22:11:56 +0100 |
commit | d1559c9141b51714116290bdca502610324ad54c (patch) | |
tree | 55af3c629921d81676bde2a684b1abbc8e3f36a3 | |
parent | 2ee2495486e3266ab0037daad0b1cf220bd254b0 (diff) | |
download | vte-wip/issue-2589.tar.gz |
widget: Add API to get the displayed textwip/issue-2589
https://gitlab.gnome.org/GNOME/vte/-/issues/2589
-rw-r--r-- | src/vte/vteterminal.h | 5 | ||||
-rw-r--r-- | src/vtegtk.cc | 48 |
2 files changed, 53 insertions, 0 deletions
diff --git a/src/vte/vteterminal.h b/src/vte/vteterminal.h index 90aae937..6cacf645 100644 --- a/src/vte/vteterminal.h +++ b/src/vte/vteterminal.h @@ -430,6 +430,11 @@ char* vte_terminal_get_text_range_format(VteTerminal* terminal, gsize* length) _VTE_CXX_NOEXCEPT _VTE_GNUC_NONNULL(1) G_GNUC_MALLOC; _VTE_PUBLIC +char* vte_terminal_get_text_displayed_format(VteTerminal* terminal, + VteFormat format, + gsize* length) _VTE_CXX_NOEXCEPT _VTE_GNUC_NONNULL(1) G_GNUC_MALLOC; + +_VTE_PUBLIC void vte_terminal_get_cursor_position(VteTerminal *terminal, glong *column, glong *row) _VTE_CXX_NOEXCEPT _VTE_GNUC_NONNULL(1); diff --git a/src/vtegtk.cc b/src/vtegtk.cc index 20cac974..61b92a49 100644 --- a/src/vtegtk.cc +++ b/src/vtegtk.cc @@ -4360,6 +4360,54 @@ catch (...) } /** + * vte_terminal_get_text_displayed_format: + * @terminal: a #VteTerminal + * @format: the #VteFormat to use + * @length: (optional) (default 0) (out): a pointer to a #gsize to store the string length + * + * Returns the currently displayed text in the speficied format + * + * Returns: (transfer full) (nullable): a newly allocated string, or %NULL. + * + * Since: 0.72 + */ +char * +vte_terminal_get_text_displayed_format(VteTerminal* terminal, + VteFormat format, + gsize* length) noexcept +try +{ + g_return_val_if_fail(VTE_IS_TERMINAL(terminal), nullptr); + g_return_val_if_fail(check_enum_value(format), nullptr); + + if (length) + *length = 0; + + auto attributes = vte::Freeable<GArray>{}; + if (format == VTE_FORMAT_HTML) + attributes = vte::take_freeable(g_array_new(false, + true, + sizeof(struct _VteCharAttributes))); + + auto const impl = IMPL(terminal); + auto text = vte::take_freeable(impl->get_text_displayed(true, // wrap + attributes.get())); + if (!text) + return nullptr; + + if (format == VTE_FORMAT_HTML) + text = vte::take_freeable(impl->attributes_to_html(text.get(), + attributes.get())); + + return vte::glib::release_to_string(std::move(text), length); +} +catch (...) +{ + vte::log_exception(); + return nullptr; +} + +/** * vte_terminal_get_text_include_trailing_spaces: * @terminal: a #VteTerminal * @is_selected: (scope call) (allow-none): a #VteSelectionFunc callback |