From 0b355bc704f873f7fff8a965e14aabebdeb695a5 Mon Sep 17 00:00:00 2001
From: Daniele Verducci su MatissePenguin <daniele.verducci@gmail.com>
Date: Tue, 15 Dec 2020 18:14:29 +0100
Subject: [PATCH] Terminal emu: restoring cursor position after ADB

---
 python/terminal_emulator.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/python/terminal_emulator.py b/python/terminal_emulator.py
index 3e34609..433c53c 100755
--- a/python/terminal_emulator.py
+++ b/python/terminal_emulator.py
@@ -39,18 +39,22 @@ class TerminalEmulator:
                 b = ser.read(1)
                 if ord(b) > 31 or ord(b) == 10:
                     w.addch(b)
-            
+
             # read key and write to serial port
             key = w.getch()
             if key == 10 or (key > 31 and key < 256):
                 # Is a character
                 ser.write(bytes([key]))
             elif int(key) == 1:     # CTRL+A, enter ADB mode
+                # Save cursor position
+                (xPos, yPos) = w.getyx()
                 self.adbMode(w, ser)
+                # Restore cursor position
+                w.move(xPos, yPos)
 
 
             w.refresh()
-    
+
     def adbMode(self, w, ser):
         stdscr.nodelay(False)
         curses.echo()
@@ -72,11 +76,9 @@ class TerminalEmulator:
             w.clrtoeol()
             w.addstr(" {}".format(str(e)), curses.A_REVERSE)
             w.refresh()
-        
+
         curses.noecho()
         stdscr.nodelay(True)
-                
-
         
 
 if __name__ == '__main__':