Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
78 changes: 78 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ shellexpand = "2.1.*"
log = "0.4.*"
env_logger = "0.10.*"
sysinfo = "0.33.*"
rust-ini = "0.21"

[package.metadata.deb]
maintainer = "beeender <chenmulong@gmail.com>"
Expand Down
98 changes: 98 additions & 0 deletions src/backend/foot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
use super::Functions;
use crate::config::Config;
use crate::error::GlrnvimError;
use ini::Ini;
use std::io::Write;
use std::path::PathBuf;
use tempfile::NamedTempFile;

pub const FOOT_NAME: &str = "foot";

struct Foot {
exe_path: PathBuf,
temp_file: Option<NamedTempFile>,
}

pub fn init(config: &Config) -> Result<Box<dyn Functions>, GlrnvimError> {
let exe_path = super::exe_path(&config.term_exe_path, FOOT_NAME)?;

Ok(Box::new(Foot {
exe_path,
temp_file: None,
}))
}

impl Foot {
fn create_conf_file(&mut self, config: &Config) {
let mut foot_conf = if config.load_term_conf {
let conf_files = Foot::find_default_confs();
if conf_files.is_empty() {
Ini::new()
} else {
let path = conf_files.first().unwrap();
Ini::load_from_file(path).expect("Failed to load default config file")
}
} else {
Ini::new()
};

let mut font_str = String::new();
for f in &config.fonts {
if !font_str.is_empty() {
font_str += ",";
}
font_str += f;
if config.font_size != 0 {
font_str += &format!(":size={}", config.font_size).to_string();
}
}
if !font_str.is_empty() {
foot_conf.with_section(Some("main")).set("font", font_str);
}
// Note: The ctrl-z seems to be no-op so we don't have to disable it. Other default
// key bindings are quite harmless for now. If needed, just disable them in the config file
// here.

let mut file = tempfile::NamedTempFile::new().expect("Failed to create temporary file");
foot_conf
.write_to_file(&file)
.expect("Failed to write to temporary file");
file.flush().unwrap();

file.path();
self.temp_file = Some(file);
}

fn find_default_confs() -> Vec<String> {
let base_confs: [String; 0] = [];
let pri_confs: [String; 3] = [
"$XDG_CONFIG_HOME/foot/foot.conf".to_string(),
"$HOME/.config/foot/foot.conf".to_string(),
"$XDG_CONFIG_DIRS/foot/foot.conf".to_string(),
];
super::find_term_conf_files(&base_confs, &pri_confs)
}
}

impl Functions for Foot {
fn create_command(&mut self, config: &Config) -> std::process::Command {
let mut command = std::process::Command::new(&self.exe_path);

command.arg("--config");
if let Some(config_path) = config.term_config_path.as_ref() {
command.arg(config_path.as_str());
} else {
self.create_conf_file(config);
// Overwrite the config with the generated settings from glrnvim.yml
command.arg(self.temp_file.as_ref().unwrap().path());
}

command.arg("--app-id");
command.arg("glrnvim");

command.arg(&config.nvim_exe_path);
command.args(super::COMMON_ARGS);

command
}
}
2 changes: 2 additions & 0 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod alacritty;
mod kitty;
mod urxvt;
mod wezterm;
mod foot;
use super::config::Config;
use crate::config::Backend;
use crate::error::GlrnvimError;
Expand Down Expand Up @@ -42,6 +43,7 @@ pub fn init(config: &Config) -> Result<Box<dyn Functions>, GlrnvimError> {
Backend::Urxvt => urxvt::init(config),
Backend::Kitty => kitty::init(config),
Backend::Wezterm => wezterm::init(config),
Backend::Foot => foot::init(config),
},
None => {
for init_func in &[alacritty::init, urxvt::init, kitty::init, wezterm::init] {
Expand Down
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub enum Backend {
Urxvt,
Kitty,
Wezterm,
Foot,
}

#[derive(Debug, PartialEq, Eq, Deserialize)]
Expand Down