1# Copyright 2012 - 2013, Steve Rader 2# Copyright 2013 - 2014, Scott Kostyshak 3 4sub draw_header_line { 5 my ($row,$lhs,$rhs) = @_; 6 my $str = ' ' x $COLS; 7 $header_win->addstr($row, 0, $str); 8 $header_win->addstr($row, 0, $lhs); 9 $header_win->addstr($row, $COLS - length($rhs), $rhs); 10 $header_win->refresh(); 11} 12 13#------------------------------------------------------------------ 14 15sub draw_prompt_line { 16 my ($lhs) = @_; 17 $prompt_win->addstr(0, 0, $lhs); 18 $prompt_win->clrtoeol(); 19 $prompt_win->addstr(0, $COLS - length($cursor_position) - 1, $cursor_position); 20 $prompt_win->refresh(); 21} 22 23#------------------------------------------------------------------ 24 25sub draw_prompt { 26 my ($lhs) = @_; 27 $prompt_win->addstr(0, 0, $lhs); 28 $prompt_win->clrtoeol(); 29 $prompt_win->refresh(); 30} 31 32#------------------------------------------------------------------ 33 34sub draw_prompt_cur { 35 my ($lhs) = @_; 36 $prompt_win->addstr(0, 0, $lhs); 37 $prompt_win->clrtoeol(); 38 $prompt_win->move(0, $cur_pos); 39 $prompt_win->refresh(); 40} 41 42#------------------------------------------------------------------ 43 44sub draw_error_msg { 45 beep(); 46 &audit("ERROR $error_msg"); 47 $prompt_win->addstr(0, 0, ' '); 48 $prompt_win->clrtoeol(); 49 $prompt_win->attron(COLOR_PAIR($COLOR_ERRORS)); 50 $prompt_win->attron(A_BOLD); 51 $prompt_win->addstr(0, 0, $error_msg); 52 $prompt_win->attroff(A_BOLD); 53 $prompt_win->attroff(COLOR_PAIR($COLOR_ERRORS)); 54 $prompt_win->attron(COLOR_PAIR($COLOR_HEADER)); 55 $prompt_win->addstr(0, $COLS - length($cursor_position) - 1, $cursor_position); 56 $prompt_win->refresh(); 57} 58 59#------------------------------------------------------------------ 60 61sub draw_feedback_msg { 62 my $len = length($feedback_msg); 63 my $start = ($COLS/2) - ($len/2) - 3; 64 $prompt_win->addstr(0, 0, ' '); 65 $prompt_win->clrtoeol(); 66 $prompt_win->addstr(0, $start, $feedback_msg); 67 $prompt_win->addstr(0, $COLS - length($cursor_position) - 1, $cursor_position); 68 $prompt_win->refresh(); 69} 70 71#------------------------------------------------------------------ 72 73sub draw_report_line { 74 my ($i,$line,$mode) = @_; 75 my ($x, $t, $cp, $str); 76 $x = 0; 77 if ( $mode eq 'with-selection' && $i == $task_selected_idx ) { 78 $report_win->attron(COLOR_PAIR($COLOR_SELECTION)); 79 &set_attron($report_win,$selection_attrs); 80 } 81 for $t (0 .. $#{ $report_tokens[$i] } ) { 82 if ( $mode eq 'without-selection' || $i != $task_selected_idx ) { 83 my $fg = $report_colors_fg[$i][$t]; 84 my $bg = $report_colors_bg[$i][$t]; 85 $cp = &get_color_pair($fg,$bg); 86 $report_win->attron(COLOR_PAIR($cp)); 87 } 88 #if ( $t == 0 ) { debug("DRAW tok=$line.$t cp=$cp \"$report_tokens[$i][$t]\""); } 89 &set_attron($report_win,$report_attrs[$i][$t]); 90 $report_win->addstr($line,$x,$report_tokens[$i][$t]); 91 &set_attroff($report_win,$report_attrs[$i][$t]); 92 if ( $mode eq 'without-selection' || $i != $task_selected_idx ) { 93 $report_win->attroff(COLOR_PAIR($cp)); 94 } 95 $x += length($report_tokens[$i][$t]); 96 } 97 $str = ' ' x ($REPORT_COLS - $x); 98 if ( $mode eq 'without-selection' || $i != $task_selected_idx ) { 99 $report_win->attron(COLOR_PAIR($cp)); 100 } 101 &set_attron($report_win,$report_attrs[$i][$#{ $report_tokens[$i] }]); 102 $report_win->addstr($line,$x,$str); 103 &set_attroff($report_win,$report_attrs[$i][$#{ $report_tokens[$i] }]); 104 if ( $mode eq 'with-selection' && $i == $task_selected_idx ) { 105 $report_win->attroff(COLOR_PAIR($COLOR_SELECTION)); 106 &set_attroff($report_win,$selection_attrs); 107 } else { 108 $report_win->attroff(COLOR_PAIR($cp)); 109 } 110} 111 112#------------------------------------------------------------------ 113 114sub flash_current_task { 115 my ($x, $t, $cp, $str); 116 my $i = $task_selected_idx; 117 my $line = $task_selected_idx - $display_start_idx; 118 119 &draw_report_line($i,$line,'without-selection'); 120 $report_win->refresh(); 121 usleep($flash_delay); 122 123 $report_win->addstr($line,0,' '); 124 $report_win->clrtoeol(); 125 $report_win->refresh(); 126 usleep($flash_delay); 127 128 &draw_report_line($i,$line,'without-selection'); 129 $report_win->refresh(); 130 usleep($flash_delay); 131 132 $report_win->addstr($line,0,' '); 133 $report_win->clrtoeol(); 134 $report_win->refresh(); 135 usleep($flash_delay); 136 137 &draw_report_line($i,$line,'without-selection'); 138 $report_win->refresh(); 139 usleep($flash_delay); 140} 141 142#------------------------------------------------------------------ 143 144sub flash_convergence { 145 $header_win->attron(COLOR_PAIR($COLOR_HEADER)); 146 &set_attron($header_win,$header_attrs); 147 &draw_header_line(1,'',"$tasks_completed tasks completed"); 148 usleep($flash_delay); 149 &draw_header_line(1,$convergence,"$tasks_completed tasks completed"); 150 usleep($flash_delay); 151 &draw_header_line(1,'',"$tasks_completed tasks completed"); 152 usleep($flash_delay); 153 &draw_header_line(1,$convergence,"$tasks_completed tasks completed"); 154 usleep($flash_delay); 155 &set_attroff($header_win,$header_attrs); 156 $header_win->attroff(COLOR_PAIR($COLOR_HEADER)); 157} 158 159#------------------------------------------------------------------ 160 161sub set_attron { 162 my ($win,$attr) = @_; 163 if ( ! defined $attr ) { return; } 164 if ( $attr =~ /underline/ ) { 165 $win->attron(A_UNDERLINE); 166 } 167 if ( $attr =~ /bold/ ) { 168 $win->attron(A_BOLD); 169 } 170} 171 172#------------------------------------------------------------------ 173 174sub set_attroff { 175 my ($win,$attr) = @_; 176 if ( ! defined $attr ) { return; } 177 if ( $attr =~ /underline/ ) { 178 $win->attroff(A_UNDERLINE); 179 } 180 if ( $attr =~ /bold/ ) { 181 $win->attroff(A_BOLD); 182 } 183 if ( $attr =~ /inverse/ ) { 184 $win->attroff(A_REVERSE); 185 } 186 if ( $attr =~ /standout/ ) { 187 $win->attroff(A_STANDOUT); 188 } 189} 190 191return 1; 192