GoNCurses在前景窗口移动后刷新背景窗口。

huangapple go评论115阅读模式
英文:

GoNCurses refresh background window after foreground window moves

问题

我正在尝试理解ncurses的工作原理。这里有一个我正在努力理解和使其工作的示例。

首先是思路:

  • 窗口1(stdscr)具有背景和打印文本
  • 窗口2(sWin)位于窗口1上方,具有不同的背景
  • 移动窗口2在窗口1上方

以下是设置:

  1. stdscr, _ := gc.Init()
  2. defer gc.End()
  3. gc.Echo(false)
  4. gc.Cursor(0)
  5. gc.CBreak(true)
  6. stdscr.SetBackground('#')
  7. stdscr.MovePrint(12, 15, "ABCDEFGHIJKLMNOPQ...")
  8. stdscr.NoutRefresh()
  9. y, x := 10, 20
  10. sWin, _ := gc.NewWindow(4, 8, y, x)
  11. sWin.Keypad(true)
  12. sWin.SetBackground('.')
  13. sWin.Box(0, 0)
  14. sWin.NoutRefresh()
  15. gc.Update()

还有一个非常简单的for循环,用于移动前景窗口:

  1. main:
  2. for {
  3. // stdscr.Erase()
  4. // stdscr.NoutRefresh()
  5. sWin.MoveWindow(y, x)
  6. sWin.NoutRefresh()
  7. gc.Update()
  8. switch sWin.GetChar() {
  9. case gc.KEY_RIGHT:
  10. x++
  11. case gc.KEY_DOWN:
  12. y++
  13. case 'q':
  14. break main
  15. }
  16. }
  17. sWin.Delete()
  18. stdscr.Delete()

现在,当我移动窗口2时,背景中的窗口不会刷新,留下了痕迹。

当我取消注释stdscr.Erase()stdscr.NoutRefresh()时,我修复了痕迹,但是我当然会失去背景窗口上的所有数据,比如文本"ABCDEFGHIJKLMNOPQ..."

我尝试将窗口2设置为主窗口的子窗口,但没有成功。我该如何修复/处理这个问题?一般情况下,ncurses如何管理重叠的窗口?谢谢!

英文:

I am trying to understand how does ncurses work. Here is one example I am struggling to understand and make it work.

First the idea:

  • Window 1 (stdscr) with background and printed text
  • Window 2 (sWin) over Window 1 with different background
  • Moving Window 2 over Window 1

And here is the setup:

  1. stdscr, _ := gc.Init()
  2. defer gc.End()
  3. gc.Echo(false)
  4. gc.Cursor(0)
  5. gc.CBreak(true)
  6. stdscr.SetBackground('#')
  7. stdscr.MovePrint(12, 15, "ABCDEFGHIJKLMNOPQ...")
  8. stdscr.NoutRefresh()
  9. y, x := 10, 20
  10. sWin, _ := gc.NewWindow(4, 8, y, x)
  11. sWin.Keypad(true)
  12. sWin.SetBackground('.')
  13. sWin.Box(0, 0)
  14. sWin.NoutRefresh()
  15. gc.Update()

And a very simple for loop that will help with moving the foreground window:

  1. main:
  2. for {
  3. // stdscr.Erase()
  4. // stdscr.NoutRefresh()
  5. sWin.MoveWindow(y, x)
  6. sWin.NoutRefresh()
  7. gc.Update()
  8. switch sWin.GetChar() {
  9. case gc.KEY_RIGHT:
  10. x++
  11. case gc.KEY_DOWN:
  12. y++
  13. case 'q':
  14. break main
  15. }
  16. }
  17. sWin.Delete()
  18. stdscr.Delete()

Now when I move window 2 the one in the background does not refresh and a trail is left:

  1. ##########################
  2. #######┌┌┌┌┌──────┐#######
  3. #######│││││......│#######
  4. ##ABCDE│││││......│...####
  5. #######└└└└└──────┘#######
  6. ##########################
  7. ##########################

When I uncomment stdscr.Erase() and stdscr.NoutRefresh() I fix the trail but of course I lose all the data on the background window such as the text "ABCDEFGHIJKLMNOPQ...":

  1. #####################
  2. #######┌──────┐######
  3. #######│......│######
  4. #######│......│######
  5. #######└──────┘######
  6. #####################
  7. #####################

I tried making Window 2 a sub window of the main one but it did not work. How can I fix/handle this? And how are overlapping windows managed in general with ncurses?
Thanks!

答案1

得分: 1

curses不直接支持这个(请参阅panel库)。否则,你可以使用touchwin作为一种解决方法(使用dialogcdk完成)。

英文:

curses doesn't support that directly (see the panel library. Otherwise, you'll have to use touchwin as a workaround (done with dialog and cdk).

huangapple
  • 本文由 发表于 2023年2月9日 10:10:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75393528.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定