-
Notifications
You must be signed in to change notification settings - Fork 11
/
LayoutExample.scala
35 lines (30 loc) · 1.09 KB
/
LayoutExample.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package tuiexamples
import tui._
import tui.crossterm.CrosstermJni
import tui.widgets._
object LayoutExample {
def main(args: Array[String]): Unit = withTerminal((jni, terminal) => run_app(terminal, jni))
def run_app(terminal: Terminal, jni: CrosstermJni): Unit =
while (true) {
terminal.draw(f => ui(f))
jni.read() match {
case key: tui.crossterm.Event.Key =>
key.keyEvent.code match {
case char: tui.crossterm.KeyCode.Char if char.c() == 'q' => return
case _ => ()
}
case _ => ()
}
}
def ui(f: Frame): Unit = {
val chunks = Layout(
direction = Direction.Vertical,
constraints = Array(Constraint.Percentage(10), Constraint.Percentage(80), Constraint.Percentage(10))
)
.split(f.size)
val block0 = BlockWidget(title = Some(Spans.nostyle("Block")), borders = Borders.ALL)
f.renderWidget(block0, chunks(0))
val block1 = BlockWidget(title = Some(Spans.nostyle("Block 2")), borders = Borders.ALL)
f.renderWidget(block1, chunks(2))
}
}