aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-07-17 10:52:58 +0000
committerFuwn <[email protected]>2022-07-17 10:52:58 +0000
commit3287ca848c1abde039a237fc1af0e48b63a91409 (patch)
tree46c81727200e74bdc78ce3032e4de51fa0d22611
parentdocs(README.md): add gif of usage (diff)
downloadsydney-3287ca848c1abde039a237fc1af0e48b63a91409.tar.xz
sydney-3287ca848c1abde039a237fc1af0e48b63a91409.zip
feat(app.rs): auto obtain terminal width
-rw-r--r--src/app.rs6
-rw-r--r--src/command.rs2
2 files changed, 4 insertions, 4 deletions
diff --git a/src/app.rs b/src/app.rs
index a2f3ffc..a773319 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -37,7 +37,7 @@ pub struct App {
pub response_input: String,
pub accept_response_input: bool,
pub response_input_text: String,
- pub wrap_at: usize,
+ pub wrap_at: u16,
}
impl App {
pub fn new() -> Self {
@@ -57,7 +57,7 @@ impl App {
previous_capsule: None,
accept_response_input: false,
response_input_text: "".to_string(),
- wrap_at: 80,
+ wrap_at: crossterm::terminal::size().unwrap_or((80, 24)).0,
};
app.make_request();
@@ -123,7 +123,7 @@ impl App {
} else {
line
.as_bytes()
- .chunks(self.wrap_at)
+ .chunks(self.wrap_at as usize)
.map(|buf| {
#[allow(unsafe_code)]
unsafe { std::str::from_utf8_unchecked(buf) }.to_string()
diff --git a/src/command.rs b/src/command.rs
index 4dc3615..f17b235 100644
--- a/src/command.rs
+++ b/src/command.rs
@@ -19,7 +19,7 @@ pub enum Command {
Quit,
Open(Option<String>),
Unknown,
- Wrap(usize, Option<String>),
+ Wrap(u16, Option<String>),
}
impl From<String> for Command {
fn from(s: String) -> Self {