{
"id": "275",
"prompt": "Fetch a plain-text URL and put the text on screen. rustlite can't read fetched bytes back out of memory (read_body's out pointer needs a writable buffer the language can't produce), so use the host-held path: http::body_lines(handle) counts the newline-delimited lines and http::draw_line(handle, line, x, y, rgb, scale) rasterizes one straight from the host's copy. Show the first 14 lines once ready, a blinking FETCHING state before that, and the total line count in a footer.",
"solution_rl": "fn frame(t: i32) {\n host::display::clear(0x101018);\n if host::display::state_get(0) == 0 {\n let h: i32 = host::http::get(\"https://example.com/robots.txt\", 30);\n host::display::state_set(1, h);\n if h < 0 {\n host::display::state_set(0, 3);\n } else {\n host::display::state_set(0, 1);\n }\n }\n let h2: i32 = host::display::state_get(1);\n if host::display::state_get(0) == 1 {\n let r: i32 = host::http::ready(h2);\n if r == 1 {\n host::display::state_set(0, 2);\n } else if r < 0 {\n host::display::state_set(0, 3);\n }\n }\n let phase: i32 = host::display::state_get(0);\n host::display::draw_string(8, 8, \"TEXT VIEWER\", 0xffffff, 2);\n host::display::fill_rect(0, 30, 512, 2, 0x333333);\n if phase == 1 {\n host::display::draw_string(8, 60, \"FETCHING\", 0xaa7700, 1);\n if (t / 20) % 2 == 0 {\n host::display::fill_rect(70, 58, 8, 8, 0xaa7700);\n }\n } else if phase == 2 {\n let total: i32 = host::http::body_lines(h2);\n let mut n: i32 = total;\n if n > 14 {\n n = 14;\n }\n for i in 0..n {\n host::http::draw_line(h2, i, 8, 48 + i * 14, 0xcccccc, 1);\n }\n host::display::draw_string(8, 480, \"LINES\", 0x888888, 1);\n host::display::draw_number(56, 478, total, 0xffffff, 1);\n } else {\n host::display::draw_string(8, 60, \"FETCH FAILED\", 0xbb3333, 2);\n }\n host::display::present();\n}\n",
"tags": [
"http",
"text",
"viewer"
]
}