Skip to content

Commit 211347d

Browse files
committed
perf(win): cursor position query has a significantly faster alternative in winapi
1 parent 5b0b556 commit 211347d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tui.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ namespace tui {
182182
// tell the terminal to check where the cursor is
183183
csi_fn(query_position, "6n");
184184

185+
#ifdef _WIN32
186+
// returns: (rows;cols)
187+
inline std::pair<unsigned, unsigned> get_position() {
188+
auto info = get_console_buf_info();
189+
auto rows = info.dwCursorPosition.X + 1;
190+
auto cols = info.dwCursorPosition.Y + 1;
191+
return {rows, cols};
192+
}
193+
#else
185194
// returns: (rows;cols)
186195
// NOTE: can take a while (eg 16ms) on (relatively) slow terminals
187196
inline std::pair<unsigned, unsigned> get_position() {
@@ -200,6 +209,8 @@ namespace tui {
200209

201210
return {rows, cols};
202211
}
212+
#endif
213+
203214
} // namespace cursor
204215

205216
namespace screen {

0 commit comments

Comments
 (0)