chore: tui enhancements
d7e6cc19
1 file(s) · +36 −8
| 366 | 366 | ); |
|
| 367 | 367 | frame.render_widget(content_input, form_layout[1]); |
|
| 368 | 368 | ||
| 369 | + | match app.focus { |
|
| 370 | + | Focus::CreateName => { |
|
| 371 | + | let x = form_layout[0].x + 1 + app.create_name.len() as u16; |
|
| 372 | + | let y = form_layout[0].y + 1; |
|
| 373 | + | frame.set_cursor_position((x, y)); |
|
| 374 | + | } |
|
| 375 | + | Focus::CreateContent => { |
|
| 376 | + | let last_line = app.create_content.lines().last().unwrap_or(""); |
|
| 377 | + | let line_count = app.create_content.lines().count() |
|
| 378 | + | + if app.create_content.ends_with('\n') { |
|
| 379 | + | 1 |
|
| 380 | + | } else { |
|
| 381 | + | 0 |
|
| 382 | + | }; |
|
| 383 | + | let y_offset = if line_count == 0 { 0 } else { line_count - 1 }; |
|
| 384 | + | let x = form_layout[1].x |
|
| 385 | + | + 1 |
|
| 386 | + | + if app.create_content.ends_with('\n') { |
|
| 387 | + | 0 |
|
| 388 | + | } else { |
|
| 389 | + | last_line.len() as u16 |
|
| 390 | + | }; |
|
| 391 | + | let y = form_layout[1].y + 1 + y_offset as u16; |
|
| 392 | + | frame.set_cursor_position((x, y)); |
|
| 393 | + | } |
|
| 394 | + | _ => {} |
|
| 395 | + | } |
|
| 396 | + | ||
| 369 | 397 | let hint = Paragraph::new(Line::from(vec![ |
|
| 370 | - | Span::styled("Enter", Style::default().fg(Color::Yellow)), |
|
| 371 | - | Span::raw(match app.focus { |
|
| 372 | - | Focus::CreateName => " next field ", |
|
| 373 | - | _ => " newline ", |
|
| 374 | - | }), |
|
| 398 | + | Span::styled("Tab", Style::default().fg(Color::Yellow)), |
|
| 399 | + | Span::raw(" switch field "), |
|
| 375 | 400 | Span::styled("Ctrl+S", Style::default().fg(Color::Yellow)), |
|
| 376 | 401 | Span::raw(" save "), |
|
| 377 | 402 | Span::styled("Esc", Style::default().fg(Color::Yellow)), |
|
| 548 | 573 | KeyCode::Char('c') => app.start_create(), |
|
| 549 | 574 | KeyCode::Char('r') if app.is_remote => app.refresh(backend), |
|
| 550 | 575 | KeyCode::Char('?') => app.show_help = true, |
|
| 551 | - | KeyCode::Enter => { |
|
| 576 | + | KeyCode::Enter | KeyCode::Char('l') => { |
|
| 552 | 577 | if app.selected_snippet().is_some() { |
|
| 553 | 578 | app.focus = Focus::Content; |
|
| 554 | 579 | } |
|
| 556 | 581 | _ => {} |
|
| 557 | 582 | }, |
|
| 558 | 583 | Focus::Content => match key.code { |
|
| 559 | - | KeyCode::Char(' ') | KeyCode::Esc | KeyCode::Char('q') => { |
|
| 584 | + | KeyCode::Char(' ') | KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('h') => { |
|
| 560 | 585 | app.focus = Focus::List; |
|
| 561 | 586 | } |
|
| 562 | 587 | KeyCode::Char('j') | KeyCode::Down => { |
|
| 575 | 600 | } else { |
|
| 576 | 601 | match key.code { |
|
| 577 | 602 | KeyCode::Esc => app.cancel_create(), |
|
| 578 | - | KeyCode::Enter => app.focus = Focus::CreateContent, |
|
| 603 | + | KeyCode::Enter | KeyCode::Tab => { |
|
| 604 | + | app.focus = Focus::CreateContent |
|
| 605 | + | } |
|
| 579 | 606 | KeyCode::Backspace => { |
|
| 580 | 607 | app.create_name.pop(); |
|
| 581 | 608 | } |
|
| 592 | 619 | } else { |
|
| 593 | 620 | match key.code { |
|
| 594 | 621 | KeyCode::Esc => app.cancel_create(), |
|
| 622 | + | KeyCode::Tab => app.focus = Focus::CreateName, |
|
| 595 | 623 | KeyCode::Enter => app.create_content.push('\n'), |
|
| 596 | 624 | KeyCode::Backspace => { |
|
| 597 | 625 | app.create_content.pop(); |
|