summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cmdline/mocks/transient_message.h1
-rw-r--r--src/cmdline/transient_message.cc20
-rw-r--r--src/cmdline/transient_message.h6
-rw-r--r--src/generic/views/download_progress.h1
-rw-r--r--tests/test_transient_message.cc46
5 files changed, 74 insertions, 0 deletions
diff --git a/src/cmdline/mocks/transient_message.h b/src/cmdline/mocks/transient_message.h
index efc18539..5ab90ca8 100644
--- a/src/cmdline/mocks/transient_message.h
+++ b/src/cmdline/mocks/transient_message.h
@@ -38,6 +38,7 @@ namespace aptitude
public:
MOCK_METHOD1(set_text, void(const std::wstring &));
MOCK_METHOD0(preserve_and_advance, void());
+ MOCK_METHOD1(display_and_advance, void(const std::wstring &));
};
}
}
diff --git a/src/cmdline/transient_message.cc b/src/cmdline/transient_message.cc
index 34949233..96019c82 100644
--- a/src/cmdline/transient_message.cc
+++ b/src/cmdline/transient_message.cc
@@ -59,6 +59,15 @@ namespace aptitude
void preserve_and_advance()
{
}
+
+ void display_and_advance(const std::wstring &msg)
+ {
+ // I could generate output here, but the messages passed to
+ // display_and_advance might be inappropriate for
+ // non-terminal output; this layer of the code doesn't have
+ // the necessary information to decide whether they should
+ // be displayed.
+ }
};
class transient_message_impl : public transient_message
@@ -90,6 +99,7 @@ namespace aptitude
void set_text(const std::wstring &line);
void preserve_and_advance();
+ void display_and_advance(const std::wstring &line);
};
@@ -158,6 +168,16 @@ namespace aptitude
term->write_text(L"\n");
term->flush();
}
+
+ void transient_message_impl::display_and_advance(const std::wstring &msg)
+ {
+ clear_last_line();
+ term->write_text(msg);
+ term->write_text(L"\n");
+
+ last_line_len = 0;
+ last_line.clear();
+ }
}
shared_ptr<transient_message>
diff --git a/src/cmdline/transient_message.h b/src/cmdline/transient_message.h
index 2055d965..b8e24fb7 100644
--- a/src/cmdline/transient_message.h
+++ b/src/cmdline/transient_message.h
@@ -46,6 +46,12 @@ namespace aptitude
* line.
*/
virtual void preserve_and_advance() = 0;
+
+ /** \brief Replace the currently displayed text with the given
+ * message, which will not be clipped if it exceeds the terminal
+ * width, and advance to the next line.
+ */
+ virtual void display_and_advance(const std::wstring &text) = 0;
};
class terminal;
diff --git a/src/generic/views/download_progress.h b/src/generic/views/download_progress.h
index 020ad59e..d6266ebc 100644
--- a/src/generic/views/download_progress.h
+++ b/src/generic/views/download_progress.h
@@ -22,6 +22,7 @@
// System includes:
#include <boost/optional.hpp>
+#include <boost/variant.hpp>
#include <sigc++/slot.h>
diff --git a/tests/test_transient_message.cc b/tests/test_transient_message.cc
index dd7fccf4..d1b574b5 100644
--- a/tests/test_transient_message.cc
+++ b/tests/test_transient_message.cc
@@ -36,6 +36,7 @@ using aptitude::cmdline::transient_message;
using boost::shared_ptr;
using testing::InSequence;
using testing::Return;
+using testing::StrEq;
using testing::Test;
using testing::_;
@@ -106,6 +107,51 @@ TEST_F(TransientMessage, PreserveAndAdvance)
message->preserve_and_advance();
}
+TEST_F(TransientMessage, DisplayAndAdvanceBasic)
+{
+ {
+ InSequence dummy;
+
+ EXPECT_CALL(*teletype, set_last_line(StrEq(L"abcdefghi")));
+ EXPECT_CALL(*teletype, newline());
+ }
+
+ message->display_and_advance(L"abcdefghi");
+}
+
+TEST_F(TransientMessage, DisplayAndAdvanceWrapping)
+{
+ EXPECT_CALL(*term, get_screen_width())
+ .WillRepeatedly(Return(4));
+
+ {
+ InSequence dummy;
+
+ EXPECT_CALL(*teletype, set_last_line(StrEq(L"abcd")));
+ EXPECT_CALL(*teletype, newline());
+ EXPECT_CALL(*teletype, set_last_line(StrEq(L"efgh")));
+ EXPECT_CALL(*teletype, newline());
+ EXPECT_CALL(*teletype, set_last_line(StrEq(L"ij")));
+ EXPECT_CALL(*teletype, newline());
+ }
+
+ message->display_and_advance(L"abcdefghij");
+}
+
+TEST_F(TransientMessage, DisplayAndAdvanceClearsExistingText)
+{
+ {
+ InSequence dummy;
+
+ EXPECT_CALL(*teletype, set_last_line(StrTrimmedRightEq(L"xyzw")));
+ EXPECT_CALL(*teletype, set_last_line(StrEq(L"abcd")));
+ EXPECT_CALL(*teletype, newline());
+ }
+
+ message->set_text(L"xyzw");
+ message->display_and_advance(L"abcd");
+}
+
TEST_F(TransientMessage, ClearText)
{
{