Skip to content

Commit 94b0179

Browse files
authored
make widget from POC (#1)
Was added widget implementation Were added 2 examples (full_screen and split_view)
1 parent 194b5d9 commit 94b0179

27 files changed

+2273
-1389
lines changed

Cargo.lock

+1,197-1,060
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
[workspace]
2+
members = ["examples/*"]
3+
14
[package]
2-
name = "iced-alacritty"
5+
name = "iced_term"
36
version = "0.1.0"
47
edition = "2021"
58

69
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
710

811
[dependencies]
9-
alacritty_terminal = "0.18.0"
10-
iced = { version = "0.8.0", features = ["smol", "tokio", "canvas", "wgpu"] }
11-
iced_native = "0.9.1"
12-
iced_graphics = "0.8.0"
12+
alacritty_terminal = "0.20.0"
13+
iced = { version = "0.10.0", features = ["smol", "tokio", "canvas", "wgpu", "lazy", "advanced"] }
14+
tokio = { version = "1.23.0", features = ["full"]}
15+
iced_graphics = "0.9.0"
16+
iced_tiny_skia = "0.1.0"
17+
iced_native = "0.10.3"

LICENSE

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Copyright 2019 Héctor Ramón, Iced contributors
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7+
the Software, and to permit persons to whom the Software is furnished to do so,
8+
subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Terminal emulator widget based on ICED fraemwork.

clippy.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
too-many-arguments-threshold = 20
2+
enum-variant-name-threshold = 10

examples/full_screen/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "full_screen"
3+
version = "0.10.1"
4+
edition = "2021"
5+
publish = false
6+
7+
[dependencies]
8+
iced = "0.10.0"
9+
iced_term = { path = "../../" }

examples/full_screen/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Fullscreen example
2+
3+
Example of basic ICED app with using iced_term widget.
4+
5+
![screenshot](./assets/screenshot.png)
61.1 KB
Loading

examples/full_screen/src/main.rs

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
use iced::advanced::graphics::core::Element;
2+
use iced::widget::container;
3+
use iced::{
4+
executor, window, Application, Command, Length, Settings, Subscription,
5+
Theme,
6+
};
7+
use iced_term::{self, BackendSettings, FontSettings, Term, TermSettings};
8+
use std::collections::HashMap;
9+
10+
fn main() -> iced::Result {
11+
App::run(Settings {
12+
antialiasing: true,
13+
window: window::Settings {
14+
size: (800, 600),
15+
..window::Settings::default()
16+
},
17+
..Settings::default()
18+
})
19+
}
20+
21+
#[derive(Debug, Clone)]
22+
pub enum Message {
23+
TermEvent(iced_term::Event),
24+
}
25+
26+
struct App {
27+
tabs: HashMap<u64, Term>,
28+
}
29+
30+
impl Application for App {
31+
type Message = Message;
32+
type Theme = Theme;
33+
type Executor = executor::Default;
34+
type Flags = ();
35+
36+
fn new(_flags: ()) -> (Self, Command<Message>) {
37+
let system_shell = env!("SHELL");
38+
let tab_id = 0;
39+
let tab = iced_term::Term::new(
40+
tab_id,
41+
TermSettings {
42+
font: FontSettings { size: 14.0 },
43+
backend: BackendSettings {
44+
shell: system_shell.to_string(),
45+
..BackendSettings::default()
46+
},
47+
},
48+
);
49+
let mut tabs = HashMap::new();
50+
tabs.insert(tab_id, tab);
51+
(Self { tabs }, Command::none())
52+
}
53+
54+
fn title(&self) -> String {
55+
String::from("Terminal app")
56+
}
57+
58+
fn update(&mut self, message: Self::Message) -> iced::Command<Message> {
59+
match message {
60+
Message::TermEvent(event) => {
61+
match event {
62+
iced_term::Event::InputReceived(id, c) => {
63+
let tab = self
64+
.tabs
65+
.get_mut(&id)
66+
.expect("tab with target id not found");
67+
tab.update(iced_term::Command::WriteToPTY(c))
68+
},
69+
iced_term::Event::DataUpdated(id, data) => {
70+
let tab = self
71+
.tabs
72+
.get_mut(&id)
73+
.expect("tab with target id not found");
74+
tab.update(iced_term::Command::RenderData(data))
75+
},
76+
iced_term::Event::ContainerScrolled(id, delta) => {
77+
let tab = self
78+
.tabs
79+
.get_mut(&id)
80+
.expect("tab with target id not found");
81+
tab.update(iced_term::Command::Scroll(delta as i32))
82+
},
83+
iced_term::Event::Resized(id, size) => {
84+
let tab = self
85+
.tabs
86+
.get_mut(&id)
87+
.expect("tab with target id not found");
88+
tab.update(iced_term::Command::Resize(size));
89+
},
90+
_ => {},
91+
};
92+
93+
Command::none()
94+
},
95+
}
96+
}
97+
98+
fn subscription(&self) -> Subscription<Message> {
99+
let mut sb = vec![];
100+
for id in self.tabs.keys() {
101+
let tab = self.tabs.get(id).unwrap();
102+
let sub = tab.data_subscription().map(Message::TermEvent);
103+
104+
sb.push(sub)
105+
}
106+
107+
Subscription::batch(sb)
108+
}
109+
110+
fn view(&self) -> Element<Message, iced::Renderer> {
111+
let tab_id = 0;
112+
let tab = self
113+
.tabs
114+
.get(&tab_id)
115+
.expect("tab with target id not found");
116+
117+
let tab_view = tab.view().map(Message::TermEvent);
118+
119+
container(tab_view)
120+
.width(Length::Fill)
121+
.height(Length::Fill)
122+
.into()
123+
}
124+
}

examples/split_view/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "split_view"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
iced = { version = "0.10.0", features = ["debug", "lazy"] }
8+
iced_term = { path = "../../" }

examples/split_view/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SplitView example
2+
3+
Example of basic ICED app with using iced_term inside the pane grid widget.
4+
5+
![screenshot](./assets/screenshot.png)
404 KB
Loading

0 commit comments

Comments
 (0)