aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes2015-05-06 14:40:05 -0500
committerElliott Hughes2015-05-06 23:17:05 -0500
commitc049163234003ef463bca018920622bc8269c69b (patch)
treed2a34c360eab7268e2642857367cc4bac8dce6b8 /screen_ui.cpp
parentaeb980bd8958e3c6e135835aa7d34b5c4e3a601b (diff)
downloadplatform-bootable-recovery-c049163234003ef463bca018920622bc8269c69b.tar.gz
platform-bootable-recovery-c049163234003ef463bca018920622bc8269c69b.tar.xz
platform-bootable-recovery-c049163234003ef463bca018920622bc8269c69b.zip
Add an alternate screen for viewing recovery logs.
This makes it easier to go back and forth without losing current output. Also make the display more like regular more(1). Bug: http://b/20834540 Change-Id: Icc5703e9c8a378cc7072d8ebb79e34451267ee1b
Diffstat (limited to 'screen_ui.cpp')
-rw-r--r--screen_ui.cpp110
1 files changed, 64 insertions, 46 deletions
diff --git a/screen_ui.cpp b/screen_ui.cpp
index 5e73d37c..ff959151 100644
--- a/screen_ui.cpp
+++ b/screen_ui.cpp
@@ -58,18 +58,19 @@ ScreenRecoveryUI::ScreenRecoveryUI() :
58 progressScopeSize(0), 58 progressScopeSize(0),
59 progress(0), 59 progress(0),
60 pagesIdentical(false), 60 pagesIdentical(false),
61 text(nullptr), 61 text_cols_(0),
62 text_cols(0), 62 text_rows_(0),
63 text_rows(0), 63 text_(nullptr),
64 text_col(0), 64 text_col_(0),
65 text_row(0), 65 text_row_(0),
66 text_top(0), 66 text_top_(0),
67 show_text(false), 67 show_text(false),
68 show_text_ever(false), 68 show_text_ever(false),
69 menu(nullptr), 69 menu_(nullptr),
70 show_menu(false), 70 show_menu(false),
71 menu_items(0), 71 menu_items(0),
72 menu_sel(0), 72 menu_sel(0),
73 file_viewer_text_(nullptr),
73 animation_fps(20), 74 animation_fps(20),
74 installing_frames(-1), 75 installing_frames(-1),
75 stage(-1), 76 stage(-1),
@@ -255,7 +256,7 @@ void ScreenRecoveryUI::draw_screen_locked() {
255 DrawTextLines(&y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP); 256 DrawTextLines(&y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP);
256 257
257 SetColor(HEADER); 258 SetColor(HEADER);
258 DrawTextLines(&y, menu_headers); 259 DrawTextLines(&y, menu_headers_);
259 260
260 SetColor(MENU); 261 SetColor(MENU);
261 DrawHorizontalRule(&y); 262 DrawHorizontalRule(&y);
@@ -267,10 +268,10 @@ void ScreenRecoveryUI::draw_screen_locked() {
267 gr_fill(0, y - 2, gr_fb_width(), y + char_height + 2); 268 gr_fill(0, y - 2, gr_fb_width(), y + char_height + 2);
268 // Bold white text for the selected item. 269 // Bold white text for the selected item.
269 SetColor(MENU_SEL_FG); 270 SetColor(MENU_SEL_FG);
270 gr_text(4, y, menu[i], true); 271 gr_text(4, y, menu_[i], true);
271 SetColor(MENU); 272 SetColor(MENU);
272 } else { 273 } else {
273 gr_text(4, y, menu[i], false); 274 gr_text(4, y, menu_[i], false);
274 } 275 }
275 y += char_height + 4; 276 y += char_height + 4;
276 } 277 }
@@ -281,14 +282,14 @@ void ScreenRecoveryUI::draw_screen_locked() {
281 // screen, the bottom of the menu, or we've displayed the 282 // screen, the bottom of the menu, or we've displayed the
282 // entire text buffer. 283 // entire text buffer.
283 SetColor(LOG); 284 SetColor(LOG);
284 int row = (text_top+text_rows-1) % text_rows; 285 int row = (text_top_ + text_rows_ - 1) % text_rows_;
285 size_t count = 0; 286 size_t count = 0;
286 for (int ty = gr_fb_height() - char_height; 287 for (int ty = gr_fb_height() - char_height;
287 ty >= y && count < text_rows; 288 ty >= y && count < text_rows_;
288 ty -= char_height, ++count) { 289 ty -= char_height, ++count) {
289 gr_text(0, ty, text[row], false); 290 gr_text(0, ty, text_[row], false);
290 --row; 291 --row;
291 if (row < 0) row = text_rows-1; 292 if (row < 0) row = text_rows_ - 1;
292 } 293 }
293 } 294 }
294} 295}
@@ -391,14 +392,15 @@ void ScreenRecoveryUI::Init() {
391 gr_init(); 392 gr_init();
392 393
393 gr_font_size(&char_width, &char_height); 394 gr_font_size(&char_width, &char_height);
394 text_rows = gr_fb_height() / char_height; 395 text_rows_ = gr_fb_height() / char_height;
395 text_cols = gr_fb_width() / char_width; 396 text_cols_ = gr_fb_width() / char_width;
396 397
397 text = Alloc2d(text_rows, text_cols + 1); 398 text_ = Alloc2d(text_rows_, text_cols_ + 1);
398 menu = Alloc2d(text_rows, text_cols + 1); 399 file_viewer_text_ = Alloc2d(text_rows_, text_cols_ + 1);
400 menu_ = Alloc2d(text_rows_, text_cols_ + 1);
399 401
400 text_col = text_row = 0; 402 text_col_ = text_row_ = 0;
401 text_top = 1; 403 text_top_ = 1;
402 404
403 backgroundIcon[NONE] = nullptr; 405 backgroundIcon[NONE] = nullptr;
404 LoadBitmapArray("icon_installing", &installing_frames, &installation); 406 LoadBitmapArray("icon_installing", &installing_frames, &installation);
@@ -514,17 +516,17 @@ void ScreenRecoveryUI::Print(const char *fmt, ...) {
514 fputs(buf, stdout); 516 fputs(buf, stdout);
515 517
516 pthread_mutex_lock(&updateMutex); 518 pthread_mutex_lock(&updateMutex);
517 if (text_rows > 0 && text_cols > 0) { 519 if (text_rows_ > 0 && text_cols_ > 0) {
518 for (const char* ptr = buf; *ptr != '\0'; ++ptr) { 520 for (const char* ptr = buf; *ptr != '\0'; ++ptr) {
519 if (*ptr == '\n' || text_col >= text_cols) { 521 if (*ptr == '\n' || text_col_ >= text_cols_) {
520 text[text_row][text_col] = '\0'; 522 text_[text_row_][text_col_] = '\0';
521 text_col = 0; 523 text_col_ = 0;
522 text_row = (text_row + 1) % text_rows; 524 text_row_ = (text_row_ + 1) % text_rows_;
523 if (text_row == text_top) text_top = (text_top + 1) % text_rows; 525 if (text_row_ == text_top_) text_top_ = (text_top_ + 1) % text_rows_;
524 } 526 }
525 if (*ptr != '\n') text[text_row][text_col++] = *ptr; 527 if (*ptr != '\n') text_[text_row_][text_col_++] = *ptr;
526 } 528 }
527 text[text_row][text_col] = '\0'; 529 text_[text_row_][text_col_] = '\0';
528 update_screen_locked(); 530 update_screen_locked();
529 } 531 }
530 pthread_mutex_unlock(&updateMutex); 532 pthread_mutex_unlock(&updateMutex);
@@ -532,21 +534,23 @@ void ScreenRecoveryUI::Print(const char *fmt, ...) {
532 534
533void ScreenRecoveryUI::PutChar(char ch) { 535void ScreenRecoveryUI::PutChar(char ch) {
534 pthread_mutex_lock(&updateMutex); 536 pthread_mutex_lock(&updateMutex);
535 if (ch != '\n') text[text_row][text_col++] = ch; 537 if (ch != '\n') text_[text_row_][text_col_++] = ch;
536 if (ch == '\n' || text_col >= text_cols) { 538 if (ch == '\n' || text_col_ >= text_cols_) {
537 text_col = 0; 539 text_col_ = 0;
538 ++text_row; 540 ++text_row_;
541
542 if (text_row_ == text_top_) text_top_ = (text_top_ + 1) % text_rows_;
539 } 543 }
540 pthread_mutex_unlock(&updateMutex); 544 pthread_mutex_unlock(&updateMutex);
541} 545}
542 546
543void ScreenRecoveryUI::ClearText() { 547void ScreenRecoveryUI::ClearText() {
544 pthread_mutex_lock(&updateMutex); 548 pthread_mutex_lock(&updateMutex);
545 text_col = 0; 549 text_col_ = 0;
546 text_row = 0; 550 text_row_ = 0;
547 text_top = 1; 551 text_top_ = 1;
548 for (size_t i = 0; i < text_rows; ++i) { 552 for (size_t i = 0; i < text_rows_; ++i) {
549 memset(text[i], 0, text_cols + 1); 553 memset(text_[i], 0, text_cols_ + 1);
550 } 554 }
551 pthread_mutex_unlock(&updateMutex); 555 pthread_mutex_unlock(&updateMutex);
552} 556}
@@ -590,12 +594,11 @@ void ScreenRecoveryUI::ShowFile(FILE* fp) {
590 594
591 int ch = getc(fp); 595 int ch = getc(fp);
592 if (ch == EOF) { 596 if (ch == EOF) {
593 text_row = text_top = text_rows - 2; 597 while (text_row_ < text_rows_ - 1) PutChar('\n');
594 show_prompt = true; 598 show_prompt = true;
595 } else { 599 } else {
596 PutChar(ch); 600 PutChar(ch);
597 if (text_col == 0 && text_row >= text_rows - 2) { 601 if (text_col_ == 0 && text_row_ >= text_rows_ - 1) {
598 text_top = text_row;
599 show_prompt = true; 602 show_prompt = true;
600 } 603 }
601 } 604 }
@@ -608,19 +611,34 @@ void ScreenRecoveryUI::ShowFile(const char* filename) {
608 Print(" Unable to open %s: %s\n", filename, strerror(errno)); 611 Print(" Unable to open %s: %s\n", filename, strerror(errno));
609 return; 612 return;
610 } 613 }
614
615 char** old_text = text_;
616 size_t old_text_col = text_col_;
617 size_t old_text_row = text_row_;
618 size_t old_text_top = text_top_;
619
620 // Swap in the alternate screen and clear it.
621 text_ = file_viewer_text_;
622 ClearText();
623
611 ShowFile(fp); 624 ShowFile(fp);
612 fclose(fp); 625 fclose(fp);
626
627 text_ = old_text;
628 text_col_ = old_text_col;
629 text_row_ = old_text_row;
630 text_top_ = old_text_top;
613} 631}
614 632
615void ScreenRecoveryUI::StartMenu(const char* const * headers, const char* const * items, 633void ScreenRecoveryUI::StartMenu(const char* const * headers, const char* const * items,
616 int initial_selection) { 634 int initial_selection) {
617 pthread_mutex_lock(&updateMutex); 635 pthread_mutex_lock(&updateMutex);
618 if (text_rows > 0 && text_cols > 0) { 636 if (text_rows_ > 0 && text_cols_ > 0) {
619 menu_headers = headers; 637 menu_headers_ = headers;
620 size_t i = 0; 638 size_t i = 0;
621 for (; i < text_rows && items[i] != nullptr; ++i) { 639 for (; i < text_rows_ && items[i] != nullptr; ++i) {
622 strncpy(menu[i], items[i], text_cols-1); 640 strncpy(menu_[i], items[i], text_cols_ - 1);
623 menu[i][text_cols-1] = '\0'; 641 menu_[i][text_cols_ - 1] = '\0';
624 } 642 }
625 menu_items = i; 643 menu_items = i;
626 show_menu = true; 644 show_menu = true;
@@ -649,7 +667,7 @@ int ScreenRecoveryUI::SelectMenu(int sel) {
649 667
650void ScreenRecoveryUI::EndMenu() { 668void ScreenRecoveryUI::EndMenu() {
651 pthread_mutex_lock(&updateMutex); 669 pthread_mutex_lock(&updateMutex);
652 if (show_menu && text_rows > 0 && text_cols > 0) { 670 if (show_menu && text_rows_ > 0 && text_cols_ > 0) {
653 show_menu = false; 671 show_menu = false;
654 update_screen_locked(); 672 update_screen_locked();
655 } 673 }