Skip to content

Commit

Permalink
Merge pull request #48 from ckaznable/ratatui
Browse files Browse the repository at this point in the history
Update Ratatui version
  • Loading branch information
ckaznable authored Jun 24, 2024
2 parents 4bd40f9 + 40a46ee commit af4bddd
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 43 deletions.
63 changes: 45 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ version = "1.12.2"
edition = "2021"

[dependencies]
ratatui = "=0.26.2"
ratatui = "=0.27.0"
tui-input = "=0.8.0"
crossterm = "=0.27.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sys-locale = "0.3.1"
lazy_static = "1.4"
clap = { version = "4.4.7", features = ["derive"] }
regex = "1.10.2"
textwrap = "0.16.0"
ansi-to-tui = "=3.1.0"
ansi-to-tui = "4.0.1"
anyhow = "1.0.79"
xdg = "2.5.2"

Expand Down
2 changes: 1 addition & 1 deletion src/keybinding.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
use tui_input::backend::crossterm::EventHandler;

use crate::state::{AppState, InputMode};
Expand Down
12 changes: 6 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ use std::{
use xdg::BaseDirectories;

use clap::Parser;
use crossterm::{
event::{self, DisableMouseCapture, Event},
execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
};
use poketex::{
env::DEF_LOCALES,
keybinding::handle_key,
Expand All @@ -24,6 +19,11 @@ use poketex::{
state::{AppState, PokemonListState},
ui::ui,
};
use ratatui::crossterm::{
event::{self, DisableMouseCapture, Event},
execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
};
use ratatui::{
backend::{Backend, CrosstermBackend},
Terminal,
Expand Down Expand Up @@ -58,7 +58,7 @@ impl Tui {
impl Drop for Tui {
fn drop(&mut self) {
// restore terminal
if crossterm::terminal::is_raw_mode_enabled().unwrap() {
if ratatui::crossterm::terminal::is_raw_mode_enabled().unwrap() {
let _ = execute!(
self.terminal.backend_mut(),
LeaveAlternateScreen,
Expand Down
6 changes: 3 additions & 3 deletions src/state/pokemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl PokemonListState {
let list_scrollbar_state = ScrollbarState::default().content_length(pokemon_len);

let mut list_state = ListState::default();
list_state.select(Some(0));
list_state.select_first();

let filtered_list = Vec::with_capacity(pokemon_len);

Expand Down Expand Up @@ -69,7 +69,7 @@ impl PokemonListState {
}

pub fn scroll_to_first(&mut self) {
self.select(0)
self.list_state.select_first();
}

pub fn scroll_to_end(&mut self) {
Expand Down Expand Up @@ -138,7 +138,7 @@ impl PokemonListState {
}

pub fn set_list_filter(&mut self, filter: String) {
self.filter_query = filter.clone();
self.filter_query.clone_from(&filter);

if !filter.is_empty() {
self.filtered_list.clear();
Expand Down
24 changes: 12 additions & 12 deletions src/widget/profile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ impl StatefulWidget for PokemonProfileWidget {
ascii_form.to_string()
};

let (ansi_width, ansi_height, ansi) = match std::fs::read(
let (ansi_width, ansi_height, ansi) = std::fs::read(
state
.get_assets_path(ascii_type)
.join(lowercase_name + &ascii_form),
) {
Err(_) => (0u16, 0u16, None),
Ok(buffer) => match buffer.into_text() {
Ok(ansi) => (
ansi.width() as u16 + 1,
ansi.height() as u16 + 1,
Some(ansi),
),
Err(_) => (0u16, 0u16, None),
},
};
)
.map(|buffer| buffer.into_text().ok())
.ok()
.flatten()
.map_or((0u16, 0u16, None), |ansi| {
(
ansi.width() as u16 + 1,
ansi.height() as u16 + 1,
Some(ansi),
)
});

let [overview, _, main, _, ability_bottom_area, region_form_navigation] =
Layout::vertical([
Expand Down

0 comments on commit af4bddd

Please sign in to comment.