Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add live preview to theme picker #1798

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
94a377f
Add theme picker with live preview
jharrilim Mar 12, 2022
753131e
Add live theme preview to :theme command
jharrilim Mar 12, 2022
b0c4f7c
cargo fmt
jharrilim Mar 12, 2022
6bfde21
Fix clippy warnings
jharrilim Mar 12, 2022
1481093
Remove picker variant
jharrilim Mar 13, 2022
fe5ec9e
Remove unused import
jharrilim Mar 13, 2022
2d96be2
Cleanup
jharrilim Mar 15, 2022
c638d0b
Change current_theme to last_theme
jharrilim Mar 15, 2022
dcb09e0
Fix accidental comment flash deletion
jharrilim Mar 15, 2022
3c1638b
Merge branch 'master' into feat/add-theme-picker-with-live-preview-jh…
jharrilim Mar 18, 2022
8dfd840
Merge branch 'master' into feat/add-theme-picker-with-live-preview-jh…
jharrilim Jun 18, 2022
0178162
Typo
jharrilim Jun 18, 2022
5f85522
Remove theme cache
jharrilim Jun 18, 2022
97ed0d6
Add some comments
jharrilim Jun 18, 2022
01467e3
Refactor some theme handling
jharrilim Jun 18, 2022
b782d07
Remove unnecessary renames
jharrilim Jun 19, 2022
3e9b33e
Constrain last_theme theme preview lifecycle
jharrilim Jun 19, 2022
a05186f
Switch to bitflag implementation
jharrilim Jun 19, 2022
a83069e
Better handling of last_theme
jharrilim Jun 20, 2022
89ec841
Sort theme names
jharrilim Jun 20, 2022
1d1c8cc
Better memory juggling
jharrilim Jun 20, 2022
0af7ed6
Missed a branch
jharrilim Jun 20, 2022
a8514d0
Remove name from theme, switch bitand to &
jharrilim Jun 22, 2022
1961ac5
Merge branch 'master' into feat/add-theme-picker-with-live-preview-jh…
jharrilim Jun 22, 2022
860665b
cargo fmt
jharrilim Jun 22, 2022
5eb1d41
Update helix-view/src/editor.rs
jharrilim Jun 24, 2022
5a313c9
Switch boolean to enum
jharrilim Jun 26, 2022
bc3a1de
Merge branch 'feat/add-theme-picker-with-live-preview-jharrilim' of g…
jharrilim Jun 26, 2022
670f0b8
Remove bitflag impl
jharrilim Jul 2, 2022
b81aedf
cargo fmt
jharrilim Jul 2, 2022
8f6991f
Remove un-needed type arg
jharrilim Jul 2, 2022
251d61a
cargo fmt
jharrilim Jul 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ use {
#[cfg(windows)]
type Signals = futures_util::stream::Empty<()>;

fn default_theme(theme_loader: Arc<theme::Loader>, true_color: bool) -> (String, theme::Theme) {
if true_color {
(String::from("default"), theme_loader.default())
} else {
(
String::from("base16_default"),
theme_loader.base16_default(),
)
}
}

pub struct Application {
compositor: Compositor,
editor: Editor,
Expand Down Expand Up @@ -67,26 +78,24 @@ impl Application {
std::sync::Arc::new(theme::Loader::new(&conf_dir, &helix_loader::runtime_dir()));

let true_color = config.editor.true_color || crate::true_color();
let theme = config
.theme
.as_ref()
.and_then(|theme| {
theme_loader
.load(theme)

let (theme_name, theme) = match config.theme.as_ref() {
Some(theme_name) => {
match theme_loader
.load(theme_name)
.map_err(|e| {
log::warn!("failed to load theme `{}` - {}", theme, e);
log::warn!("failed to load theme `{}` - {}", theme_name, e);
e
})
.ok()
.filter(|theme| (true_color || theme.is_16_color()))
})
.unwrap_or_else(|| {
if true_color {
theme_loader.default()
} else {
theme_loader.base16_default()
{
Some(theme) => (theme_name.clone(), theme),
None => default_theme(theme_loader.clone(), true_color),
}
});
}
None => default_theme(theme_loader.clone(), true_color),
};

let syn_loader_conf = user_syntax_loader().unwrap_or_else(|err| {
eprintln!("Bad language config: {}", err);
Expand All @@ -103,6 +112,7 @@ impl Application {
theme_loader.clone(),
syn_loader.clone(),
config.editor.clone(),
theme_name.clone(),
);

let editor_view = Box::new(ui::EditorView::new(std::mem::take(&mut config.keys)));
Expand Down Expand Up @@ -159,7 +169,7 @@ impl Application {
.unwrap_or_else(|_| editor.new_file(Action::VerticalSplit));
}

editor.set_theme(theme);
editor.set_theme(theme, theme_name);

#[cfg(windows)]
let signals = futures_util::stream::empty();
Expand Down
6 changes: 3 additions & 3 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,7 @@ fn global_search(cx: &mut Context) {

let picker = FilePicker::new(
all_matches,
move |(_line_num, path)| {
move |_, (_line_num, path)| {
let relative_path = helix_core::path::get_relative_path(path)
.to_string_lossy()
.into_owned();
Expand Down Expand Up @@ -2077,7 +2077,7 @@ fn buffer_picker(cx: &mut Context) {
.iter()
.map(|(_, doc)| new_meta(doc))
.collect(),
BufferMeta::format,
|_, a| BufferMeta::format(a),
|cx, meta, action| {
cx.editor.switch(meta.id, action);
},
Expand Down Expand Up @@ -2127,7 +2127,7 @@ pub fn command_palette(cx: &mut Context) {

let picker = Picker::new(
commands,
move |command| match command {
move |_, command| match command {
MappableCommand::Typable { doc, name, .. } => match keymap.get(name as &String)
{
Some(bindings) => format!("{} ({})", doc, fmt_binding(bindings)).into(),
Expand Down
6 changes: 3 additions & 3 deletions helix-term/src/commands/dap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn thread_picker(
let thread_states = debugger.thread_states.clone();
let picker = FilePicker::new(
threads,
move |thread| {
move |_, thread| {
format!(
"{} ({})",
thread.name,
Expand Down Expand Up @@ -320,7 +320,7 @@ pub fn dap_launch(cx: &mut Context) {

cx.push_layer(Box::new(overlayed(Picker::new(
templates,
|template| template.name.as_str().into(),
|_, template| template.name.as_str().into(),
|cx, template, _action| {
let completions = template.completion.clone();
let name = template.name.clone();
Expand Down Expand Up @@ -792,7 +792,7 @@ pub fn dap_switch_stack_frame(cx: &mut Context) {

let picker = FilePicker::new(
frames,
|frame| frame.name.as_str().into(), // TODO: include thread_states in the label
|_, frame| frame.name.as_str().into(), // TODO: include thread_states in the label
move |cx, frame, _action| {
let debugger = debugger!(cx.editor);
// TODO: this should be simpler to find
Expand Down
4 changes: 2 additions & 2 deletions helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn sym_picker(
let current_path2 = current_path.clone();
let mut picker = FilePicker::new(
symbols,
move |symbol| {
move |_, symbol| {
if current_path.as_ref() == Some(&symbol.location.uri) {
symbol.name.as_str().into()
} else {
Expand Down Expand Up @@ -455,7 +455,7 @@ fn goto_impl(
_locations => {
let picker = FilePicker::new(
locations,
move |location| {
move |_, location| {
let file: Cow<'_, str> = (location.uri.scheme() == "file")
.then(|| {
location
Expand Down
Loading