From 2f2287318b33ddf855a692fcc191f6b25caf4644 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 16 Dec 2020 18:18:40 +0100 Subject: [gdb/cli] Add a progress meter Add a progress meter. It's not used anywhere yet. gdb/ChangeLog: 2020-12-16 Tom Tromey Tom Tromey Tom de Vries * utils.h (get_chars_per_line): Declare. * utils.c (get_chars_per_line): New function. (fputs_maybe_filtered): Handle '\r'. * ui-out.h (ui_out::progress_meter): New class. (ui_out::progress, ui_out::do_progress_start) (ui_out::do_progress_notify, ui_out::do_progress_end): New methods. * ui-out.c (do_progress_end) (make_cleanup_ui_out_progress_begin_end, ui_out_progress): New functions. * mi/mi-out.h (mi_ui_out::do_progress_start) (mi_ui_out::do_progress_notify, mi_ui_out::do_progress_end): New methods. * cli-out.h (struct cli_ui_out) : New methods. : New. : New member. * cli-out.c (cli_ui_out::do_progress_start) (cli_ui_out::do_progress_notify, cli_ui_out::do_progress_end): New methods. --- gdb/ui-out.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'gdb/ui-out.h') diff --git a/gdb/ui-out.h b/gdb/ui-out.h index 9fc6061..dfd9679 100644 --- a/gdb/ui-out.h +++ b/gdb/ui-out.h @@ -275,6 +275,39 @@ class ui_out escapes. */ virtual bool can_emit_style_escape () const = 0; + /* An object that starts and finishes a progress meter. */ + class progress_meter + { + public: + /* SHOULD_PRINT indicates whether something should be printed for a tty. */ + progress_meter (struct ui_out *uiout, const std::string &name, + bool should_print) + : m_uiout (uiout) + { + m_uiout->do_progress_start (name, should_print); + } + + ~progress_meter () + { + m_uiout->do_progress_notify (1.0); + m_uiout->do_progress_end (); + } + + progress_meter (const progress_meter &) = delete; + progress_meter &operator= (const progress_meter &) = delete; + + private: + + struct ui_out *m_uiout; + }; + + /* Emit some progress corresponding to the most recently created + progress meter. HOWMUCH may range from 0.0 to 1.0. */ + void progress (double howmuch) + { + do_progress_notify (howmuch); + } + protected: virtual void do_table_begin (int nbrofcols, int nr_rows, const char *tblid) @@ -309,6 +342,10 @@ class ui_out virtual void do_flush () = 0; virtual void do_redirect (struct ui_file *outstream) = 0; + virtual void do_progress_start (const std::string &, bool) = 0; + virtual void do_progress_notify (double) = 0; + virtual void do_progress_end () = 0; + /* Set as not MI-like by default. It is overridden in subclasses if necessary. */ -- cgit v1.1