Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
尝试修复go-musicfox/go-musicfox#223
我看了一下源代码,计算
itemMaxLen
的时候menuStartColumn
没有*2
,因此程序只考虑左侧的空白并假设右侧的空白为0,最终导致itemMaxLen
过高,输出的时候第一列太长,留给第二列的空间不够(例如截图所示)。加上
*2
之后并没有完全解决问题,比如那个我也不知道为什么好用的+6
。理论上屏幕的宽度减去左右的空白(-menuStartColumn*2
),再减去中间的4个空格(-4
),得出的就是可以用来展示菜单的字符数,最后再把它除以二,平分给两列即可,但是实际上+6
的效果更好。我怀疑是后面什么地方给前面的计算问题打了补丁,所以这里也必须把itemMaxLen
算大一点。当前版本还有不少问题,尤其是初始菜单:因为每一项都很短,所以整个菜单看起来偏左。一个解决方案是根据当页菜单的内容长短决定
menuStartColumn
是什么,但是会导致之前提过的菜单左右跳动的问题(尤其是翻页的时候)。还有一个方案是在菜单周围加个框,让用户能看到菜单的边界是什么。我不太确定怎么搞最好,所以先把草稿发出了看看反馈。