static void text_screen_scroll(struct text_screen *screen, int key) { int win_lines = getmaxy(screen->scr.sub_ncw); int win_cols = getmaxx(screen->scr.sub_ncw) - 1; int delta, len, i; if (key == KEY_UP) delta = -1; else if (key == KEY_DOWN) delta = 1; else return; if (screen->scroll_y + delta < 0) return; if (screen->scroll_y + delta + win_lines > screen->n_lines) return; screen->scroll_y += delta; wscrl(screen->scr.sub_ncw, delta); if (delta > 0) { i = screen->scroll_y + win_lines - 1; len = strncols(screen->lines[i]) > win_cols ? win_cols : -1; mvwaddnstr(screen->scr.sub_ncw, win_lines - 1, 1, screen->lines[i], len); } else if (delta < 0) { i = screen->scroll_y; len = strncols(screen->lines[i]) > win_cols ? win_cols : -1; mvwaddnstr(screen->scr.sub_ncw, 0, 1, screen->lines[i], len); } wrefresh(screen->scr.sub_ncw); }
void text_screen_draw(struct text_screen *screen) { int max_y, max_x, i, len; max_y = getmaxy(screen->scr.sub_ncw); max_x = getmaxx(screen->scr.sub_ncw) - 1; max_y = min(max_y, screen->scroll_y + screen->n_lines); for (i = screen->scroll_y; i < max_y; i++) { len = strncols(screen->lines[i]) > max_x ? max_x : -1; mvwaddnstr(screen->scr.sub_ncw, i, 1, screen->lines[i], len); } wrefresh(screen->scr.sub_ncw); }
struct boot_editor *boot_editor_init(struct cui *cui, struct pmenu_item *item, const struct system_info *sysinfo, void (*on_exit)(struct cui *cui, struct pmenu_item *item, struct pb_boot_data *bd)) { struct boot_editor *boot_editor; boot_editor = talloc_zero(cui, struct boot_editor); if (!boot_editor) return NULL; talloc_set_destructor(boot_editor, boot_editor_destructor); boot_editor->cui = cui; boot_editor->item = item; boot_editor->on_exit = on_exit; boot_editor->state = STATE_EDIT; boot_editor->need_redraw = false; boot_editor->need_update = false; int ncols1 = strncols(_("Device tree:")); int ncols2 = strncols(_("Boot arguments:")); boot_editor->label_x = 1; boot_editor->field_x = 2 + max(ncols1, ncols2); nc_scr_init(&boot_editor->scr, pb_boot_editor_sig, 0, cui, boot_editor_process_key, boot_editor_post, boot_editor_unpost, boot_editor_resize); boot_editor->scr.frame.ltitle = talloc_strdup(boot_editor, _("Petitboot Option Editor")); boot_editor->scr.frame.rtitle = NULL; boot_editor->scr.frame.help = talloc_strdup(boot_editor, _("tab=next, shift+tab=previous, x=exit, h=help")); nc_scr_frame_draw(&boot_editor->scr); if (item) { struct pb_boot_data *bd = cod_from_item(item)->bd; boot_editor->image = bd->image; boot_editor->initrd = bd->initrd; boot_editor->dtb = bd->dtb; boot_editor->args = bd->args; boot_editor_find_device(boot_editor, bd, sysinfo); } else { boot_editor->image = boot_editor->initrd = boot_editor->dtb = boot_editor->args = ""; } boot_editor->pad = newpad( pad_height(sysinfo ? sysinfo->n_blockdevs : 0), COLS); boot_editor_setup_widgets(boot_editor, sysinfo); boot_editor_layout_widgets(boot_editor); wrefresh(boot_editor->scr.main_ncw); return boot_editor; }