From a63e0cc539aa2439bb6ee2bce0961aeba37c839e Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 16 Sep 2020 08:42:17 -0300 Subject: [PATCH] Adding method to get translated cursor position. --- src/core/screen.c | 21 +++++++++++++++++++++ src/include/lib3270.h | 15 +++++++++++++++ 2 files changed, 36 insertions(+), 0 deletions(-) diff --git a/src/core/screen.c b/src/core/screen.c index 3faf38c..7357ff4 100644 --- a/src/core/screen.c +++ b/src/core/screen.c @@ -422,6 +422,27 @@ LIB3270_EXPORT int lib3270_get_cursor_address(const H3270 *hSession) return state ? -state : hSession->cursor_addr; } +LIB3270_EXPORT int lib3270_get_cursor_position(const H3270 *hSession, unsigned short *row, unsigned short *col) +{ + int state = check_online_session(hSession); + if(state) + { + *row = *col = 9; + return state; + } + + unsigned short addr = (unsigned short) hSession->cursor_addr; + + if(row) + *row = (addr / ((unsigned short) hSession->view.cols))+1; + + if(col) + *col = (addr % ((unsigned short) hSession->view.cols))+1; + + return 0; +} + + /** * @brief Converts row/col in a buffer address. * diff --git a/src/include/lib3270.h b/src/include/lib3270.h index b71c119..4124dcf 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -767,6 +767,21 @@ LIB3270_EXPORT int lib3270_get_cursor_address(const H3270 *hSession); /** + * @brief Get row/col of the current cursor position. + * + * @param hSession Session handler. + * @param row Pointer for current cursor row. + * @param col Pointer for current cursor column. + * + * @return 0 if ok, error code if not (sets errno). + * + * @retval EINVAL Invalid session. + * @retval ENOTCONN Not connected to host. + * + */ + LIB3270_EXPORT int lib3270_get_cursor_position(const H3270 *hSession, unsigned short *row, unsigned short *col); + + /** * @brief Move cursor * * @param h Session handle. -- libgit2 0.21.2