1
0
mirror of https://github.com/gdamore/tcell.git synced 2025-04-26 13:48:53 +08:00

fixes #44 Expose some capability info

This commit is contained in:
Garrett D'Amore 2016-01-19 15:51:33 -08:00
parent 0c522ee370
commit 5dc5326c0e
4 changed files with 87 additions and 4 deletions

View File

@ -1,6 +1,6 @@
// +build windows
// Copyright 2015 The TCell Authors
// Copyright 2016 The TCell Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use file except in compliance with the License.
@ -934,4 +934,49 @@ func (s *cScreen) CanDisplay(r rune, checkFallbacks bool) bool {
return true
}
func (s *cScreen) HasMouse() bool {
return true
}
func (s *cScreen) Resize(int, int, int, int) {}
func (s *cScreen) HasKey(k Key) bool {
// Microsoft has codes for some keys, but they are unusual,
// so we don't include them. We include all the typical
// 101, 105 key layout keys.
valid := map[Key]bool{
KeyBackspace: true,
KeyTab: true,
KeyEscape: true,
KeySpace: true,
KeyPause: true,
KeyPrint: true,
KeyPgUp: true,
KeyPgDn: true,
KeyEnter: true,
KeyEnd: true,
KeyHome: true,
KeyLeft: true,
KeyUp: true,
KeyRight: true,
KeyDown: true,
KeyInsert: true,
KeyDelete: true,
KeyF1: true,
KeyF2: true,
KeyF3: true,
KeyF4: true,
KeyF5: true,
KeyF6: true,
KeyF7: true,
KeyF8: true,
KeyF9: true,
KeyF10: true,
KeyF11: true,
KeyF12: true,
KeyRune: true,
}
return valid[k]
}

View File

@ -1,4 +1,4 @@
// Copyright 2015 The TCell Authors
// Copyright 2016 The TCell Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use file except in compliance with the License.
@ -101,6 +101,12 @@ type Screen interface {
// DisableMouse disables the mouse.
DisableMouse()
// HasMouse returns true if the terminal (apparently) supports a
// mouse. Note that the a return value of true doesn't guarantee that
// a mouse/pointing device is present; a false return definitely
// indicates no mouse support is available.
HasMouse() bool
// Colors returns the number of colors. All colors are assumed to
// use the ANSI color map. If a terminal is monochrome, it will
// return 0.
@ -174,6 +180,16 @@ type Screen interface {
// ask a screen to resize, but it allows the Screen to implement
// the View interface.
Resize(int, int, int, int)
// HasKey returns true if the keyboard is believed to have the
// key. In some cases a keyboard may have keys with this name
// but no support for them, while in others a key may be reported
// as supported but not actually be usable (such as some emulators
// that hijack certain keys). Its best not to depend to strictly
// on this function, but it can be used for hinting when building
// menus, displayed hot-keys, etc. Note that KeyRune (literal
// runes) is always true.
HasKey(Key) bool
}
// NewScreen returns a default Screen suitable for the user's terminal

View File

@ -1,4 +1,4 @@
// Copyright 2015 The TCell Authors
// Copyright 2016 The TCell Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use file except in compliance with the License.
@ -491,4 +491,12 @@ func (s *simscreen) CanDisplay(r rune, checkFallbacks bool) bool {
return false
}
func (s *simscreen) HasMouse() bool {
return false
}
func (s *simscreen) Resize(int, int, int, int) {}
func (s *simscreen) HasKey(Key) bool {
return true
}

View File

@ -1,4 +1,4 @@
// Copyright 2015 The TCell Authors
// Copyright 2016 The TCell Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use file except in compliance with the License.
@ -1133,4 +1133,18 @@ func (t *tScreen) CanDisplay(r rune, checkFallbacks bool) bool {
return false
}
func (t *tScreen) HasMouse() bool {
return len(t.mouse) != 0
}
func (t *tScreen) HasKey(k Key) bool {
if k == KeyRune {
return true
}
if _, exist := t.keys[k]; exist {
return true
}
return false
}
func (t *tScreen) Resize(int, int, int, int) {}