2018-04-14 23:06:57 +01:00
|
|
|
// Copyright 2018 Google Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2018-04-06 04:56:36 +02:00
|
|
|
// Binary boxes just creates containers with borders.
|
|
|
|
// Runs as long as there is at least one input (keyboard, mouse or terminal resize) event every 10 seconds.
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-04-09 03:17:40 +01:00
|
|
|
"image"
|
2018-04-06 04:56:36 +02:00
|
|
|
"time"
|
|
|
|
|
2018-04-23 01:05:54 +01:00
|
|
|
"github.com/mum4k/termdash"
|
2018-04-06 04:56:36 +02:00
|
|
|
"github.com/mum4k/termdash/container"
|
|
|
|
"github.com/mum4k/termdash/draw"
|
|
|
|
"github.com/mum4k/termdash/terminal/termbox"
|
|
|
|
"github.com/mum4k/termdash/terminalapi"
|
2018-04-09 03:33:24 +01:00
|
|
|
"github.com/mum4k/termdash/widgetapi"
|
2018-04-09 03:17:40 +01:00
|
|
|
"github.com/mum4k/termdash/widgets/fakewidget"
|
2018-04-06 04:56:36 +02:00
|
|
|
)
|
|
|
|
|
2018-04-09 03:17:40 +01:00
|
|
|
// inputEvents sends mouse and keyboard events on the channel.
|
|
|
|
func inputEvents(ctx context.Context, t terminalapi.Terminal, c *container.Container) <-chan terminalapi.Event {
|
|
|
|
ch := make(chan terminalapi.Event)
|
2018-04-06 04:56:36 +02:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
ev := t.Event(ctx)
|
2018-04-09 03:17:40 +01:00
|
|
|
switch ev.(type) {
|
|
|
|
case *terminalapi.Keyboard, *terminalapi.Mouse:
|
|
|
|
ch <- ev
|
2018-04-06 04:56:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
return ch
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
t, err := termbox.New()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer t.Close()
|
|
|
|
|
2018-04-09 03:33:24 +01:00
|
|
|
wOpts := widgetapi.Options{
|
2018-04-23 01:05:54 +01:00
|
|
|
MinimumSize: fakewidget.MinimumSize,
|
2018-04-09 03:17:40 +01:00
|
|
|
WantKeyboard: true,
|
|
|
|
WantMouse: true,
|
|
|
|
}
|
2018-04-06 04:56:36 +02:00
|
|
|
c := container.New(
|
|
|
|
t,
|
|
|
|
container.SplitVertical(
|
|
|
|
container.Left(
|
|
|
|
container.SplitHorizontal(
|
|
|
|
container.Top(
|
|
|
|
container.Border(draw.LineStyleLight),
|
2018-04-09 03:33:24 +01:00
|
|
|
container.PlaceWidget(fakewidget.New(widgetapi.Options{
|
2018-04-23 01:05:54 +01:00
|
|
|
MinimumSize: fakewidget.MinimumSize,
|
2018-04-09 03:17:40 +01:00
|
|
|
WantKeyboard: true,
|
|
|
|
WantMouse: true,
|
|
|
|
Ratio: image.Point{5, 1},
|
|
|
|
})),
|
2018-04-06 04:56:36 +02:00
|
|
|
),
|
|
|
|
container.Bottom(
|
|
|
|
container.SplitHorizontal(
|
|
|
|
container.Top(
|
|
|
|
container.Border(draw.LineStyleLight),
|
2018-04-09 03:17:40 +01:00
|
|
|
container.PlaceWidget(fakewidget.New(wOpts)),
|
2018-04-06 04:56:36 +02:00
|
|
|
),
|
|
|
|
container.Bottom(
|
|
|
|
container.SplitVertical(
|
|
|
|
container.Left(
|
|
|
|
container.Border(draw.LineStyleLight),
|
2018-04-09 03:17:40 +01:00
|
|
|
container.PlaceWidget(fakewidget.New(wOpts)),
|
2018-04-06 04:56:36 +02:00
|
|
|
),
|
|
|
|
container.Right(
|
|
|
|
container.SplitVertical(
|
|
|
|
container.Left(
|
|
|
|
container.Border(draw.LineStyleLight),
|
2018-04-09 03:17:40 +01:00
|
|
|
container.VerticalAlignMiddle(),
|
2018-04-09 03:33:24 +01:00
|
|
|
container.PlaceWidget(fakewidget.New(widgetapi.Options{
|
2018-04-23 01:05:54 +01:00
|
|
|
MinimumSize: fakewidget.MinimumSize,
|
2018-04-09 03:17:40 +01:00
|
|
|
WantKeyboard: true,
|
|
|
|
WantMouse: true,
|
|
|
|
Ratio: image.Point{2, 1},
|
|
|
|
})),
|
2018-04-06 04:56:36 +02:00
|
|
|
),
|
|
|
|
container.Right(
|
|
|
|
container.Border(draw.LineStyleLight),
|
2018-04-09 03:17:40 +01:00
|
|
|
container.PlaceWidget(fakewidget.New(wOpts)),
|
2018-04-06 04:56:36 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
container.Right(
|
|
|
|
container.Border(draw.LineStyleLight),
|
2018-04-09 03:17:40 +01:00
|
|
|
container.PlaceWidget(fakewidget.New(wOpts)),
|
2018-04-06 04:56:36 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2018-04-23 01:05:54 +01:00
|
|
|
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
if err := termdash.Run(ctx, t, c); err != nil {
|
2018-04-06 04:56:36 +02:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|