mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Error popup message height is now calculated based on the content it must display
This commit is contained in:
committed by
Christian Visintin
parent
587d7da2cb
commit
6559c6b083
@@ -40,6 +40,7 @@ Released on FIXME:
|
|||||||
- **Ui**:
|
- **Ui**:
|
||||||
- Transfer abortion is now more responsive
|
- Transfer abortion is now more responsive
|
||||||
- Selected files will now be rendered with **Reversed, underlined and italic** text modifiers instead of being prepended with `*`.
|
- Selected files will now be rendered with **Reversed, underlined and italic** text modifiers instead of being prepended with `*`.
|
||||||
|
- Error popup message height is now calculated based on the content it must display.
|
||||||
- **Midnight commander keys**
|
- **Midnight commander keys**
|
||||||
- `<F1>`: Show help
|
- `<F1>`: Show help
|
||||||
- `<F2>`: Save file as (actually I invented this)
|
- `<F2>`: Save file as (actually I invented this)
|
||||||
@@ -74,7 +75,8 @@ Released on FIXME:
|
|||||||
- By default the log level is now set to `INFO`
|
- By default the log level is now set to `INFO`
|
||||||
- It is now possible to enable the `TRACE` level with the `-D` CLI option.
|
- It is now possible to enable the `TRACE` level with the `-D` CLI option.
|
||||||
- Dependencies:
|
- Dependencies:
|
||||||
- Updated `tui-realm` to `1.3.0`
|
- Added `unicode-width 0.1.8`
|
||||||
|
- Updated `tui-realm` to `1.4.2`
|
||||||
- Updated `tui-realm-stdlib` to `1.1.4`
|
- Updated `tui-realm-stdlib` to `1.1.4`
|
||||||
- Removed `rust-s3`, `ssh2`, `suppaftp`; replaced by `remotefs 0.2.0`, `remotefs-aws-s3 0.1.0`, `remotefs-ftp 0.1.0` and `remotefs-ssh 0.1.0`
|
- Removed `rust-s3`, `ssh2`, `suppaftp`; replaced by `remotefs 0.2.0`, `remotefs-aws-s3 0.1.0`, `remotefs-ftp 0.1.0` and `remotefs-ssh 0.1.0`
|
||||||
- Removed `crossterm` (since bridged by tui-realm)
|
- Removed `crossterm` (since bridged by tui-realm)
|
||||||
|
|||||||
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -2288,6 +2288,7 @@ dependencies = [
|
|||||||
"toml",
|
"toml",
|
||||||
"tui-realm-stdlib",
|
"tui-realm-stdlib",
|
||||||
"tuirealm",
|
"tuirealm",
|
||||||
|
"unicode-width",
|
||||||
"users",
|
"users",
|
||||||
"whoami",
|
"whoami",
|
||||||
"wildmatch",
|
"wildmatch",
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ thiserror = "^1.0.0"
|
|||||||
toml = "0.5.8"
|
toml = "0.5.8"
|
||||||
tui-realm-stdlib = "^1.1.0"
|
tui-realm-stdlib = "^1.1.0"
|
||||||
tuirealm = "^1.2.0"
|
tuirealm = "^1.2.0"
|
||||||
|
unicode-width = "^0.1.8"
|
||||||
whoami = "1.1.1"
|
whoami = "1.1.1"
|
||||||
wildmatch = "2.0.0"
|
wildmatch = "2.0.0"
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ use tuirealm::event::{Key, KeyEvent, KeyModifiers};
|
|||||||
use tuirealm::tui::layout::{Constraint, Direction, Layout};
|
use tuirealm::tui::layout::{Constraint, Direction, Layout};
|
||||||
use tuirealm::tui::widgets::Clear;
|
use tuirealm::tui::widgets::Clear;
|
||||||
use tuirealm::{Sub, SubClause, SubEventClause};
|
use tuirealm::{Sub, SubClause, SubEventClause};
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
impl FileTransferActivity {
|
impl FileTransferActivity {
|
||||||
// -- init
|
// -- init
|
||||||
@@ -292,12 +293,22 @@ impl FileTransferActivity {
|
|||||||
// make popup
|
// make popup
|
||||||
self.app.view(&Id::SortingPopup, f, popup);
|
self.app.view(&Id::SortingPopup, f, popup);
|
||||||
} else if self.app.mounted(&Id::ErrorPopup) {
|
} else if self.app.mounted(&Id::ErrorPopup) {
|
||||||
let popup = draw_area_in(f.size(), 50, 10);
|
// TODO: inject dynamic height here
|
||||||
|
let popup = draw_area_in(
|
||||||
|
f.size(),
|
||||||
|
50,
|
||||||
|
self.calc_popup_height(Id::ErrorPopup, f.size().width, f.size().height),
|
||||||
|
);
|
||||||
f.render_widget(Clear, popup);
|
f.render_widget(Clear, popup);
|
||||||
// make popup
|
// make popup
|
||||||
self.app.view(&Id::ErrorPopup, f, popup);
|
self.app.view(&Id::ErrorPopup, f, popup);
|
||||||
} else if self.app.mounted(&Id::FatalPopup) {
|
} else if self.app.mounted(&Id::FatalPopup) {
|
||||||
let popup = draw_area_in(f.size(), 50, 10);
|
// TODO: inject dynamic height here
|
||||||
|
let popup = draw_area_in(
|
||||||
|
f.size(),
|
||||||
|
50,
|
||||||
|
self.calc_popup_height(Id::FatalPopup, f.size().width, f.size().height),
|
||||||
|
);
|
||||||
f.render_widget(Clear, popup);
|
f.render_widget(Clear, popup);
|
||||||
// make popup
|
// make popup
|
||||||
self.app.view(&Id::FatalPopup, f, popup);
|
self.app.view(&Id::FatalPopup, f, popup);
|
||||||
@@ -854,6 +865,39 @@ impl FileTransferActivity {
|
|||||||
let _ = self.app.umount(&Id::KeybindingsPopup);
|
let _ = self.app.umount(&Id::KeybindingsPopup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -- dynamic size
|
||||||
|
|
||||||
|
/// Given the id of the component to display and the width and height of the total area,
|
||||||
|
/// returns the height in percentage to the entire area height, that the popup should have
|
||||||
|
fn calc_popup_height(&self, id: Id, width: u16, height: u16) -> u16 {
|
||||||
|
// Get current text width
|
||||||
|
let text_width = self
|
||||||
|
.app
|
||||||
|
.query(&id, tuirealm::Attribute::Text)
|
||||||
|
.ok()
|
||||||
|
.flatten()
|
||||||
|
.map(|x| {
|
||||||
|
x.unwrap_payload()
|
||||||
|
.unwrap_vec()
|
||||||
|
.into_iter()
|
||||||
|
.map(|x| x.unwrap_text_span().content)
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join("")
|
||||||
|
.width() as u16
|
||||||
|
})
|
||||||
|
.unwrap_or(0);
|
||||||
|
// Calc real width of a row in the popup
|
||||||
|
let row_width = (width / 2).saturating_sub(2);
|
||||||
|
// Calc row height in percentage (1 : height = x : 100)
|
||||||
|
let row_height_p = (100.0 / (height as f64)).ceil() as u16;
|
||||||
|
// Get amount of required rows NOTE: + 2 because of margins
|
||||||
|
let display_rows = ((text_width as f64) / (row_width as f64)).ceil() as u16 + 2;
|
||||||
|
// Return height (row_height_p * display_rows)
|
||||||
|
display_rows * row_height_p
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- global listener
|
||||||
|
|
||||||
fn mount_global_listener(&mut self) {
|
fn mount_global_listener(&mut self) {
|
||||||
assert!(self
|
assert!(self
|
||||||
.app
|
.app
|
||||||
|
|||||||
Reference in New Issue
Block a user