mirror of
https://gitlab.redox-os.org/redox-os/redox.git
synced 2026-06-24 22:04:19 +08:00
Merge branch 'tui-scroll' into 'master'
Remove scroll wheel code from TUI See merge request redox-os/redox!2060
This commit is contained in:
commit
1fb7d3d679
@ -13,7 +13,7 @@ use cookbook::recipe::{CookRecipe, recipes_flatten_package_names, recipes_mark_a
|
||||
use cookbook::{Error, staged_pkg};
|
||||
use pkg::{PackageName, PackageState};
|
||||
use ratatui::Terminal;
|
||||
use ratatui::layout::{Constraint, Direction, Layout, Position, Rect};
|
||||
use ratatui::layout::{Constraint, Direction, Layout, Rect};
|
||||
use ratatui::prelude::TermionBackend;
|
||||
use ratatui::style::{Color, Style};
|
||||
use ratatui::text::{Line, Span, Text};
|
||||
@ -30,7 +30,7 @@ use std::sync::{Arc, OnceLock, mpsc};
|
||||
use std::time::{Duration, Instant};
|
||||
use std::{cmp, env, fs};
|
||||
use std::{process, thread};
|
||||
use termion::event::{Event, Key, MouseEvent};
|
||||
use termion::event::{Event, Key};
|
||||
use termion::input::TermRead;
|
||||
use termion::raw::IntoRawMode;
|
||||
use termion::screen::IntoAlternateScreen;
|
||||
@ -976,15 +976,10 @@ struct TuiApp {
|
||||
log_scroll: usize,
|
||||
log_view_job: JobType,
|
||||
auto_scroll: bool,
|
||||
fetch_scroll: usize,
|
||||
cook_scroll: usize,
|
||||
cook_auto_scroll: bool,
|
||||
cook_list_state: ListState,
|
||||
fetch_complete: bool,
|
||||
cook_complete: bool,
|
||||
fetch_panel_rect: Option<Rect>,
|
||||
cook_panel_rect: Option<Rect>,
|
||||
log_panel_rect: Option<Rect>,
|
||||
prompt: Option<FailurePrompt>,
|
||||
dump_logs_anyway: bool,
|
||||
dump_logs_on_exit: Option<(PackageName, String)>,
|
||||
@ -1008,15 +1003,10 @@ impl TuiApp {
|
||||
log_scroll: 0,
|
||||
auto_scroll: true,
|
||||
log_view_job: JobType::Fetch,
|
||||
fetch_scroll: 0,
|
||||
cook_scroll: 0,
|
||||
cook_auto_scroll: true,
|
||||
cook_list_state: ListState::default(),
|
||||
fetch_complete: false,
|
||||
cook_complete: false,
|
||||
fetch_panel_rect: None,
|
||||
cook_panel_rect: None,
|
||||
log_panel_rect: None,
|
||||
prompt: None,
|
||||
dump_logs_anyway: false,
|
||||
dump_logs_on_exit: None,
|
||||
@ -1383,7 +1373,6 @@ fn run_tui_cook(config: CliConfig, recipes: Vec<CookRecipe>) -> Result<TuiApp, c
|
||||
terminal
|
||||
.clear()
|
||||
.map_err(|e| Error::from_io_error(e, "Clearing terminal pty"))?;
|
||||
|
||||
let mut app = TuiApp::new(recipes);
|
||||
|
||||
let spinner = ['-', '\\', '|', '/'];
|
||||
@ -1465,8 +1454,7 @@ fn run_tui_cook(config: CliConfig, recipes: Vec<CookRecipe>) -> Result<TuiApp, c
|
||||
ListItem::new(format!("{icon} {}", r.name)).style(style)
|
||||
})
|
||||
.collect();
|
||||
let total_items = cook_items.len();
|
||||
if app.cook_auto_scroll {
|
||||
{
|
||||
let cooking_index = app
|
||||
.recipes
|
||||
.iter()
|
||||
@ -1486,16 +1474,6 @@ fn run_tui_cook(config: CliConfig, recipes: Vec<CookRecipe>) -> Result<TuiApp, c
|
||||
|
||||
*app.cook_list_state.offset_mut() = new_offset;
|
||||
}
|
||||
} else {
|
||||
app.cook_list_state.select(None);
|
||||
if total_items > 0 {
|
||||
let max_offset = total_items.saturating_sub(panel_height as usize);
|
||||
if *app.cook_list_state.offset_mut() > max_offset {
|
||||
*app.cook_list_state.offset_mut() = max_offset;
|
||||
}
|
||||
} else {
|
||||
*app.cook_list_state.offset_mut() = 0;
|
||||
}
|
||||
}
|
||||
let cook_items: Vec<ListItem> = cook_items[app.cook_scroll..].into();
|
||||
let cook_chunk = chunks[if app.fetch_complete { 0 } else { 1 }];
|
||||
@ -1721,46 +1699,6 @@ fn handle_main_event(app: &mut TuiApp, event: &Event) {
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
|
||||
//FIXME: This does nothing, it seems ratatui handles this itself magically
|
||||
Event::Mouse(mouse_event) => {
|
||||
match mouse_event {
|
||||
MouseEvent::Press(termion::event::MouseButton::WheelUp, x, y) => {
|
||||
// termion is 1-based, ratatui rects are 0-based
|
||||
let pos = Position {
|
||||
x: x.saturating_sub(1),
|
||||
y: y.saturating_sub(1),
|
||||
};
|
||||
|
||||
if app.fetch_panel_rect.map_or(false, |r| r.contains(pos)) {
|
||||
app.fetch_scroll = app.fetch_scroll.saturating_sub(1);
|
||||
} else if app.cook_panel_rect.map_or(false, |r| r.contains(pos)) {
|
||||
app.cook_scroll = app.cook_scroll.saturating_sub(1);
|
||||
app.cook_auto_scroll = false;
|
||||
} else if app.log_panel_rect.map_or(false, |r| r.contains(pos)) {
|
||||
app.auto_scroll = false;
|
||||
app.log_scroll = app.log_scroll.saturating_sub(1);
|
||||
}
|
||||
}
|
||||
MouseEvent::Press(termion::event::MouseButton::WheelDown, x, y) => {
|
||||
let pos = Position {
|
||||
x: x.saturating_sub(1),
|
||||
y: y.saturating_sub(1),
|
||||
};
|
||||
|
||||
if app.fetch_panel_rect.map_or(false, |r| r.contains(pos)) {
|
||||
app.fetch_scroll = app.fetch_scroll.saturating_add(1);
|
||||
} else if app.cook_panel_rect.map_or(false, |r| r.contains(pos)) {
|
||||
app.cook_scroll = app.cook_scroll.saturating_add(1);
|
||||
app.cook_auto_scroll = false;
|
||||
} else if app.log_panel_rect.map_or(false, |r| r.contains(pos)) {
|
||||
app.auto_scroll = false;
|
||||
app.log_scroll = app.log_scroll.saturating_add(1);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user