Skip to content

Commit

Permalink
Improve and declutter logs
Browse files Browse the repository at this point in the history
  • Loading branch information
doonv committed Jan 4, 2024
1 parent dfcbe94 commit 5a8de88
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
2 changes: 0 additions & 2 deletions src/builtin_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ impl CommandParser for BuiltinCommandParser {
let ast = parse(&mut tokens, &environment);
world.insert_non_send_resource(environment);

dbg!(&ast);

match ast {
Ok(ast) => {
runner::run(ast, world);
Expand Down
38 changes: 27 additions & 11 deletions src/builtin_parser/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ pub fn run(ast: Ast, world: &mut World) {
match value {
Ok(Value::None) => {}
Ok(value) => match value.try_format(span, world, &registrations) {
Ok(value) => info!(name: COMMAND_RESULT_NAME, "{value}"),
Ok(value) => {
info!(name: COMMAND_RESULT_NAME, "{}{value}", crate::ui::COMMAND_RESULT_PREFIX)
}
Err(err) => error!("{err:?}"),
},
Err(err) => {
Expand Down Expand Up @@ -520,17 +522,31 @@ fn eval_path(
}
}
Expression::Dereference(inner) => {
if let Expression::Variable(variable) = inner.value {
let value = environment.get(&variable, inner.span)?;
if let Value::Reference(ref reference) = &*value.borrow_inner().borrow() {
Ok(expr.span.wrap(Path::Variable(reference.clone())))
} else {
Err(RunError::CouldntDereferenceValue(
expr.span.wrap(value.borrow_inner().borrow().kind()),
))
let path = eval_path(
*inner,
EvalParams {
world,
environment,
registrations,
},
)?;
match path.value {
Path::Variable(value) => {
let strong = value
.upgrade()
.ok_or(RunError::ReferenceToMovedData(path.span))?;
let borrow = strong.borrow();

if let Value::Reference(ref reference) = &*borrow {
Ok(expr.span.wrap(Path::Variable(reference.clone())))
} else {
Err(RunError::CouldntDereferenceValue(
expr.span.wrap(borrow.kind()),
))
}
}
} else {
todo_error!()
Path::NewVariable(_) => todo_error!(),
Path::Resource(_) => todo_error!(),
}
}
expr => todo_error!("{expr:#?}"),
Expand Down
22 changes: 15 additions & 7 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,36 +220,44 @@ fn format_line(

*command_index += 1;

let message_stripped = message
.strip_prefix(COMMAND_MESSAGE_PREFIX)
.unwrap_or(message);
text.append(COMMAND_MESSAGE_PREFIX, 0.0, config.theme.format_dark());
// TODO: Handle more than just the first element
if let Some(hint) = hints.first() {
const PREFIX_LEN: usize = COMMAND_MESSAGE_PREFIX.len();

text.append(
&message[..hint.span.start + PREFIX_LEN],
&message_stripped[..hint.span.start],
0.,
config.theme.format_text(),
);
text.append(
&message[hint.span.start + PREFIX_LEN..hint.span.end + PREFIX_LEN],
&message_stripped[hint.span.start..hint.span.end],
0.,
TextFormat {
underline: Stroke::new(1.0, config.theme.error.to_color32()),
..config.theme.format_text()
},
);
text.append(
&message[hint.span.end + PREFIX_LEN..],
&message_stripped[hint.span.end..],
0.,
config.theme.format_text(),
);
return text;
}
text.append(message.as_str(), 0.0, config.theme.format_text());
text.append(message_stripped, 0.0, config.theme.format_text());
text
}
COMMAND_RESULT_NAME => {
text.append(COMMAND_RESULT_PREFIX, 0.0, config.theme.format_dark());
text.append(message.as_str(), 0.0, config.theme.format_text());
text.append(
message
.strip_prefix(COMMAND_RESULT_PREFIX)
.unwrap_or(message),
0.0,
config.theme.format_text(),
);
text
}
_ => {
Expand Down

0 comments on commit 5a8de88

Please sign in to comment.