Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
btwise
Termbox Go
提交
d9cda937
T
Termbox Go
项目概览
btwise
/
Termbox Go
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Termbox Go
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d9cda937
编写于
12月 17, 2013
作者:
N
nsf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Disable mouse events by default. Allow ORing InputMode as flags.
Add InputMouse flag, which controls the mouse button click events.
上级
682ffcd2
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
72 addition
and
35 deletion
+72
-35
_demos/keyboard.go
_demos/keyboard.go
+27
-16
api.go
api.go
+13
-4
api_common.go
api_common.go
+3
-2
api_windows.go
api_windows.go
+20
-4
termbox.go
termbox.go
+3
-3
termbox_windows.go
termbox_windows.go
+6
-6
未找到文件。
_demos/keyboard.go
浏览文件 @
d9cda937
...
...
@@ -493,13 +493,19 @@ func draw_keyboard() {
printf_tb
(
21
,
2
,
termbox
.
ColorMagenta
,
termbox
.
ColorBlack
,
"(press CTRL+X and then CTRL+Q to exit)"
)
printf_tb
(
15
,
3
,
termbox
.
ColorMagenta
,
termbox
.
ColorBlack
,
"(press CTRL+X and then CTRL+C to change input mode)"
)
var
inputmodemap
=
[]
string
{
""
,
"termbox.InputEsc"
,
"termbox.InputAlt"
,
inputmode
:=
termbox
.
SetInputMode
(
termbox
.
InputCurrent
)
inputmode_str
:=
""
switch
{
case
inputmode
&
termbox
.
InputEsc
!=
0
:
inputmode_str
=
"termbox.InputEsc"
case
inputmode
&
termbox
.
InputAlt
!=
0
:
inputmode_str
=
"termbox.InputAlt"
}
printf_tb
(
3
,
18
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
,
"Input mode: %s"
,
inputmodemap
[
termbox
.
SetInputMode
(
termbox
.
InputCurrent
)])
if
inputmode
&
termbox
.
InputMouse
!=
0
{
inputmode_str
+=
" | termbox.InputMouse"
}
printf_tb
(
3
,
18
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
,
"Input mode: %s"
,
inputmode_str
)
}
var
fcmap
=
[]
string
{
...
...
@@ -581,17 +587,17 @@ func pretty_print_press(ev *termbox.Event) {
printf_tb
(
8
,
21
,
termbox
.
ColorCyan
,
termbox
.
ColorBlack
,
"octal: 0%o"
,
ev
.
Key
)
printf_tb
(
8
,
22
,
termbox
.
ColorRed
,
termbox
.
ColorBlack
,
"string: %s"
,
funckeymap
(
ev
.
Key
))
printf_tb
(
43
,
19
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
,
"Char: "
)
printf_tb
(
49
,
19
,
termbox
.
ColorYellow
,
termbox
.
ColorBlack
,
"decimal: %d"
,
ev
.
Ch
)
printf_tb
(
49
,
20
,
termbox
.
ColorGreen
,
termbox
.
ColorBlack
,
"hex: 0x%X"
,
ev
.
Ch
)
printf_tb
(
49
,
21
,
termbox
.
ColorCyan
,
termbox
.
ColorBlack
,
"octal: 0%o"
,
ev
.
Ch
)
printf_tb
(
49
,
22
,
termbox
.
ColorRed
,
termbox
.
ColorBlack
,
"string: %s"
,
string
(
ev
.
Ch
))
printf_tb
(
54
,
19
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
,
"Char: "
)
printf_tb
(
60
,
19
,
termbox
.
ColorYellow
,
termbox
.
ColorBlack
,
"decimal: %d"
,
ev
.
Ch
)
printf_tb
(
60
,
20
,
termbox
.
ColorGreen
,
termbox
.
ColorBlack
,
"hex: 0x%X"
,
ev
.
Ch
)
printf_tb
(
60
,
21
,
termbox
.
ColorCyan
,
termbox
.
ColorBlack
,
"octal: 0%o"
,
ev
.
Ch
)
printf_tb
(
60
,
22
,
termbox
.
ColorRed
,
termbox
.
ColorBlack
,
"string: %s"
,
string
(
ev
.
Ch
))
modifier
:=
"none"
if
ev
.
Mod
!=
0
{
modifier
=
"termbox.ModAlt"
}
printf_tb
(
43
,
18
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
,
"Modifier: %s"
,
modifier
)
printf_tb
(
54
,
18
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
,
"Modifier: %s"
,
modifier
)
}
func
pretty_print_resize
(
ev
*
termbox
.
Event
)
{
...
...
@@ -649,11 +655,12 @@ func main() {
}
defer
termbox
.
Close
()
termbox
.
SetInputMode
(
termbox
.
InputEsc
)
termbox
.
SetInputMode
(
termbox
.
InputEsc
|
termbox
.
InputMouse
)
termbox
.
Clear
(
termbox
.
ColorDefault
,
termbox
.
ColorDefault
)
draw_keyboard
()
termbox
.
Flush
()
inputmode
:=
0
ctrlxpressed
:=
false
loop
:
for
{
...
...
@@ -664,12 +671,16 @@ loop:
}
if
ev
.
Key
==
termbox
.
KeyCtrlC
&&
ctrlxpressed
{
chmap
:=
[]
termbox
.
InputMode
{
0
,
termbox
.
InputEsc
|
termbox
.
InputMouse
,
termbox
.
InputAlt
|
termbox
.
InputMouse
,
termbox
.
InputAlt
,
termbox
.
InputEsc
,
}
termbox
.
SetInputMode
(
chmap
[
termbox
.
SetInputMode
(
termbox
.
InputCurrent
)])
inputmode
++
if
inputmode
>=
len
(
chmap
)
{
inputmode
=
0
}
termbox
.
SetInputMode
(
chmap
[
inputmode
])
}
if
ev
.
Key
==
termbox
.
KeyCtrlX
{
ctrlxpressed
=
true
...
...
api.go
浏览文件 @
d9cda937
...
...
@@ -71,7 +71,6 @@ func Init() error {
out
.
WriteString
(
funcs
[
t_enter_ca
])
out
.
WriteString
(
funcs
[
t_enter_keypad
])
out
.
WriteString
(
funcs
[
t_enter_mouse
])
out
.
WriteString
(
funcs
[
t_hide_cursor
])
out
.
WriteString
(
funcs
[
t_clear_screen
])
...
...
@@ -277,16 +276,26 @@ func Clear(fg, bg Attribute) error {
// Sets termbox input mode. Termbox has two input modes:
//
// 1. Esc input mode. When ESC sequence is in the buffer and it doesn't match
// any known sequence. ESC means KeyEsc.
// any known sequence. ESC means KeyEsc.
This is the default input mode.
//
// 2. Alt input mode. When ESC sequence is in the buffer and it doesn't match
// any known sequence. ESC enables ModAlt modifier for the next keyboard event.
//
// Both input modes can be OR'ed with Mouse mode. Setting Mouse mode bit up will
// enable mouse button click events.
//
// If 'mode' is InputCurrent, returns the current input mode. See also Input*
// constants.
func
SetInputMode
(
mode
InputMode
)
InputMode
{
if
mode
!=
InputCurrent
{
input_mode
=
mode
if
mode
==
InputCurrent
{
return
input_mode
}
if
mode
&
InputMouse
!=
0
{
out
.
WriteString
(
funcs
[
t_enter_mouse
])
}
else
{
out
.
WriteString
(
funcs
[
t_exit_mouse
])
}
input_mode
=
mode
return
input_mode
}
api_common.go
浏览文件 @
d9cda937
...
...
@@ -142,9 +142,10 @@ const (
// Input mode. See SetInputMode function.
const
(
InputCurrent
InputMode
=
iota
InputEsc
InputEsc
InputMode
=
1
<<
iota
InputAlt
InputMouse
InputCurrent
InputMode
=
0
)
// Event type. See Event.Type field.
...
...
api_windows.go
浏览文件 @
d9cda937
...
...
@@ -30,7 +30,7 @@ func Init() error {
return
err
}
err
=
set_console_mode
(
in
,
enable_window_input
|
enable_mouse_input
)
err
=
set_console_mode
(
in
,
enable_window_input
)
if
err
!=
nil
{
return
err
}
...
...
@@ -155,16 +155,32 @@ func Clear(fg, bg Attribute) error {
// Sets termbox input mode. Termbox has two input modes:
//
// 1. Esc input mode. When ESC sequence is in the buffer and it doesn't match
// any known sequence. ESC means KeyEsc.
// any known sequence. ESC means KeyEsc.
This is the default input mode.
//
// 2. Alt input mode. When ESC sequence is in the buffer and it doesn't match
// any known sequence. ESC enables ModAlt modifier for the next keyboard event.
//
// Both input modes can be OR'ed with Mouse mode. Setting Mouse mode bit up will
// enable mouse button click events.
//
// If 'mode' is InputCurrent, returns the current input mode. See also Input*
// constants.
func
SetInputMode
(
mode
InputMode
)
InputMode
{
if
mode
!=
InputCurrent
{
input_mode
=
mode
if
mode
==
InputCurrent
{
return
input_mode
}
if
mode
&
InputMouse
!=
0
{
err
=
set_console_mode
(
in
,
enable_window_input
|
enable_mouse_input
)
if
err
!=
nil
{
panic
(
err
)
}
}
else
{
err
=
set_console_mode
(
in
,
enable_window_input
)
if
err
!=
nil
{
panic
(
err
)
}
}
input_mode
=
mode
return
input_mode
}
termbox.go
浏览文件 @
d9cda937
...
...
@@ -263,8 +263,8 @@ func extract_event(event *Event) bool {
}
// it's not escape sequence, then it's Alt or Esc, check input_mode
switch
input_mode
{
case
InputEsc
:
switch
{
case
input_mode
&
InputEsc
!=
0
:
// if we're in escape mode, fill Esc event, pop buffer, return success
event
.
Ch
=
0
event
.
Key
=
KeyEsc
...
...
@@ -272,7 +272,7 @@ func extract_event(event *Event) bool {
copy
(
inbuf
,
inbuf
[
1
:
])
inbuf
=
inbuf
[
:
len
(
inbuf
)
-
1
]
return
true
case
InputAlt
:
case
input_mode
&
InputAlt
!=
0
:
// if we're in alt mode, set Alt modifier to event and redo parsing
event
.
Mod
=
ModAlt
copy
(
inbuf
,
inbuf
[
1
:
])
...
...
termbox_windows.go
浏览文件 @
d9cda937
...
...
@@ -521,7 +521,7 @@ func key_event_record_to_event(r *key_event_record) (Event, bool) {
}
e
:=
Event
{
Type
:
EventKey
}
if
input_mode
==
InputAlt
{
if
input_mode
&
InputAlt
!=
0
{
if
alt_mode_esc
{
e
.
Mod
=
ModAlt
alt_mode_esc
=
false
...
...
@@ -599,10 +599,10 @@ func key_event_record_to_event(r *key_event_record) (Event, bool) {
case
vk_enter
:
e
.
Key
=
KeyEnter
case
vk_esc
:
switch
input_mode
{
case
InputEsc
:
switch
{
case
input_mode
&
InputEsc
!=
0
:
e
.
Key
=
KeyEsc
case
InputAlt
:
case
input_mode
&
InputAlt
!=
0
:
alt_mode_esc
=
true
return
Event
{},
false
}
...
...
@@ -624,7 +624,7 @@ func key_event_record_to_event(r *key_event_record) (Event, bool) {
if
ctrlpressed
{
if
Key
(
r
.
unicode_char
)
>=
KeyCtrlA
&&
Key
(
r
.
unicode_char
)
<=
KeyCtrlRsqBracket
{
e
.
Key
=
Key
(
r
.
unicode_char
)
if
input_mode
==
InputAlt
&&
e
.
Key
==
KeyEsc
{
if
input_mode
&
InputAlt
!=
0
&&
e
.
Key
==
KeyEsc
{
alt_mode_esc
=
true
return
Event
{},
false
}
...
...
@@ -636,7 +636,7 @@ func key_event_record_to_event(r *key_event_record) (Event, bool) {
e
.
Key
=
KeyCtrl2
return
e
,
true
case
51
:
if
input_mode
==
InputAlt
{
if
input_mode
&
InputAlt
!=
0
{
alt_mode_esc
=
true
return
Event
{},
false
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录