Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
btwise
Termbox Go
提交
93860e16
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 搜索 >>
未验证
提交
93860e16
编写于
8月 18, 2019
作者:
Y
Yasuhiro Matsumoto
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix demos
上级
92e767c2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
89 addition
and
30 deletion
+89
-30
_demos/editbox.go
_demos/editbox.go
+36
-12
_demos/keyboard.go
_demos/keyboard.go
+53
-18
未找到文件。
_demos/editbox.go
浏览文件 @
93860e16
package
main
import
(
"unicode/utf8"
"github.com/mattn/go-runewidth"
"github.com/nsf/termbox-go"
"unicode/utf8"
)
func
tbprint
(
x
,
y
int
,
fg
,
bg
termbox
.
Attribute
,
msg
string
)
{
...
...
@@ -80,6 +81,8 @@ func (eb *EditBox) Draw(x, y, w, h int) {
eb
.
AdjustVOffset
(
w
)
const
coldef
=
termbox
.
ColorDefault
const
colred
=
termbox
.
ColorRed
fill
(
x
,
y
,
w
,
h
,
termbox
.
Cell
{
Ch
:
' '
})
t
:=
eb
.
text
...
...
@@ -96,8 +99,8 @@ func (eb *EditBox) Draw(x, y, w, h int) {
}
if
rx
>=
w
{
termbox
.
SetCell
(
x
+
w
-
1
,
y
,
'→'
,
col
def
,
coldef
)
termbox
.
SetCell
(
x
+
w
-
1
,
y
,
arrowRight
,
col
red
,
coldef
)
break
}
...
...
@@ -124,7 +127,7 @@ func (eb *EditBox) Draw(x, y, w, h int) {
}
if
eb
.
line_voffset
!=
0
{
termbox
.
SetCell
(
x
,
y
,
'←'
,
coldef
,
coldef
)
termbox
.
SetCell
(
x
,
y
,
arrowLeft
,
colred
,
coldef
)
}
}
...
...
@@ -237,14 +240,25 @@ func redraw_all() {
midx
:=
(
w
-
edit_box_width
)
/
2
// unicode box drawing chars around the edit box
termbox
.
SetCell
(
midx
-
1
,
midy
,
'│'
,
coldef
,
coldef
)
termbox
.
SetCell
(
midx
+
edit_box_width
,
midy
,
'│'
,
coldef
,
coldef
)
termbox
.
SetCell
(
midx
-
1
,
midy
-
1
,
'┌'
,
coldef
,
coldef
)
termbox
.
SetCell
(
midx
-
1
,
midy
+
1
,
'└'
,
coldef
,
coldef
)
termbox
.
SetCell
(
midx
+
edit_box_width
,
midy
-
1
,
'┐'
,
coldef
,
coldef
)
termbox
.
SetCell
(
midx
+
edit_box_width
,
midy
+
1
,
'┘'
,
coldef
,
coldef
)
fill
(
midx
,
midy
-
1
,
edit_box_width
,
1
,
termbox
.
Cell
{
Ch
:
'─'
})
fill
(
midx
,
midy
+
1
,
edit_box_width
,
1
,
termbox
.
Cell
{
Ch
:
'─'
})
if
runewidth
.
EastAsianWidth
{
termbox
.
SetCell
(
midx
-
1
,
midy
,
'|'
,
coldef
,
coldef
)
termbox
.
SetCell
(
midx
+
edit_box_width
,
midy
,
'|'
,
coldef
,
coldef
)
termbox
.
SetCell
(
midx
-
1
,
midy
-
1
,
'+'
,
coldef
,
coldef
)
termbox
.
SetCell
(
midx
-
1
,
midy
+
1
,
'+'
,
coldef
,
coldef
)
termbox
.
SetCell
(
midx
+
edit_box_width
,
midy
-
1
,
'+'
,
coldef
,
coldef
)
termbox
.
SetCell
(
midx
+
edit_box_width
,
midy
+
1
,
'+'
,
coldef
,
coldef
)
fill
(
midx
,
midy
-
1
,
edit_box_width
,
1
,
termbox
.
Cell
{
Ch
:
'-'
})
fill
(
midx
,
midy
+
1
,
edit_box_width
,
1
,
termbox
.
Cell
{
Ch
:
'-'
})
}
else
{
termbox
.
SetCell
(
midx
-
1
,
midy
,
'│'
,
coldef
,
coldef
)
termbox
.
SetCell
(
midx
+
edit_box_width
,
midy
,
'│'
,
coldef
,
coldef
)
termbox
.
SetCell
(
midx
-
1
,
midy
-
1
,
'┌'
,
coldef
,
coldef
)
termbox
.
SetCell
(
midx
-
1
,
midy
+
1
,
'└'
,
coldef
,
coldef
)
termbox
.
SetCell
(
midx
+
edit_box_width
,
midy
-
1
,
'┐'
,
coldef
,
coldef
)
termbox
.
SetCell
(
midx
+
edit_box_width
,
midy
+
1
,
'┘'
,
coldef
,
coldef
)
fill
(
midx
,
midy
-
1
,
edit_box_width
,
1
,
termbox
.
Cell
{
Ch
:
'─'
})
fill
(
midx
,
midy
+
1
,
edit_box_width
,
1
,
termbox
.
Cell
{
Ch
:
'─'
})
}
edit_box
.
Draw
(
midx
,
midy
,
edit_box_width
,
1
)
termbox
.
SetCursor
(
midx
+
edit_box
.
CursorX
(),
midy
)
...
...
@@ -253,6 +267,16 @@ func redraw_all() {
termbox
.
Flush
()
}
var
arrowLeft
=
'←'
var
arrowRight
=
'→'
func
init
()
{
if
runewidth
.
EastAsianWidth
{
arrowLeft
=
'<'
arrowRight
=
'>'
}
}
func
main
()
{
err
:=
termbox
.
Init
()
if
err
!=
nil
{
...
...
_demos/keyboard.go
浏览文件 @
93860e16
package
main
import
"github.com/nsf/termbox-go"
import
"fmt"
import
(
"fmt"
"github.com/mattn/go-runewidth"
"github.com/nsf/termbox-go"
)
type
key
struct
{
x
int
...
...
@@ -173,6 +177,37 @@ var K_ARROW_RIGHT = []key{{58, 12, '('}, {59, 12, 0x2192}, {60, 12, ')'}}
var
K_K_0
=
[]
key
{{
65
,
12
,
' '
},
{
66
,
12
,
'0'
},
{
67
,
12
,
' '
},
{
68
,
12
,
' '
}}
var
K_K_PERIOD
=
[]
key
{{
71
,
12
,
'.'
}}
var
borderTopLeft
rune
=
0x250C
var
borderTopRight
rune
=
0x2510
var
borderBotomLeft
rune
=
0x2514
var
borderBottomRight
rune
=
0x2518
var
borderVertical
rune
=
0x2500
var
borderHorizontal
rune
=
0x2502
var
borderHorizontalLeftBar
rune
=
0x251C
var
borderHorizontalRight
rune
=
0x2524
var
boxShadow
rune
=
0x2588
func
init
()
{
if
runewidth
.
EastAsianWidth
{
K_BACKSPACE
[
0
]
.
ch
=
'<'
K_BACKSPACE
[
1
]
.
ch
=
'-'
K_BACKSPACE
[
2
]
.
ch
=
'-'
K_ARROW_UP
[
1
]
.
ch
=
'^'
K_ARROW_DOWN
[
1
]
.
ch
=
'v'
K_ARROW_LEFT
[
1
]
.
ch
=
'<'
K_ARROW_RIGHT
[
1
]
.
ch
=
'>'
borderTopLeft
=
'+'
borderTopRight
=
'+'
borderBotomLeft
=
'+'
borderBottomRight
=
'+'
borderVertical
=
'-'
borderHorizontal
=
'|'
borderHorizontalLeftBar
=
'+'
borderHorizontalRight
=
'+'
boxShadow
=
' '
}
}
type
combo
struct
{
keys
[][]
key
}
...
...
@@ -352,28 +387,28 @@ func draw_key(k []key, fg, bg termbox.Attribute) {
}
func
draw_keyboard
()
{
termbox
.
SetCell
(
0
,
0
,
0x250C
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
79
,
0
,
0x2510
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
0
,
23
,
0x2514
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
79
,
23
,
0x2518
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
0
,
0
,
borderTopLeft
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
79
,
0
,
borderTopRight
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
0
,
23
,
borderBotomLeft
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
79
,
23
,
borderBottomRight
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
for
i
:=
1
;
i
<
79
;
i
++
{
termbox
.
SetCell
(
i
,
0
,
0x2500
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
i
,
23
,
0x2500
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
i
,
17
,
0x2500
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
i
,
4
,
0x2500
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
i
,
0
,
borderVertical
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
i
,
23
,
borderVertical
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
i
,
17
,
borderVertical
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
i
,
4
,
borderVertical
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
}
for
i
:=
1
;
i
<
23
;
i
++
{
termbox
.
SetCell
(
0
,
i
,
0x2502
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
79
,
i
,
0x2502
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
0
,
i
,
borderHorizontal
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
79
,
i
,
borderHorizontal
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
}
termbox
.
SetCell
(
0
,
17
,
0x251C
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
79
,
17
,
0x2524
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
0
,
4
,
0x251C
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
79
,
4
,
0x2524
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
0
,
17
,
borderHorizontalLeftBar
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
79
,
17
,
borderHorizontalRight
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
0
,
4
,
borderHorizontalLeftBar
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
termbox
.
SetCell
(
79
,
4
,
borderHorizontalRight
,
termbox
.
ColorWhite
,
termbox
.
ColorBlack
)
for
i
:=
5
;
i
<
17
;
i
++
{
termbox
.
SetCell
(
1
,
i
,
0x2588
,
termbox
.
ColorYellow
,
termbox
.
ColorYellow
)
termbox
.
SetCell
(
78
,
i
,
0x2588
,
termbox
.
ColorYellow
,
termbox
.
ColorYellow
)
termbox
.
SetCell
(
1
,
i
,
boxShadow
,
termbox
.
ColorYellow
,
termbox
.
ColorYellow
)
termbox
.
SetCell
(
78
,
i
,
boxShadow
,
termbox
.
ColorYellow
,
termbox
.
ColorYellow
)
}
draw_key
(
K_ESC
,
termbox
.
ColorWhite
,
termbox
.
ColorBlue
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录