0

I'm trying to get the terminal size using ansi escape codes. I found some help in How do I determine size of ANSI terminal? but i cannot understand how to get the response from DSR6 to get the row / column of the bottom right corner. Thank you. I need this because im trying to align some text in the middle of the terminal.

  • In general itʼs better to use a dedicated library for terminal management; have you considered using ncurses? – Daniel H Jun 20 '20 at 10:21
  • No.. i haven't tried any library. But i will check it out . Thank you –  Jun 20 '20 at 10:22
  • 2
    Does this answer your question? [Get size of terminal window (rows/columns)](https://stackoverflow.com/questions/23369503/get-size-of-terminal-window-rows-columns) – brc-dd Jun 20 '20 at 10:24
  • can i get the desired result without any other library? Is there any possibility to use cin? –  Jun 20 '20 at 10:27
  • @AlexandruStoica I have never heard even a bit of such possibility... AFAIK you'll have to rely on some platform-specific header like `ioctl` or `ncurses` or `windows`. – brc-dd Jun 20 '20 at 10:43
  • 1
    Yes, it is possible to just use `std::cin` and not use ncurses. Depending on how much functionality you need, you'll end up creating something much like ncurses. (Although ncurses has the advantage of having been well debugged over the past few decades.) – Eljay Jun 20 '20 at 14:25

1 Answers1

0

I don't have a solution using ansi escape codes, but this solution here gives you the terminal size in both Windows and Linux: https://stackoverflow.com/a/62485211/9178992

ProjectPhysX
  • 3,068
  • 2
  • 11
  • 26