read command history from file

pull/9143/head
Ingrid 11 months ago
parent 08f16fd4ca
commit 32512a02b4

@ -27,6 +27,7 @@ use crate::{
handlers,
job::Jobs,
keymap::Keymaps,
session,
ui::{self, overlay::overlaid},
};
@ -148,6 +149,14 @@ impl Application {
handlers,
);
// TODO: do most of this in the background?
#[cfg(not(feature = "integration"))]
editor
.registers
.write_unreversed(':', session::read_command_history())
// TODO: do something about this unwrap
.unwrap();
let keys = Box::new(Map::new(Arc::clone(&config), |config: &Config| {
&config.keys
}));

@ -1,5 +1,9 @@
use helix_loader::command_histfile;
use std::{fs::OpenOptions, io::Write};
use std::{
fs::{File, OpenOptions},
io::{self, BufRead, BufReader, Lines, Write},
path::PathBuf,
};
pub fn push_history(register: char, line: &str) {
let filepath = match register {
@ -17,3 +21,15 @@ pub fn push_history(register: char, line: &str) {
// TODO: do something about this unwrap
writeln!(file, "{}", line).unwrap();
}
fn read_histfile(filepath: PathBuf) -> Lines<BufReader<File>> {
// TODO: do something about this unwrap
BufReader::new(File::open(filepath).unwrap()).lines()
}
pub fn read_command_history() -> Vec<String> {
read_histfile(command_histfile())
.collect::<io::Result<Vec<String>>>()
// TODO: do something about this unwrap
.unwrap()
}

@ -104,6 +104,29 @@ impl Registers {
}
}
pub fn write_unreversed(&mut self, name: char, values: Vec<String>) -> Result<()> {
match name {
'_' => Ok(()),
'#' | '.' | '%' => Err(anyhow::anyhow!("Register {name} does not support writing")),
'*' | '+' => {
self.clipboard_provider.set_contents(
values.join(NATIVE_LINE_ENDING.as_str()),
match name {
'+' => ClipboardType::Clipboard,
'*' => ClipboardType::Selection,
_ => unreachable!(),
},
)?;
self.inner.insert(name, values);
Ok(())
}
_ => {
self.inner.insert(name, values);
Ok(())
}
}
}
pub fn push(&mut self, name: char, mut value: String) -> Result<()> {
match name {
'_' => Ok(()),

Loading…
Cancel
Save