There is some legacy C code that implements a multi-level menu in the linux terminal. To navigate through nested menus, use the following algorithm:

  1. There is a buffer containing 24x80 characters.
  2. A new screen is drawn in it.
  3. If this is not the first screen, then the previous state is reset to the second buffer.
  4. Buffer content is displayed.

I need to refine this code now, but this mechanism with drawing into the buffer just freezes. All kinds of life-style delights printf'ov immediately go to the forest.

I want to remake this way:

  1. Calculate the area of ​​drawing a new submenu
  2. Specifically, this area is dropped into a small local buffer.
  3. A submenu is drawn directly to the screen
  4. When returning - we return a piece of the screen from the buffer back

Actually a question. Is it possible to implement paragraph 2?

Well, in general, if you have any thoughts on how to organize such behavior humanly, I will be glad.

PS curses not to offer. Fully shovel under it will not stay.

  • printf walks through the forest because you don't know about sprintf - KoVadim 1:56 pm
  • @KoVadim No, not for this. He goes to the forest, because there this buffer with the buffers is organized in a completely hellish way. Here's a piece even laid out govnokod.ru/20400 - rjhdby
  • You can implement as you wish. ESC sequence in the terminal works. Therefore, you can rewrite at least one character. - Yaroslav
  • @Yaroslav the question is not how to redraw - this, thank God, does not cause problems. The question is how to buffer a piece of the screen in order to return the contents covered by the new window after it is closed. - rjhdby
  • @rjhdby Do you want to find out what is on the terminal? - Yaroslav

0