-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ilya Shvyryalkin
committed
Dec 14, 2024
1 parent
d31c54c
commit 6f5c449
Showing
8 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "custom_cmd" | ||
version = "0.5.1" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
iced = "0.13.1" | ||
iced_term = { path = "../../" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Fullscreen example | ||
|
||
Example of basic ICED app with using iced_term widget. | ||
|
||
 |
Binary file added
BIN
+1.95 MB
examples/custom_cmd/assets/fonts/JetBrains/JetBrainsMonoNerdFontMono-Bold.ttf
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
use iced::advanced::graphics::core::Element; | ||
use iced::font::{Family, Stretch, Weight}; | ||
use iced::widget::container; | ||
use iced::{Font, Length, Size, Subscription, Task, Theme}; | ||
use iced_term::TerminalView; | ||
|
||
fn main() -> iced::Result { | ||
iced::application(App::title, App::update, App::view) | ||
.antialiasing(false) | ||
.window_size(Size { | ||
width: 1280.0, | ||
height: 720.0, | ||
}) | ||
.subscription(App::subscription) | ||
.run_with(App::new) | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum Event { | ||
Terminal(iced_term::Event), | ||
} | ||
|
||
struct App { | ||
title: String, | ||
term: iced_term::Terminal, | ||
} | ||
|
||
impl App { | ||
fn new() -> (Self, Task<Event>) { | ||
let system_shell = std::env::var("SHELL") | ||
.expect("SHELL variable is not defined") | ||
.to_string(); | ||
let term_id = 0; | ||
let term_settings = iced_term::settings::Settings { | ||
font: iced_term::settings::FontSettings { | ||
size: 14.0, | ||
font_type: Font { | ||
weight: Weight::Bold, | ||
family: Family::Name("JetBrainsMono Nerd Font Mono"), | ||
stretch: Stretch::Normal, | ||
..Default::default() | ||
}, | ||
..Default::default() | ||
}, | ||
theme: iced_term::settings::ThemeSettings::default(), | ||
backend: iced_term::settings::BackendSettings { | ||
cmd: "echo".to_string(), | ||
args: vec!["101".to_string()] | ||
}, | ||
}; | ||
|
||
( | ||
Self { | ||
title: String::from("custom_cmd"), | ||
term: iced_term::Terminal::new(term_id, term_settings), | ||
}, | ||
Task::none(), | ||
) | ||
} | ||
|
||
fn title(&self) -> String { | ||
self.title.clone() | ||
} | ||
|
||
fn subscription(&self) -> Subscription<Event> { | ||
let term_subscription = iced_term::Subscription::new(self.term.id); | ||
let term_event_stream = term_subscription.event_stream(); | ||
Subscription::run_with_id(self.term.id, term_event_stream) | ||
.map(Event::Terminal) | ||
} | ||
|
||
fn update(&mut self, event: Event) -> Task<Event> { | ||
println!("{:?}", event); | ||
match event { | ||
Event::Terminal(iced_term::Event::CommandReceived(_, cmd)) => { | ||
match self.term.update(cmd) { | ||
iced_term::actions::Action::ChangeTitle(title) => { | ||
self.title = title; | ||
Task::none() | ||
}, | ||
_ => Task::none(), | ||
} | ||
}, | ||
} | ||
} | ||
|
||
fn view(&self) -> Element<Event, Theme, iced::Renderer> { | ||
container(TerminalView::show(&self.term).map(Event::Terminal)) | ||
.width(Length::Fill) | ||
.height(Length::Fill) | ||
.into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters