mirror of https://github.com/helix-editor/helix
switch to multi-file approach, implement persisting command history
parent
0fcb26c877
commit
08f16fd4ca
@ -1,68 +1,19 @@
|
|||||||
use bincode::{encode_into_std_write, Decode, Encode};
|
use helix_loader::command_histfile;
|
||||||
use helix_loader::{session_file, VERSION_AND_GIT_HASH};
|
use std::{fs::OpenOptions, io::Write};
|
||||||
// use helix_view::view::ViewPosition;
|
|
||||||
use std::{
|
pub fn push_history(register: char, line: &str) {
|
||||||
fs::File,
|
let filepath = match register {
|
||||||
time::{SystemTime, UNIX_EPOCH},
|
':' => command_histfile(),
|
||||||
};
|
_ => return,
|
||||||
|
};
|
||||||
// TODO: should this be non-exhaustive?
|
|
||||||
#[derive(Debug, Encode, Decode)]
|
let mut file = OpenOptions::new()
|
||||||
struct Header {
|
.append(true)
|
||||||
generator: String,
|
.create(true)
|
||||||
version: String,
|
.open(filepath)
|
||||||
max_kbyte: u32,
|
|
||||||
pid: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: should this be non-exhaustive?
|
|
||||||
#[derive(Debug, Encode, Decode)]
|
|
||||||
struct FilePosition {
|
|
||||||
path: String,
|
|
||||||
// position: ViewPosition,
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: should this be non-exhaustive?
|
|
||||||
#[derive(Debug, Encode, Decode)]
|
|
||||||
enum EntryData {
|
|
||||||
Header(Header),
|
|
||||||
FilePosition(FilePosition),
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: should this be non-exhaustive?
|
|
||||||
#[derive(Debug, Encode, Decode)]
|
|
||||||
struct Entry {
|
|
||||||
timestamp: u64,
|
|
||||||
data: EntryData,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn timestamp_now() -> u64 {
|
|
||||||
SystemTime::now()
|
|
||||||
.duration_since(UNIX_EPOCH)
|
|
||||||
.unwrap_or_default()
|
|
||||||
.as_secs()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn generate_header() -> Entry {
|
|
||||||
Entry {
|
|
||||||
timestamp: timestamp_now(),
|
|
||||||
data: EntryData::Header(Header {
|
|
||||||
generator: "helix".to_string(),
|
|
||||||
version: VERSION_AND_GIT_HASH.to_string(),
|
|
||||||
max_kbyte: 100,
|
|
||||||
pid: std::process::id(),
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn write_session_file() {
|
|
||||||
// TODO: merge existing file if exists
|
|
||||||
|
|
||||||
// TODO: do something about this unwrap
|
// TODO: do something about this unwrap
|
||||||
let mut session_file = File::create(session_file()).unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let header = generate_header();
|
|
||||||
|
|
||||||
// TODO: do something about this unwrap
|
// TODO: do something about this unwrap
|
||||||
encode_into_std_write(&header, &mut session_file, bincode::config::standard()).unwrap();
|
writeln!(file, "{}", line).unwrap();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue