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]
|
||||
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::Font;
|
||||
use iced::widget::text_input::Id;
|
||||
use iced::widget::{column, row, scrollable, text, text_input};
|
||||
use iced::{Element, Font, Task};
|
||||
|
||||
use nix::pty::{ForkptyResult, forkpty};
|
||||
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 {
|
||||
Msg::HasInput => {
|
||||
let mut write_buffer = self.input.as_bytes().to_vec();
|
||||
|
@ -91,7 +91,8 @@ impl Model {
|
|||
Some(red) => self.update_screen_buffer(&red),
|
||||
None => (),
|
||||
},
|
||||
}
|
||||
};
|
||||
iced::widget::text_input::focus::<Msg>(Id::new("text_input"))
|
||||
}
|
||||
|
||||
pub fn view(&self) -> Element<'_, Msg> {
|
||||
|
@ -110,13 +111,14 @@ impl Model {
|
|||
),
|
||||
};
|
||||
scrollable(column![
|
||||
text(left).font(Font::MONOSPACE),
|
||||
text(left),
|
||||
row![
|
||||
text(right).font(Font::MONOSPACE),
|
||||
text(right),
|
||||
text_input("", &self.input)
|
||||
.on_input(Msg::InputChanged)
|
||||
.on_submit(Msg::HasInput)
|
||||
.font(Font::MONOSPACE)
|
||||
.padding(0)
|
||||
.id(Id::new("text_input"))
|
||||
]
|
||||
])
|
||||
.into()
|
||||
|
|
|
@ -3,6 +3,8 @@ use rust_term::*;
|
|||
fn main() -> iced::Result {
|
||||
iced::application("test", Model::update, Model::view)
|
||||
.theme(Model::theme)
|
||||
.default_font(iced::Font::MONOSPACE)
|
||||
.decorations(false)
|
||||
.subscription(Model::subscription)
|
||||
.run()
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue