Skip to content

Commit 6725882

Browse files
authored
Merge pull request #130 from togglebyte/dev
0.2.8
2 parents e931105 + dbc9f95 commit 6725882

File tree

52 files changed

+1123
-624
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1123
-624
lines changed

CHANGES.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
* 0.2.8
2+
* An emitter can be created before the runtime
3+
* Messages can be emitted to both widget ids and component ids
4+
* Feature flag: `serde` is now a feature flag that adds `Serialize` / `Deserialize` to `WidgetId`
5+
* There is now a distinction between `global`s and `local`s
6+
* BUGFIX: ctrl+c works with the error display
7+
* Trying to use a component twice will now include the component name in the
8+
error
9+
* Global definitions will raise an error if it's already assigned
110
* 0.2.7
211
* BUGFIX: use correct truthiness check in control flow update
312
* 0.2.6

Cargo.toml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "anathema"
33
edition = "2024"
4-
version = "0.2.7"
4+
version = "0.2.8"
55
license = "MIT"
66
description = "Create beautiful, easily customisable terminal applications"
77
keywords = ["tui", "terminal", "widgets", "ui", "layout"]
@@ -31,31 +31,32 @@ anathema-testutils = { path = "anathema-testutils" }
3131
[features]
3232
default = []
3333
profile = ["anathema-runtime/profile", "anathema-widgets/profile", "anathema-backend/profile"]
34+
serde = ["anathema-store/serde"]
3435
# filelog = ["anathema-debug/filelog", "anathema-widgets/filelog", "anathema-runtime/filelog"]
3536

3637
[lints]
3738
workspace = true
3839

3940
[workspace.package]
4041
edition = "2024"
41-
version = "0.2.7"
42+
version = "0.2.8"
4243

4344
[workspace.dependencies]
4445
bitflags = "2.4.1"
4546
crossterm = "0.28.1"
4647
unicode-width = "0.1.11"
4748
flume = "0.11.0"
4849
notify = "6.1.1"
49-
anathema-default-widgets = { path = "./anathema-default-widgets", version = "0.2.7" }
50-
anathema-backend = { path = "./anathema-backend", version = "0.2.7" }
51-
anathema-runtime = { path = "./anathema-runtime", version = "0.2.7" }
52-
anathema-state = { path = "./anathema-state", version = "0.2.7" }
53-
anathema-state-derive = { path = "./anathema-state-derive", version = "0.2.7" }
54-
anathema-store = { path = "./anathema-store", version = "0.2.7" }
55-
anathema-templates = { path = "./anathema-templates", version = "0.2.7" }
56-
anathema-widgets = { path = "./anathema-widgets", version = "0.2.7" }
57-
anathema-geometry = { path = "./anathema-geometry", version = "0.2.7" }
58-
anathema-value-resolver = { path = "./anathema-value-resolver", version = "0.2.7" }
50+
anathema-default-widgets = { path = "./anathema-default-widgets", version = "0.2.8" }
51+
anathema-backend = { path = "./anathema-backend", version = "0.2.8" }
52+
anathema-runtime = { path = "./anathema-runtime", version = "0.2.8" }
53+
anathema-state = { path = "./anathema-state", version = "0.2.8" }
54+
anathema-state-derive = { path = "./anathema-state-derive", version = "0.2.8" }
55+
anathema-store = { path = "./anathema-store", version = "0.2.8" }
56+
anathema-templates = { path = "./anathema-templates", version = "0.2.8" }
57+
anathema-widgets = { path = "./anathema-widgets", version = "0.2.8" }
58+
anathema-geometry = { path = "./anathema-geometry", version = "0.2.8" }
59+
anathema-value-resolver = { path = "./anathema-value-resolver", version = "0.2.8" }
5960

6061
[workspace]
6162
members = [

anathema-backend/src/testing/events.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::collections::VecDeque;
22

3+
use anathema_geometry::Size;
34
use anathema_widgets::components::events::{Event, KeyEvent};
45

56
pub struct EventsMut<'a> {
@@ -19,6 +20,12 @@ impl EventsMut<'_> {
1920
self
2021
}
2122

