screen.lua
#!/usr/bin/env lua
local t = require("terminal")
local function main()
local Screen = require("terminal.ui.panel.screen")
local Panel = require("terminal.ui.panel")
local Bar = require("terminal.ui.panel.bar")
local header = Bar {
margin = 1,
padding = 3,
left = {
text = "File",
type = "left",
attr = { fg = "cyan", brightness = "bright" }
},
center = {
text = "Terminal Editor",
type = "right",
attr = { fg = "yellow", brightness = "bright", underline = true }
},
right = {
text = "Help",
type = "drop",
attr = { fg = "green", brightness = "bright" }
},
attr = { bg = "blue" }
}
local footer = Bar {
margin = 0,
padding = 2,
left = {
text = "Status: Ready",
type = "left",
attr = { fg = "white", brightness = "dim" }
},
center = {
text = "Press 'q' to quit",
type = "right",
attr = { fg = "white", brightness = "bright" }
},
right = {
text = "Resize to redraw",
type = "drop",
attr = { fg = "white", brightness = "dim" }
},
attr = { bg = "blue", brightness = "dim" }
}
local body = Panel {
content = function(self, row, col, height, width)
for i = 1, height do
t.cursor.position.set(row + i - 1, col)
t.output.write(
string.format("Body content line %d of %d", i, height),
t.clear.eol_seq()
)
end
end
}
local screen = Screen {
header = header,
body = body,
footer = footer,
name = "ExampleScreen"
}
screen:calculate_layout()
screen:render()
while true do
local input = t.input.readansi(0.2)
if input == "q" then
break
elseif input == nil then screen:check_resize(true)
end
end
end
t.initwrap(main, {
displaybackup = true,
filehandle = io.stdout,
})()
print("done!")