Merge branch 'mode-center'
This commit is contained in:
commit
190b049f76
@ -9,6 +9,7 @@ import (
|
||||
"github.com/erroneousboat/slack-term/src/service"
|
||||
)
|
||||
|
||||
// Channels is the definition of a Channels component
|
||||
type Channels struct {
|
||||
List *termui.List
|
||||
SelectedChannel int
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"github.com/erroneousboat/slack-term/src/service"
|
||||
)
|
||||
|
||||
// Chat is the definition of a Chat component
|
||||
type Chat struct {
|
||||
List *termui.List
|
||||
Offset int
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"github.com/erroneousboat/slack-term/src/service"
|
||||
)
|
||||
|
||||
// Input is the definition of and input box
|
||||
// Input is the definition of an Input component
|
||||
type Input struct {
|
||||
Par *termui.Par
|
||||
CursorPosition int
|
||||
|
@ -2,10 +2,12 @@ package components
|
||||
|
||||
import "github.com/gizak/termui"
|
||||
|
||||
// Mode is the definition of Mode component
|
||||
type Mode struct {
|
||||
Par *termui.Par
|
||||
}
|
||||
|
||||
// CreateMode is the constructor of the Mode struct
|
||||
func CreateMode() *Mode {
|
||||
mode := &Mode{
|
||||
Par: termui.NewPar("NORMAL"),
|
||||
@ -19,6 +21,36 @@ func CreateMode() *Mode {
|
||||
// Buffer implements interface termui.Bufferer
|
||||
func (m *Mode) Buffer() termui.Buffer {
|
||||
buf := m.Par.Buffer()
|
||||
|
||||
// Center text
|
||||
space := m.Par.InnerWidth()
|
||||
word := len(m.Par.Text)
|
||||
|
||||
midSpace := space / 2
|
||||
midWord := word / 2
|
||||
|
||||
start := midSpace - midWord
|
||||
|
||||
cells := termui.DefaultTxBuilder.Build(
|
||||
m.Par.Text, m.Par.TextFgColor, m.Par.TextBgColor)
|
||||
|
||||
i, j := 0, 0
|
||||
x := m.Par.InnerBounds().Min.X
|
||||
for x < m.Par.InnerBounds().Max.X {
|
||||
if i < start {
|
||||
buf.Set(x, m.Par.InnerY(), termui.Cell{Ch: ' '})
|
||||
x++
|
||||
i++
|
||||
} else {
|
||||
if j < len(cells) {
|
||||
buf.Set(x, m.Par.InnerY(), cells[j])
|
||||
i++
|
||||
j++
|
||||
}
|
||||
x++
|
||||
}
|
||||
}
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user