@@ -559,6 +559,8 @@ void Console::InitEscapeSequenceMap()
559559 escapeSequenceMap.insert ({' h' , [&](std::string args) { ShowCursor (args); } });
560560 escapeSequenceMap.insert ({' l' , [&](std::string args) { HideCursor (args); } });
561561 escapeSequenceMap.insert ({' m' , [&](std::string args) { SetDisplayAttributes (args); } });
562+ escapeSequenceMap.insert ({' s' , [&](std::string args) { SaveCursorPosition (args); } });
563+ escapeSequenceMap.insert ({' u' , [&](std::string args) { RestoreCursorPosition (args); } });
562564}
563565
564566// turns an argument string into numbers
@@ -952,6 +954,26 @@ void Console::HideCursor(std::string args)
952954 cursorRequestedHidden = true ;
953955}
954956
957+ // Bound to ANSI escape code s
958+ // Page: https://en.wikipedia.org/wiki/ANSI_escape_code
959+ // Section: Some popular private sequences
960+ // Description: Saves the current cursor position
961+ void Console::SaveCursorPosition (std::string args)
962+ {
963+ savedCursorX = cursorX;
964+ savedCursorY = cursorY;
965+ }
966+
967+ // Bound to ANSI escape code u
968+ // Page: https://en.wikipedia.org/wiki/ANSI_escape_code
969+ // Section: Some popular private sequences
970+ // Description: Restores the cursor's position to the saved value
971+ void Console::RestoreCursorPosition (std::string args)
972+ {
973+ cursorX = savedCursorX;
974+ cursorY = savedCursorY;
975+ }
976+
955977/*
956978These setter and getter functions fix a problem where ANSI escape codes expect
957979an origin of (1,1) while the Console class expects an origin of (0,0).
0 commit comments