23+
pub fn resize(self, new_size: impl Into<Size>) -> Self {
24+
let size = new_size.into();
25+
self.event_queue.push_back(Some(Event::Resize(size)));
26+
self
27+
}
28+
2229
pub fn stop(self) -> Self {
2330
self.event_queue.push_back(Some(Event::Stop));
2431
self

anathema-backend/src/testing/surface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl TestSurface {
2323

2424
pub(crate) fn resize(&mut self, new_size: Size, _glyph_map: &mut GlyphMap) {
2525
self.size = new_size;
26-
todo!("truncate and pop lines outside of the new size")
26+
// TODO: this should pop and truncate the lines to fit the new size
2727
}
2828

2929
// Get from previous lines as the clear function has most likely

anathema-default-widgets/src/testing.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use anathema_backend::{Backend, WidgetCycle};
33
use anathema_geometry::{Pos, Size};
44
use anathema_state::{State, StateId, States, Value};
55
use anathema_templates::blueprints::Blueprint;
6-
use anathema_templates::{Document, Globals, ToSourceKind};
6+
use anathema_templates::{Document, ToSourceKind, Variables};
77
use anathema_value_resolver::{AttributeStorage, Attributes, FunctionTable, Scope};
88
use anathema_widgets::components::ComponentRegistry;
99
use anathema_widgets::components::events::Event;
@@ -131,7 +131,7 @@ pub struct TestRunner {
131131
factory: Factory,
132132
backend: TestBackend,
133133
blueprint: Blueprint,
134-
globals: Globals,
134+
variables: Variables,
135135
components: Components,
136136
function_table: FunctionTable,
137137
}
@@ -167,7 +167,7 @@ impl TestRunner {
167167
states,
168168
component_registry,
169169
blueprint,
170-
globals,
170+
variables: globals,
171171
components: Components::new(),
172172
function_table: FunctionTable::new(),
173173
}
@@ -178,7 +178,7 @@ impl TestRunner {
178178
&self.blueprint,
179179
&mut self.states,
180180
&mut self.backend,
181-
&self.globals,
181+
&self.variables,
182182
&self.factory,
183183
&mut self.component_registry,
184184
&mut self.components,
@@ -192,7 +192,7 @@ pub struct TestInstance<'bp> {
192192
attribute_storage: AttributeStorage<'bp>,
193193
floating_widgets: FloatingWidgets,
194194
states: &'bp mut States,
195-
globals: &'bp Globals,
195+
variables: &'bp Variables,
196196
backend: &'bp mut TestBackend,
197197
viewport: Viewport,
198198
factory: &'bp Factory,
@@ -208,7 +208,7 @@ impl<'bp> TestInstance<'bp> {
208208
blueprint: &'bp Blueprint,
209209
states: &'bp mut States,
210210
backend: &'bp mut TestBackend,
211-
globals: &'bp Globals,
211+
variables: &'bp Variables,
212212
factory: &'bp Factory,
213213
component_registry: &'bp mut ComponentRegistry,
214214
components: &'bp mut Components,
@@ -222,7 +222,7 @@ impl<'bp> TestInstance<'bp> {
222222

223223
let scope = Scope::root();
224224
let mut ctx = LayoutCtx::new(
225-
globals,
225+
variables,
226226
factory,
227227
states,
228228
&mut attribute_storage,
@@ -244,7 +244,7 @@ impl<'bp> TestInstance<'bp> {
244244
attribute_storage,
245245
floating_widgets,
246246
states,
247-
globals,
247+
variables,
248248
backend,
249249
viewport,
250250
factory,
@@ -274,7 +274,7 @@ impl<'bp> TestInstance<'bp> {
274274
let mut tree = self.tree.view();
275275

276276
let mut ctx = LayoutCtx::new(
277-
self.globals,
277+
self.variables,
278278
self.factory,
279279
self.states,
280280
&mut self.attribute_storage,
@@ -319,7 +319,7 @@ impl<'bp> TestInstance<'bp> {
319319
let constraints = Constraints::new(width as u16, height as u16);
320320

321321
let mut ctx = LayoutCtx::new(
322-
self.globals,
322+
self.variables,
323323
self.factory,
324324
self.states,
325325
&mut self.attribute_storage,

anathema-runtime/src/builder.rs

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ pub struct Builder<G> {
3131
}
3232

3333
impl<G: GlobalEventHandler> Builder<G> {
34-
/// Create a new runtime builder
35-
pub(super) fn new(document: Document, size: Size, global_event_handler: G) -> Self {
34+
/// Create a new runtime builder with a reciver.
35+
/// Use this if the `Emitter` was created outside of the runtime.
36+
pub(super) fn with_receiver(
37+
message_receiver: flume::Receiver<ViewMessage>,
38+
emitter: Emitter,
39+
document: Document,
40+
size: Size,
41+
global_event_handler: G,
42+
) -> Self {
3643
let mut factory = Factory::new();
3744
register_default_widgets(&mut factory);
3845

39-
let (tx, message_receiver) = flume::unbounded();
40-
let emitter = tx.into();
41-
4246
Self {
4347
factory,
4448
document,
@@ -53,6 +57,13 @@ impl<G: GlobalEventHandler> Builder<G> {
5357
}
5458
}
5559

60+
/// Create a new runtime builder
61+
pub(super) fn new(document: Document, size: Size, global_event_handler: G) -> Self {
62+
let (tx, rx) = flume::unbounded();
63+
let emitter = Emitter::from(tx);
64+
Self::with_receiver(rx, emitter.clone(), document, size, global_event_handler)
65+
}
66+
5667
/// Enable/Disable hot reloading
5768
pub fn hot_reload(&mut self, value: bool) {
5869
self.hot_reload = value;
@@ -172,9 +183,15 @@ impl<G: GlobalEventHandler> Builder<G> {
172183
let (blueprint, globals) = loop {
173184
match self.document.compile() {
174185
Ok(val) => break val,
175-
Err(error) => {
176-
show_error(error, backend, &mut self.document)?;
177-
}
186+
// This can only show template errors.
187+
// Widget errors doesn't become available until after the first tick.
188+
Err(error) => match show_error(error.into(), backend, &self.document) {
189+
Ok(()) => return Err(Error::Stop),
190+
Err(Error::Reload) if self.hot_reload => {
191+
_ = self.document.reload_templates();
192+
}
193+
err => err?,
194+
},
178195
}
179196
};
180197

@@ -193,42 +210,10 @@ impl<G: GlobalEventHandler> Builder<G> {
193210
self.fps,
194211
self.global_event_handler,
195212
self.function_table,
213+
self.hot_reload,
196214
);
197215

198-
// NOTE:
199-
// this enables hot reload,
200-
// however with this enabled the `with_frame` function
201-
// on the runtime will repeat
202-
loop {
203-
match f(&mut inst, backend) {
204-
Ok(()) => (),
205-
e => match e {
206-
Ok(_) => continue,
207-
Err(Error::Stop) => break Ok(()),
208-
Err(Error::Template(error)) => match show_error(error, backend, &mut inst.document) {
209-
Ok(_) => continue,
210-
Err(err) => panic!("error console failed: {err}"),
211-
},
212-
Err(Error::Widget(err)) => panic!("this should not panic in the future: {err}"),
213-
Err(e) => break Err(e),
214-
},
215-
}
216-
217-
if !self.hot_reload {
218-
break Ok(());
219-
}
220-
221-
match inst.reload() {
222-
Ok(()) => continue,
223-
Err(Error::Stop) => todo!(),
224-
Err(Error::Template(error)) => match show_error(error, backend, &mut inst.document) {
225-
Ok(_) => continue,
226-
Err(err) => panic!("error console failed: {err}"),
227-
},
228-
Err(Error::Widget(_error)) => todo!(),
229-
Err(e) => break Err(e),
230-
}
231-
}
216+
f(&mut inst, backend)
232217
}
233218

234219
fn set_watcher(&mut self, hot_reload: bool) -> Result<Option<RecommendedWatcher>> {

anathema-runtime/src/error.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,24 @@ pub type Result<T> = std::result::Result<T, Error>;
88
#[derive(Debug)]
99
pub enum Error {
1010
Template(TemplateError),
11-
Notify(notify::Error),
1211
Widget(anathema_widgets::error::Error),
12+
Notify(notify::Error),
1313
Stop,
14+
Reload,
1415
InvalidComponentName,
1516
Resolver(anathema_value_resolver::Error),
1617
}
1718

1819
impl Display for Error {
1920
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2021
match self {
21-
Error::Template(template) => write!(f, "{template}"),
22-
Error::Stop => write!(f, "stopping"),
23-
Error::Notify(err) => write!(f, "{err}"),
24-
Error::Widget(err) => write!(f, "{err}"),
25-
Error::Resolver(err) => write!(f, "{err}"),
26-
Error::InvalidComponentName => write!(f, "no such component"),
22+
Self::Template(template) => write!(f, "{template}"),
23+
Self::Stop => write!(f, "stopping"),
24+
Self::Reload => write!(f, "reloading"),
25+
Self::Notify(err) => write!(f, "{err}"),
26+
Self::Widget(err) => write!(f, "{err}"),
27+
Self::Resolver(err) => write!(f, "{err}"),
28+
Self::InvalidComponentName => write!(f, "no such component"),
2729
}
2830
}
2931
}

0 commit comments

Comments
 (0)