Convert the log and status portions of the screen to two separate ncurses windows for simpler cleaner output.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
diff --git a/main.c b/main.c
index 1cfc7fc..977288d 100644
--- a/main.c
+++ b/main.c
@@ -518,7 +518,7 @@ static inline int cpu_from_thr_id(int thr_id)
return (thr_id - gpu_threads) % num_processors;
}
-static WINDOW * mainwin;
+static WINDOW *mainwin, *statuswin, *logwin;
static double total_secs = 0.1;
static char statusline[256];
static int cpucursor, gpucursor, logstart, logcursor;
@@ -532,79 +532,63 @@ static inline void print_status(int thr_id)
if (unlikely(!curses_active))
return;
- move(2,0);
- printw("Totals: %s", statusline);
- clrtoeol();
+ wmove(statuswin, 0, 0);
+ wattron(statuswin, A_BOLD);
+ wprintw(statuswin, PROGRAM_NAME " version " VERSION);
+ wattroff(statuswin, A_BOLD);
+ wmove(statuswin, 1, 0);
+ whline(statuswin, '-', 80);
+ wmove(statuswin, 2,0);
+ wprintw(statuswin, "Totals: %s", statusline);
+ wclrtoeol(statuswin);
+ wmove(statuswin, 3, 0);
+ whline(statuswin, '-', 80);
+ wmove(statuswin, logstart - 1, 0);
+ whline(statuswin, '-', 80);
if (thr_id >= 0 && thr_id < gpu_threads) {
int gpu = gpu_from_thr_id(thr_id);
struct cgpu_info *cgpu = &gpus[gpu];
- move(gpucursor + gpu, 0);
- printw("GPU %d: [%.1f Mh/s] [Q:%d A:%d R:%d HW:%d E:%.0f%% U:%.2f/m] ",
+ wmove(statuswin, gpucursor + gpu, 0);
+ wprintw(statuswin, "GPU %d: [%.1f Mh/s] [Q:%d A:%d R:%d HW:%d E:%.0f%% U:%.2f/m]",
gpu, cgpu->total_mhashes / total_secs,
cgpu->getworks, cgpu->accepted, cgpu->rejected, cgpu->hw_errors,
cgpu->efficiency, cgpu->utility);
- clrtoeol();
+ wclrtoeol(statuswin);
} else if (thr_id >= gpu_threads) {
int cpu = cpu_from_thr_id(thr_id);
struct cgpu_info *cgpu = &cpus[cpu];
- move(cpucursor + cpu, 0);
- printw("CPU %d: [%.1f Mh/s] [Q:%d A:%d R:%d HW:%d E:%.0f%% U:%.2f/m]",
+ wmove(statuswin, cpucursor + cpu, 0);
+ wprintw(statuswin, "CPU %d: [%.1f Mh/s] [Q:%d A:%d R:%d HW:%d E:%.0f%% U:%.2f/m]",
cpu, cgpu->total_mhashes / total_secs,
cgpu->getworks, cgpu->accepted, cgpu->rejected, cgpu->hw_errors,
cgpu->efficiency, cgpu->utility);
- clrtoeol();
+ wclrtoeol(statuswin);
}
- move(logcursor, 0);
- refresh();
-}
-
-static void refresh_display(void)
-{
- int i, x;
-
- if (unlikely(!curses_active))
- return;
-
- move(0,0);
- attron(A_BOLD);
- printw(PROGRAM_NAME " version " VERSION);
- attroff(A_BOLD);
- clrtoeol();
- move(1, 0);
- clrtoeol();
- hline('-', 80);
- move(3, 0);
- clrtoeol();
- hline('-', 80);
- move(logstart, 0);
- clrtoeol();
- hline('-', 80);
-
- for (i = 0; i < mining_threads; i++)
- print_status(i);
-
- move(logcursor, 0);
- redrawwin(mainwin);
+ wrefresh(statuswin);
}
void log_curses(const char *f, va_list ap)
{
- int x;
+ int x, y, logx, logy;
if (unlikely(!curses_active))
return;
- /* Scroll log output downwards */
- getmaxyx(mainwin, logcursor, x);
- move(--logcursor, 0);
- vw_printw(mainwin, f, ap);
- clrtoeol();
-
- refresh_display();
+ getmaxyx(mainwin, y, x);
+ getmaxyx(logwin, logy, logx);
+ y -= logcursor;
+ /* Detect screen size change */
+ if (x != logx || y != logy) {
+ wresize(logwin, y, x);
+ redrawwin(logwin);
+ redrawwin(statuswin);
+ }
+ vw_printw(logwin, f, ap);
+ wrefresh(logwin);
}
static bool submit_fail = false;
@@ -1736,7 +1720,7 @@ static void *wakeup_thread(void *userdata)
int main (int argc, char *argv[])
{
struct thr_info *thr;
- unsigned int i, j = 0;
+ unsigned int i, j = 0, x, y;
char name[32];
if (unlikely(pthread_mutex_init(&hash_lock, NULL)))
@@ -1804,7 +1788,7 @@ int main (int argc, char *argv[])
mining_threads = opt_n_threads + gpu_threads;
gpucursor = logcursor;
cpucursor = gpucursor + nDevs;
- logstart = cpucursor + (opt_n_threads ? num_processors : 0);
+ logstart = cpucursor + (opt_n_threads ? num_processors : 0) + 1;
logcursor = logstart + 1;
if (!rpc_userpass) {
@@ -1982,16 +1966,17 @@ int main (int argc, char *argv[])
pthread_mutex_unlock(&hash_lock);
/* Set up the ncurses interface */
- if ((mainwin = initscr()) == NULL) {
- applog(LOG_ERR, "Failed to initscr");
- return 1;
- }
- idlok(mainwin, true);
- scrollok(mainwin, true);
+ mainwin = initscr();
+ statuswin = newwin(logstart, 80, 0, 0);
+ getmaxyx(mainwin, y, x);
+ logwin = newwin(y - logcursor, 0, logcursor, 0);
+ idlok(logwin, true);
+ scrollok(logwin, true);
+ leaveok(logwin, true);
+ leaveok(statuswin, true);
curses_active = true;
- getmaxyx(mainwin, logcursor, i);
- move(logcursor, 0);
- refresh_display();
+ for (i = 0; i < mining_threads; i++)
+ print_status(i);
/* Now that everything's ready put enough work in the queue */
for (i = 0; i < opt_queue + mining_threads; i++) {
@@ -2011,7 +1996,8 @@ int main (int argc, char *argv[])
applog(LOG_INFO, "workio thread dead, exiting.");
- delwin(mainwin);
+ delwin(logwin);
+ delwin(statuswin);
endwin();
refresh();