Browse Source

create windows in separate function; flush key buffer where needed

The curses windows are now created in create_windows which can
later be called from the signal handler for screen resizes.
This means it is possible to change the screen size while
the program is running, but it's still necessary to perform
an action which redraws the screen (such as entering the menu)
in order to make it work. Implementing a full automatic refresh
during resizing the window doesn't seem worth the effort.

Use flushinp() (flush keyboard input buffer) where appropriate,
e.g. when scrolling (scrolling may be slow due to database
fetches, and once the user stops pressing the Page Up/Dwn key
there should be no further scrolling) or when waiting for
operations that take some time to finish, like ADIF export
or up/downloading LoTW data to prevent that an user's impatient
key strokes cause him to miss the display with the results,
but jumps right back to the menu.
master
Fabian Kurz 4 years ago
parent
commit
c19507f8fb
  1. 42
      yfk
  2. 47
      yfksubs.pl

42
yfk

@ -209,34 +209,9 @@ init_pair(7, COLOR_BLACK, COLOR_WHITE);
}
# GENERAL WINDOWS, always visible
our $whead = &makewindow(1,80,0,0,2); # head window
our $whelp = &makewindow(1,80,$row-1,0,2); # help window
# LOGGING MODE WINDOWS ($status = 1)
our $winput = &makewindow(3,80,1,0,1); # Input Window
our $winfo = &makewindow(3,80,4,0,2); # DXCC/Info Window
# depending on $screenlayout, the windows for previous QSOs and the recent
# logbook are either next to each other or on top of each other.
our ($wlog, $wqsos);
if ($screenlayout==0) { # original YFKlog style
$wlog = &makewindow(16,30,7,0,3); # Logbook
$wqsos = &makewindow(16,50,7,30,4); # prev. QSOs window
}
elsif ($screenlayout==1) { # more info, smaller windows
# 8 lines are used for other stuff, so we have ($row-8)/2 lines left for
# each window
$wlog = &makewindow(($row-8)/2,80,7,0,3); # Logbook
$wqsos = &makewindow(($row-8)/2,80,7+($row-8)/2,0,4); # prev. QSOs window
}
# EDIT / SEARCH MODE WINDOWS ($status = 10)
our $wedit = &makewindow(5,80,1,0,1); # Edit Window
our $weditlog = &makewindow(($row-7),80,6,0,4); # Search results
our ($whead, $whelp, $winput, $winfo, $wlog, $wqsos, $wedit, $weditlog, $wmain);
# build logging windows (see yfksubs.pl)
&create_windows();
# Inside the input-window, the input fields will also be defined as single
# windows, so it will be easy to fill them with data. These are stored in the
@ -276,10 +251,6 @@ $wi[24] = &makewindow(1,6,5,39,5); # Edit Window: OPERATOR
$wi[25] = &makewindow(1,6,5,53,5); # Edit Window: GRID
my $wi = \@wi; # Window reference
# GENERAL purpose Window all over the screen, except top and bottom lines
my $wmain = &makewindow($row-2,80,1,0,4); # Input Window
##############################################################################
# MAIN PROGRAM LOOP
# This is the outer loop of the program. Depending on $status, it choses
@ -1238,6 +1209,10 @@ while (($status == 7) || ($status == 14)) {
$nr = &adifexport($filename, 'adif', $daterange) if ($status == 7);
$nr = &adifexport($filename, 'lotw', $daterange) if ($status == 14);
# if the user was impatient and pressed enter, he will not see the
# following screen, so flush the input buffer
flushinp();
addstr($wmain,0,0, ' ' x (80*($row-2))); # clear main window
addstr($wmain,10,10,"$nr QSOs exported to $filename");
@ -1293,6 +1268,7 @@ while (($status == 7) || ($status == 14)) {
}
refresh($wmain);
flushinp();
getch();
$status = 2;
@ -1925,6 +1901,8 @@ while ($status == 13) {
next;
}
flushinp();
}
else {
curs_set(1);

47
yfksubs.pl

@ -34,7 +34,7 @@ changemycall newlogtable oldlogtable choseeditqso geteditqso editw updateqso che
awards statistics qslstatistics editdb editdbw savedbedit lotwimport
databaseupgrade xplanet queryrig tableexists changeconfig readsubconfig
connectdb connectrig jumpfield receive_qso tqslsign getlotwlocations
getlotwstartdate downloadlotw redraw);
getlotwstartdate downloadlotw redraw create_windows);
use strict;
use POSIX; # needed for acos in distance/direction calculation
@ -110,8 +110,47 @@ sub redraw {
endwin();
initscr();
getmaxyx($main::row, $main::col);
$main::row-- if ($main::row % 2);
&create_windows();
}
sub create_windows {
my $row = $main::row;
# GENERAL WINDOWS, always visible
$main::whead = &makewindow(1,80,0,0,2); # head window
$main::whelp = &makewindow(1,80,$row-1,0,2); # help window
# LOGGING MODE WINDOWS ($status = 1)
$main::winput = &makewindow(3,80,1,0,1); # Input Window
$main::winfo = &makewindow(3,80,4,0,2); # DXCC/Info Window
# depending on $screenlayout, the windows for previous QSOs and the recent
# logbook are either next to each other or on top of each other.
if ($screenlayout==0) { # original YFKlog style
$main::wlog = &makewindow(16,30,7,0,3); # Logbook
$main::wqsos = &makewindow(16,50,7,30,4); # prev. QSOs window
}
elsif ($screenlayout==1) { # more info, smaller windows
# 8 lines are used for other stuff, so we have ($row-8)/2 lines left for
# each window
$main::wlog = &makewindow(($row-8)/2,80,7,0,3); # Logbook
$main::wqsos = &makewindow(($row-8)/2,80,7+($row-8)/2,0,4); # prev. QSOs window
}
# EDIT / SEARCH MODE WINDOWS ($status = 10)
$main::wedit = &makewindow(5,80,1,0,1); # Edit Window
$main::weditlog = &makewindow(($row-7),80,6,0,4); # Search results
$main::wmain = &makewindow($row-2,80,1,0,4); # Input Window
}
# We read the configuration file .yfklog.
sub readsubconfig {
@ -1809,11 +1848,13 @@ do { # loop and get keyboard input
if (($ch eq KEY_NPAGE) && ($offset != 0)) { # scroll down 16/8 QSOs
$aline = 0; # first line
$offset -= $nbr; # next 16/8 QSOs
flushinp(); # avoid excessive scrolling
}
elsif (($ch eq KEY_PPAGE) && $callsthispage>7) {# scroll up 16/8 QSOs
$aline = ($nbr-1); # last line
$offset += $nbr; # prev 8/16 QSOs
flushinp(); # avoid excessive scrolling
}
elsif ($ch eq KEY_F(1)) { # go to the MAIN MENU
@ -2591,12 +2632,14 @@ do { # we start looping here
elsif (($ch eq KEY_NPAGE) && ($offset+$yh < $count)) {
$offset += ($yh-1); # adjust offset
$aline = 0; # Start again at the first line
flushinp();
}
# Same with UP. We can scroll up when $offset > 0
elsif (($ch eq KEY_PPAGE) && ($offset > 0)) {
$offset -= ($yh-1); # adjust offset
$aline = ($yh-1); # Start again at the last line
flushinp();
}
# F1 => Back to the main menu. Return 2 for Status.
@ -4029,6 +4072,7 @@ do {
$$pos += ($nlines - $aline); # consider $aline!
$aline=0;
}
flushinp();
}
elsif ($ch eq KEY_PPAGE) { # scroll a full page up
@ -4038,6 +4082,7 @@ do {
$$pos -= ($aline+1); # consider $aline!
$aline=$nlines-1;
}
flushinp();
}
elsif ($ch eq KEY_HOME) { # go to first qso

Loading…
Cancel
Save