91be3c
diff -up iotop-0.6/iotop/ui.py.git9c49d59 iotop-0.6/iotop/ui.py
91be3c
--- iotop-0.6/iotop/ui.py.git9c49d59	2022-02-15 21:35:33.983889767 +0100
91be3c
+++ iotop-0.6/iotop/ui.py	2022-02-15 21:39:22.508839448 +0100
91be3c
@@ -184,6 +184,12 @@ class IOTopUI(object):
91be3c
         self.sorting_key += delta
91be3c
         self.sorting_key = max(0, self.sorting_key)
91be3c
         self.sorting_key = min(len(IOTopUI.sorting_keys) - 1, self.sorting_key)
91be3c
+        if not self.has_swapin_io:
91be3c
+            if self.sorting_key in (5, 6):
91be3c
+                if delta <= 0:
91be3c
+                    self.sorting_key = 4
91be3c
+                elif delta > 0:
91be3c
+                    self.sorting_key = 7
91be3c
         if orig_sorting_key != self.sorting_key:
91be3c
             self.sorting_reverse = IOTopUI.sorting_keys[self.sorting_key][1]
91be3c
 
91be3c
@@ -377,14 +383,22 @@ class IOTopUI(object):
91be3c
         def format(p):
91be3c
             stats = format_stats(self.options, p, self.process_list.duration)
91be3c
             io_delay, swapin_delay, read_bytes, write_bytes = stats
91be3c
+            format = '%%%dd' % MAX_PID_WIDTH
91be3c
+            params = p.pid,
91be3c
+            format += ' %4s'
91be3c
+            params += p.get_ioprio(),
91be3c
+            format += ' %-8s'
91be3c
+            params += p.get_user()[:8],
91be3c
+            format += ' %11s %11s'
91be3c
+            params += read_bytes, write_bytes
91be3c
             if self.has_swapin_io:
91be3c
-                delay_stats = '%7s %7s ' % (swapin_delay, io_delay)
91be3c
-            else:
91be3c
-                delay_stats = ' ?unavailable?  '
91be3c
-            pid_format = '%%%dd' % MAX_PID_WIDTH
91be3c
-            line = (pid_format + ' %4s %-8s %11s %11s %s') % (
91be3c
-                p.pid, p.get_ioprio(), p.get_user()[:8], read_bytes,
91be3c
-                write_bytes, delay_stats)
91be3c
+                format += ' %7s %7s'
91be3c
+                params += swapin_delay, io_delay
91be3c
+            elif self.options.batch:
91be3c
+                format += ' %s '
91be3c
+                params += '?unavailable?',
91be3c
+            format += ' '
91be3c
+            line = format % (params)
91be3c
             cmdline = p.get_cmdline()
91be3c
             if not self.options.batch:
91be3c
                 remaining_length = self.width - len(line)
91be3c
@@ -439,6 +453,7 @@ class IOTopUI(object):
91be3c
             # and iotop then uses the sysctl value instead.
91be3c
             if sysctl_task_delayacct() == False:
91be3c
                 self.has_swapin_io = False
91be3c
+        self.adjust_sorting_key(0)
91be3c
         lines = self.get_data()
91be3c
         if self.options.time:
91be3c
             titles = ['    TIME'] + titles
91be3c
@@ -462,6 +477,8 @@ class IOTopUI(object):
91be3c
                            self.width)
91be3c
             remaining_cols = self.width
91be3c
             for i in range(len(titles)):
91be3c
+                if not self.has_swapin_io and i in (5, 6):
91be3c
+                    continue
91be3c
                 attr = curses.A_REVERSE
91be3c
                 title = titles[i]
91be3c
                 if i == self.sorting_key: