Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
GitCode
Cataclysm DDA
提交
56ae13e7
C
Cataclysm DDA
项目概览
GitCode
/
Cataclysm DDA
通知
4
Star
6383
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Cataclysm DDA
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
56ae13e7
编写于
1月 15, 2022
作者:
J
Jason Fields
提交者:
GitHub
1月 15, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ui] Properly render control characters in keybindings list (#54350)
上级
43f202e3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
4 deletion
+31
-4
src/input.cpp
src/input.cpp
+20
-4
src/input.h
src/input.h
+11
-0
未找到文件。
src/input.cpp
浏览文件 @
56ae13e7
...
...
@@ -510,10 +510,18 @@ void input_manager::init_keycode_mapping()
add_keyboard_char_keycode_pair
(
KEY_END
,
translate_marker_context
(
"key name"
,
"END"
)
);
add_keyboard_char_keycode_pair
(
'\n'
,
translate_marker_context
(
"key name"
,
"RETURN"
)
);
for
(
int
c
=
0
;
IS_CTRL_CHAR
(
c
);
c
++
)
{
// Some codes fall into this range but have more common names we'd prefer to use.
if
(
!
IS_NAMED_CTRL_CHAR
(
c
)
)
{
// These are directly translated in `get_keyname()`
// NOLINTNEXTLINE(cata-translate-string-literal)
add_keyboard_char_keycode_pair
(
c
,
string_format
(
"CTRL+%c"
,
c
+
64
)
);
}
}
// function keys, as defined by ncurses
for
(
int
i
=
F_KEY_NUM_BEG
;
i
<=
F_KEY_NUM_END
;
i
++
)
{
// not marked for translation here, but specially handled in get_keyname so
// it gets properly translated.
// These are directly translated in `get_keyname()`
// NOLINTNEXTLINE(cata-translate-string-literal)
add_keyboard_char_keycode_pair
(
KEY_F
(
i
),
string_format
(
"F%d"
,
i
)
);
}
...
...
@@ -689,6 +697,12 @@ std::string input_manager::get_keyname( int ch, input_event_t inp_type, bool por
}
else
{
return
string_format
(
pgettext
(
"function key name"
,
"F%d"
),
F_KEY_NUM
(
ch
)
);
}
}
else
if
(
IS_CTRL_CHAR
(
ch
)
&&
!
IS_NAMED_CTRL_CHAR
(
ch
)
)
{
if
(
portable
)
{
return
it
->
second
;
}
else
{
return
string_format
(
pgettext
(
"control key name"
,
"CTRL+%c"
),
ch
+
64
);
}
}
else
if
(
ch
>=
char_key_beg
&&
ch
<=
char_key_end
&&
ch
!=
' '
)
{
// character keys except space need no translation
return
it
->
second
;
...
...
@@ -928,7 +942,8 @@ void input_context::register_action( const std::string &action_descriptor )
register_action
(
action_descriptor
,
translation
()
);
}
void
input_context
::
register_action
(
const
std
::
string
&
action_descriptor
,
const
translation
&
name
)
void
input_context
::
register_action
(
const
std
::
string
&
action_descriptor
,
const
translation
&
name
)
{
if
(
action_descriptor
==
"ANY_INPUT"
)
{
registered_any_input
=
true
;
...
...
@@ -1694,7 +1709,8 @@ std::string input_context::press_x( const std::string &action_id, const std::str
}
// TODO: merge this with input_context::get_desc
std
::
string
input_context
::
press_x
(
const
std
::
string
&
action_id
,
const
std
::
string
&
key_bound_pre
,
std
::
string
input_context
::
press_x
(
const
std
::
string
&
action_id
,
const
std
::
string
&
key_bound_pre
,
const
std
::
string
&
key_bound_suf
,
const
std
::
string
&
key_unbound
)
const
{
if
(
action_id
==
"ANY_INPUT"
)
{
...
...
src/input.h
浏览文件 @
56ae13e7
...
...
@@ -60,6 +60,17 @@ inline constexpr bool IS_F_KEY( const int key )
{
return
key
>=
KEY_F
(
F_KEY_NUM_BEG
)
&&
key
<=
KEY_F
(
F_KEY_NUM_END
);
}
/** @return true if the given character is in the range of basic ASCII control characters */
inline
constexpr
bool
IS_CTRL_CHAR
(
const
int
key
)
{
// https://en.wikipedia.org/wiki/C0_and_C1_control_codes#Basic_ASCII_control_codes
return
key
>=
0
&&
key
<
' '
;
}
/** @return true if the given character is an ASCII control char but should not be rendered with "CTRL+" */
inline
constexpr
bool
IS_NAMED_CTRL_CHAR
(
const
int
key
)
{
return
key
==
'\t'
||
key
==
'\n'
||
key
==
KEY_ESCAPE
||
key
==
KEY_BACKSPACE
;
}
inline
constexpr
int
KEY_NUM
(
const
int
n
)
{
return
0x30
+
n
;
/* Numbers 0, 1, ..., 9 */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录