Merge pull request #1025 from stefanrueger/terminal

Fix terminal write edge cases; add one read mode and add quell command
This commit is contained in:
Stefan Rueger 2022-07-18 14:30:45 +01:00 committed by GitHub
commit 494199fa78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 694 additions and 339 deletions

View File

@ -135,72 +135,6 @@ static void usage(void)
} }
static void update_progress_tty (int percent, double etime, char *hdr)
{
static char hashes[51];
static char *header;
static int last = 0;
int i;
setvbuf(stderr, (char*)NULL, _IONBF, 0);
hashes[50] = 0;
memset (hashes, ' ', 50);
for (i=0; i<percent; i+=2) {
hashes[i/2] = '#';
}
if (hdr) {
avrdude_message(MSG_INFO, "\n");
last = 0;
header = hdr;
}
if (last == 0) {
avrdude_message(MSG_INFO, "\r%s | %s | %d%% %0.2fs",
header, hashes, percent, etime);
}
if (percent == 100) {
if (!last) avrdude_message(MSG_INFO, "\n\n");
last = 1;
}
setvbuf(stderr, (char*)NULL, _IOLBF, 0);
}
static void update_progress_no_tty (int percent, double etime, char *hdr)
{
static int done = 0;
static int last = 0;
int cnt = (percent>>1)*2;
setvbuf(stderr, (char*)NULL, _IONBF, 0);
if (hdr) {
avrdude_message(MSG_INFO, "\n%s | ", hdr);
last = 0;
done = 0;
}
else {
while ((cnt > last) && (done == 0)) {
avrdude_message(MSG_INFO, "#");
cnt -= 2;
}
}
if ((percent == 100) && (done == 0)) {
avrdude_message(MSG_INFO, " | 100%% %0.2fs\n\n", etime);
last = 0;
done = 1;
}
else
last = (percent>>1)*2; /* Make last a multiple of 2. */
setvbuf(stderr, (char*)NULL, _IOLBF, 0);
}
static void list_programmers_callback(const char *name, const char *desc, static void list_programmers_callback(const char *name, const char *desc,
const char *cfgname, int cfglineno, const char *cfgname, int cfglineno,
void *cookie) void *cookie)
@ -760,18 +694,8 @@ int main(int argc, char * argv [])
} }
#endif #endif
if (quell_progress == 0) { if (quell_progress == 0)
if (isatty (STDERR_FILENO)) terminal_setup_update_progress();
update_progress = update_progress_tty;
else {
update_progress = update_progress_no_tty;
/* disable all buffering of stderr for compatibility with
software that captures and redirects output to a GUI
i.e. Programmers Notepad */
setvbuf( stderr, NULL, _IONBF, 0 );
setvbuf( stdout, NULL, _IONBF, 0 );
}
}
/* /*
* Print out an identifying string so folks can tell what version * Print out an identifying string so folks can tell what version

File diff suppressed because it is too large Load Diff

View File

@ -34,6 +34,8 @@ typedef enum {
int terminal_mode(PROGRAMMER * pgm, struct avrpart * p); int terminal_mode(PROGRAMMER * pgm, struct avrpart * p);
char * terminal_get_input(const char *prompt); char * terminal_get_input(const char *prompt);
void terminal_setup_update_progress();
int terminal_message(const int msglvl, const char *format, ...);
#ifdef __cplusplus #ifdef __cplusplus
} }