Update Debug component

This commit is contained in:
erroneousboat 2017-12-02 11:09:01 +01:00
parent e38115970d
commit 336bf288dd
5 changed files with 37 additions and 22 deletions

View File

@ -4,44 +4,47 @@ import "github.com/erroneousboat/termui"
type Debug struct {
Par *termui.Par
List *termui.List
}
func CreateDebugComponent() *Debug {
func CreateDebugComponent(inputHeight int) *Debug {
debug := &Debug{
Par: termui.NewPar(""),
List: termui.NewList(),
}
debug.Par.Height = 3
debug.List.BorderLabel = "Debug"
debug.List.Height = termui.TermHeight() - inputHeight
return debug
}
// Buffer implements interface termui.Bufferer
func (d *Debug) Buffer() termui.Buffer {
return d.Par.Buffer()
return d.List.Buffer()
}
// GetHeight implements interface termui.GridBufferer
func (d *Debug) GetHeight() int {
return d.Par.Block.GetHeight()
return d.List.Block.GetHeight()
}
// SetWidth implements interface termui.GridBufferer
func (d *Debug) SetWidth(w int) {
d.Par.SetWidth(w)
d.List.SetWidth(w)
}
// SetX implements interface termui.GridBufferer
func (d *Debug) SetX(x int) {
d.Par.SetX(x)
d.List.SetX(x)
}
// SetY implements interface termui.GridBufferer
func (d *Debug) SetY(y int) {
d.Par.SetY(y)
d.List.SetY(y)
}
// SetText will set the text of the Debug component
func (d *Debug) SetText(text string) {
d.Par.Text = text
// Println will add the text to the Debug component
func (d *Debug) Println(text string) {
d.List.Items = append(d.List.Items, text)
termui.Render(d)
}

View File

@ -80,3 +80,18 @@ func (m *Mode) SetX(x int) {
func (m *Mode) SetY(y int) {
m.Par.SetY(y)
}
func (m *Mode) SetInsertMode() {
m.Par.Text = "INSERT"
termui.Render(m)
}
func (m *Mode) SetCommandMode() {
m.Par.Text = "NORMAL"
termui.Render(m)
}
func (m *Mode) SetSearchMode() {
m.Par.Text = "SEARCH"
termui.Render(m)
}

View File

@ -48,12 +48,12 @@ func CreateAppContext(flgConfig string, flgDebug bool) (*AppContext, error) {
termui.Body.AddRows(
termui.NewRow(
termui.NewCol(config.SidebarWidth, 0, view.Channels),
termui.NewCol(config.MainWidth, 0, view.Chat),
termui.NewCol(config.MainWidth-5, 0, view.Chat),
termui.NewCol(config.MainWidth-6, 0, view.Debug),
),
termui.NewRow(
termui.NewCol(config.SidebarWidth, 0, view.Mode),
termui.NewCol(config.MainWidth-1, 0, view.Input),
termui.NewCol(1, 0, view.Debug),
termui.NewCol(config.MainWidth, 0, view.Input),
),
)
} else {

View File

@ -238,20 +238,17 @@ func actionQuit(ctx *context.AppContext) {
func actionInsertMode(ctx *context.AppContext) {
ctx.Mode = context.InsertMode
ctx.View.Mode.Par.Text = "INSERT"
termui.Render(ctx.View.Mode)
ctx.View.Mode.SetInsertMode()
}
func actionCommandMode(ctx *context.AppContext) {
ctx.Mode = context.CommandMode
ctx.View.Mode.Par.Text = "NORMAL"
termui.Render(ctx.View.Mode)
ctx.View.Mode.SetCommandMode()
}
func actionSearchMode(ctx *context.AppContext) {
ctx.Mode = context.SearchMode
ctx.View.Mode.Par.Text = "SEARCH"
termui.Render(ctx.View.Mode)
ctx.View.Mode.SetSearchMode()
}
func actionGetMessages(ctx *context.AppContext) {

View File

@ -38,7 +38,7 @@ func CreateView(svc *service.SlackService) *View {
chat.SetMessages(slackMsgs)
// Debug: create the component
debug := components.CreateDebugComponent()
debug := components.CreateDebugComponent(input.Par.Height)
// Mode: create the component
mode := components.CreateModeComponent()