remove padding, add tasks, focus automatically
This commit is contained in:
parent
900bc2e56e
commit
27227bdfc9
3 changed files with 12 additions and 8 deletions
|
@ -5,4 +5,4 @@ edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
nix = { version = "0.30.1", features = ["term", "process", "fs"], default-features = false }
|
nix = { version = "0.30.1", features = ["term", "process", "fs"], default-features = false }
|
||||||
iced = { version = "0.13.1", features = ["smol"] }
|
iced = { version = "0.13.1", features = ["advanced", "smol"] }
|
||||||
|
|
16
src/lib.rs
16
src/lib.rs
|
@ -1,6 +1,6 @@
|
||||||
use iced::Element;
|
use iced::widget::text_input::Id;
|
||||||
use iced::Font;
|
|
||||||
use iced::widget::{column, row, scrollable, text, text_input};
|
use iced::widget::{column, row, scrollable, text, text_input};
|
||||||
|
use iced::{Element, Font, Task};
|
||||||
|
|
||||||
use nix::pty::{ForkptyResult, forkpty};
|
use nix::pty::{ForkptyResult, forkpty};
|
||||||
use nix::unistd::write;
|
use nix::unistd::write;
|
||||||
|
@ -78,7 +78,7 @@ impl Model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, msg: Msg) {
|
pub fn update(&mut self, msg: Msg) -> Task<Msg> {
|
||||||
match msg {
|
match msg {
|
||||||
Msg::HasInput => {
|
Msg::HasInput => {
|
||||||
let mut write_buffer = self.input.as_bytes().to_vec();
|
let mut write_buffer = self.input.as_bytes().to_vec();
|
||||||
|
@ -91,7 +91,8 @@ impl Model {
|
||||||
Some(red) => self.update_screen_buffer(&red),
|
Some(red) => self.update_screen_buffer(&red),
|
||||||
None => (),
|
None => (),
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
|
iced::widget::text_input::focus::<Msg>(Id::new("text_input"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> Element<'_, Msg> {
|
pub fn view(&self) -> Element<'_, Msg> {
|
||||||
|
@ -110,13 +111,14 @@ impl Model {
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
scrollable(column![
|
scrollable(column![
|
||||||
text(left).font(Font::MONOSPACE),
|
text(left),
|
||||||
row![
|
row![
|
||||||
text(right).font(Font::MONOSPACE),
|
text(right),
|
||||||
text_input("", &self.input)
|
text_input("", &self.input)
|
||||||
.on_input(Msg::InputChanged)
|
.on_input(Msg::InputChanged)
|
||||||
.on_submit(Msg::HasInput)
|
.on_submit(Msg::HasInput)
|
||||||
.font(Font::MONOSPACE)
|
.padding(0)
|
||||||
|
.id(Id::new("text_input"))
|
||||||
]
|
]
|
||||||
])
|
])
|
||||||
.into()
|
.into()
|
||||||
|
|
|
@ -3,6 +3,8 @@ use rust_term::*;
|
||||||
fn main() -> iced::Result {
|
fn main() -> iced::Result {
|
||||||
iced::application("test", Model::update, Model::view)
|
iced::application("test", Model::update, Model::view)
|
||||||
.theme(Model::theme)
|
.theme(Model::theme)
|
||||||
|
.default_font(iced::Font::MONOSPACE)
|
||||||
|
.decorations(false)
|
||||||
.subscription(Model::subscription)
|
.subscription(Model::subscription)
|
||||||
.run()
|
.run()
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue