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

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

GoNCurses refresh background window after foreground window moves

问题

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

首先是思路:

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

以下是设置:

stdscr, _ := gc.Init()
defer gc.End()
gc.Echo(false)
gc.Cursor(0)
gc.CBreak(true)

stdscr.SetBackground('#')
stdscr.MovePrint(12, 15, "ABCDEFGHIJKLMNOPQ...")
stdscr.NoutRefresh()

y, x := 10, 20
sWin, _ := gc.NewWindow(4, 8, y, x)
sWin.Keypad(true)
sWin.SetBackground('.')
sWin.Box(0, 0)
sWin.NoutRefresh()
gc.Update()

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

main:
for {
    // stdscr.Erase()
    // stdscr.NoutRefresh()
    sWin.MoveWindow(y, x)
    sWin.NoutRefresh()

    gc.Update()
    switch sWin.GetChar() {
    case gc.KEY_RIGHT:
        x++
    case gc.KEY_DOWN:
        y++
    case 'q':
        break main
    }
}
sWin.Delete()
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:

stdscr, _ := gc.Init()
defer gc.End()
gc.Echo(false)
gc.Cursor(0)
gc.CBreak(true)

stdscr.SetBackground('#')
stdscr.MovePrint(12, 15, "ABCDEFGHIJKLMNOPQ...")
stdscr.NoutRefresh()

y, x := 10, 20
sWin, _ := gc.NewWindow(4, 8, y, x)
sWin.Keypad(true)
sWin.SetBackground('.')
sWin.Box(0, 0)
sWin.NoutRefresh()
gc.Update()

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

main:
for {
	// stdscr.Erase()
	// stdscr.NoutRefresh()
	sWin.MoveWindow(y, x)
	sWin.NoutRefresh()

	gc.Update()
	switch sWin.GetChar() {
	case gc.KEY_RIGHT:
		x++
	case gc.KEY_DOWN:
		y++
	case 'q':
		break main
	}
}
sWin.Delete()
stdscr.Delete()

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

##########################
#######┌┌┌┌┌──────┐#######
#######│││││......│#######
##ABCDE│││││......│...####
#######└└└└└──────┘#######
##########################
##########################

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...":

#####################
#######┌──────┐######
#######│......│######
#######│......│######
#######└──────┘######
#####################
#####################

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:

确定