Files
endorphin-tessera-gui/examples/async-file.endor
2026-10-23 12:06:44 +08:00

23 lines
765 B
Plaintext

class FileReader {
output: TextBlock
problem: TextBlock
status: TextBlock
task: Object
function apply(self: FileReader): Unit {
self.output.text = self.task.result()
}
function read(self: FileReader, path: String): Unit {
self.task = ui.readText(self, "file", path, self.apply)
self.output.text = ""
self.status.bind("text", self.task.status)
self.problem.bind("text", self.task.error)
}
}
output = TextBlock("尚未读取文件")
problem = TextBlock("")
status = TextBlock("")
reader = FileReader(output, problem, status, ui.state(0))
page = Page()
page.title = "异步文件"
page.render(Column(24,16,TextBlock("在 REPL 调用 reader.read(绝对路径字符串)",2),status,output,problem))