Skip to content

Commit

Permalink
feat: color mode in status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpombrio committed Jun 9, 2024
1 parent b3aa4c7 commit 6651e5d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ron = "0.8.1"
[dependencies.partial-pretty-printer]
#path = "../ppp/"
git = "https://github.com/justinpombrio/partial-pretty-printer"
version = "0.9.0"
version = "0.9.1"
features = ["serialization"]
[dependencies.no-nonsense-flamegraphs]
version = "0.2.*"
Expand Down
19 changes: 16 additions & 3 deletions data/string_lang.ron
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,35 @@ LanguageSpec(
constructs: [
ConstructSpec(
name: "Root",
arity: Fixed([SortSpec(["String"])]),
arity: Fixed([SortSpec(["any"])]),
),
ConstructSpec(
name: "BgBase08",
arity: Fixed([SortSpec(["any"])]),
),
ConstructSpec(
name: "BgBase0B",
arity: Fixed([SortSpec(["any"])]),
),
ConstructSpec(
name: "String",
arity: Texty,
),
],
sorts: [],
sorts: [("any", SortSpec(["BgBase08", "BgBase0B", "String"]))],
root_construct: "Root",
),
default_display_notation: "DefaultDisplay",
default_source_notation: None,
notations: [
NotationSetSpec(
name: "DefaultDisplay",
notations: [("Root", Child(0)), ("String", Text)],
notations: [
("Root", Child(0)),
("BgBase08", Style(Properties(bg_color: Some(Base08)), Child(0))),
("BgBase0B", Style(Properties(bg_color: Some(Base0B)), Child(0))),
("String", Text)
],
)
]
)
17 changes: 14 additions & 3 deletions src/engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use super::Settings;
use crate::language::{Language, LanguageSpec, NotationSetSpec, Storage};
use crate::parsing::{Parse, ParseError};
use crate::pretty_doc::DocRef;
use crate::style::Base16Color;
use crate::tree::{Mode, Node};
use crate::util::{error, SynlessBug, SynlessError};
use crate::util::{bug, error, SynlessBug, SynlessError};
use partial_pretty_printer as ppp;
use partial_pretty_printer::pane;
use std::collections::HashMap;
Expand Down Expand Up @@ -252,15 +253,25 @@ impl Engine {
.get_content(&self.storage, label, &self.settings)
}

pub fn make_string_doc(&mut self, string: String) -> Node {
pub fn make_string_doc(&mut self, string: String, bg_color: Option<Base16Color>) -> Node {
let lang = self
.storage
.language(STRING_LANGUAGE_NAME)
.bug_msg("Missing String lang");
let c_root = lang.root_construct(&self.storage);
let c_string = lang.construct(&self.storage, "String").bug();
let string_node = Node::with_text(&mut self.storage, c_string, string).bug();
Node::with_children(&mut self.storage, c_root, [string_node]).bug()
let node = if let Some(color) = bg_color {
let c_color = match color {
Base16Color::Base08 => lang.construct(&self.storage, "BgBase08").bug(),
Base16Color::Base0B => lang.construct(&self.storage, "BgBase0B").bug(),
_ => bug!("make_string_doc: specified bg color not yet supported"),
};
Node::with_children(&mut self.storage, c_color, [string_node]).bug()
} else {
string_node
};
Node::with_children(&mut self.storage, c_root, [node]).bug()
}

/***********
Expand Down
27 changes: 14 additions & 13 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,14 @@ impl<F: Frontend<Style = Style> + 'static> Runtime<F> {

fn log(&mut self, level: LogLevel, message: String) {
let entry = LogEntry::new(level, message);
if level >= LOG_LEVEL_TO_DISPLAY {
if self
if level >= LOG_LEVEL_TO_DISPLAY
&& self
.last_log
.as_ref()
.map(|old| level > old.level)
.unwrap_or(true)
{
self.last_log = Some(entry.clone());
}
{
self.last_log = Some(entry.clone());
}
entry.log();
}
Expand Down Expand Up @@ -246,16 +245,18 @@ impl<F: Frontend<Style = Style> + 'static> Runtime<F> {
let opt_node = self
.layers
.menu_description()
.map(|menu_name| self.engine.make_string_doc(menu_name.to_owned()));
.map(|menu_name| self.engine.make_string_doc(menu_name.to_owned(), None));
(DocName::Auxilliary(MENU_NAME_LABEL.to_owned()), opt_node)
}

fn make_mode_doc(&mut self) -> (DocName, Option<Node>) {
let mode = match self.engine.mode() {
Mode::Tree => "TREE".to_owned(),
Mode::Text => "TEXT".to_owned(),
use crate::style::Base16Color;

let (mode, color) = match self.engine.mode() {
Mode::Tree => ("[TREE]".to_owned(), None),
Mode::Text => ("[TEXT]".to_owned(), Some(Base16Color::Base0B)),
};
let node = self.engine.make_string_doc(mode);
let node = self.engine.make_string_doc(mode, color);
(DocName::Auxilliary(MODE_LABEL.to_owned()), Some(node))
}

Expand All @@ -269,7 +270,7 @@ impl<F: Frontend<Style = Style> + 'static> Runtime<F> {
DocName::Metadata(label) => format!("metadata:{}", label),
DocName::Auxilliary(label) => format!("auxilliary:{}", label),
});
let opt_node = opt_label.map(|label| self.engine.make_string_doc(label));
let opt_node = opt_label.map(|label| self.engine.make_string_doc(label, None));
(DocName::Auxilliary(FILENAME_LABEL.to_owned()), opt_node)
}

Expand All @@ -280,7 +281,7 @@ impl<F: Frontend<Style = Style> + 'static> Runtime<F> {
let (numerator, denominator) = cursor.sibling_index_info(s);
format!("sibling {}/{}", numerator, denominator)
});
let opt_node = opt_label.map(|label| self.engine.make_string_doc(label));
let opt_node = opt_label.map(|label| self.engine.make_string_doc(label, None));
(
DocName::Auxilliary(SIBLING_INDEX_LABEL.to_owned()),
opt_node,
Expand All @@ -289,7 +290,7 @@ impl<F: Frontend<Style = Style> + 'static> Runtime<F> {

fn make_last_log_doc(&mut self) -> (DocName, Option<Node>) {
let opt_message = self.last_log.as_ref().map(|entry| entry.to_string());
let opt_node = opt_message.map(|msg| self.engine.make_string_doc(msg));
let opt_node = opt_message.map(|msg| self.engine.make_string_doc(msg, None));
(DocName::Auxilliary(LAST_LOG_LABEL.to_owned()), opt_node)
}

Expand Down

0 comments on commit 6651e5d

Please sign in to comment.